Preventing deletion of nodes with comments
ronsegal - September 15, 2009 - 21:35
For a discussion site, I'd like to find an easy way to prevent (non administrative) users from deleting or editing nodes after the first comment has been added. Be grateful for some help.
This I think will be a good strategy for discussion topics, together with an edit/delete timeout for comments (which the comment_edited module partially supports with some tweaks).

Preventing deletion of nodes with comments
Well I'm going to answer my own question, in case somebody else wants to do this.
Its possible in Drupal 6 by using both the Rules and Content Access modules, which work together. Assuming that the rules are to apply to authorised users who are creating and adding comments to a 'discussion' content type (nothing special about the content type).
Create 2 rules:
1. A rule to grant edit / delete permissions to authorised users who create a new discussion content node.
2. A rule to revoke edit / delete permissions when a new comment is added to that node.
Here are my exported rules, which can be imported using the Rules module's import function:
array (
'rules' =>
array (
'rules_1' =>
array (
'#type' => 'rule',
'#set' => 'event_comment_insert',
'#label' => 'new discussion comment changes node access permission',
'#active' => 1,
'#weight' => '0',
'#categories' =>
array (
),
'#status' => 'custom',
'#conditions' =>
array (
0 =>
array (
'#type' => 'condition',
'#settings' =>
array (
'type' =>
array (
'discussion' => 'discussion',
),
'#argument map' =>
array (
'node' => 'node',
),
),
'#name' => 'rules_condition_content_is_type',
'#info' =>
array (
'label' => 'Commented content is discussion',
'arguments' =>
array (
'node' =>
array (
'type' => 'node',
'label' => 'Content',
),
),
'module' => 'Node',
),
'#weight' => 0,
),
),
'#actions' =>
array (
0 =>
array (
'#type' => 'action',
'#settings' =>
array (
'#argument map' =>
array (
'node' => 'node',
),
'view' =>
array (
),
'view_own' =>
array (
),
'update' =>
array (
0 => 2,
),
'update_own' =>
array (
0 => 2,
),
'delete' =>
array (
0 => 2,
),
'delete_own' =>
array (
0 => 2,
),
),
'#name' => 'content_access_action_revoke_node_permissions',
'#info' =>
array (
'label' => 'Revoke content permissions by role',
'arguments' =>
array (
'node' =>
array (
'type' => 'node',
'label' => 'Content',
),
),
'module' => 'Content access',
),
'#weight' => 0,
),
),
'#version' => 6003,
),
'rules_2' =>
array (
'#type' => 'rule',
'#set' => 'event_node_insert',
'#label' => 'new discussion grants edit and delete permissions',
'#active' => 1,
'#weight' => '0',
'#categories' =>
array (
),
'#status' => 'custom',
'#conditions' =>
array (
1 =>
array (
'#weight' => 0,
'#type' => 'condition',
'#settings' =>
array (
'type' =>
array (
'discussion' => 'discussion',
),
'#argument map' =>
array (
'node' => 'node',
),
),
'#name' => 'rules_condition_content_is_type',
'#info' =>
array (
'label' => 'Created content is discussion',
'arguments' =>
array (
'node' =>
array (
'type' => 'node',
'label' => 'Content',
),
),
'module' => 'Node',
),
),
0 =>
array (
'#weight' => 1,
'#info' =>
array (
'label' => 'Created content is new',
'arguments' =>
array (
'node' =>
array (
'type' => 'node',
'label' => 'Content',
),
),
'module' => 'Node',
),
'#name' => 'rules_condition_content_is_new',
'#settings' =>
array (
'#argument map' =>
array (
'node' => 'node',
),
),
'#type' => 'condition',
),
),
'#actions' =>
array (
0 =>
array (
'#weight' => 0,
'#info' =>
array (
'label' => 'Grant content permissions by role',
'arguments' =>
array (
'node' =>
array (
'type' => 'node',
'label' => 'Content',
),
),
'module' => 'Content access',
),
'#name' => 'content_access_action_grant_node_permissions',
'#settings' =>
array (
'#argument map' =>
array (
'node' => 'node',
),
'view' =>
array (
0 => 1,
1 => 2,
),
'view_own' =>
array (
0 => 1,
1 => 2,
),
'update' =>
array (
),
'update_own' =>
array (
0 => 2,
),
'delete' =>
array (
),
'delete_own' =>
array (
0 => 2,
),
),
'#type' => 'action',
),
),
'#version' => 6003,
),
),
)