0

Workflow module lets you set who can change a certain state to what state. What modules can I use to be able to prevent a certain role from editing a node that is in a specific state?

Ex: if a node has been approved and is in Approved state, it should be final and can't be edited anymore by content authors.

2
  • Which Drupal version? It matters in this case.
    – mpdonadio
    Jul 15 '14 at 12:31
  • @MPD It's 7.x. I think I may have found a solution using the Workflow Access submodule in Workflow but it's not working as I expect. Still investigating.
    – radj
    Jul 16 '14 at 6:21
0

For this you should have to implement hook_node_grants and hook_node_access_records. It look something like that -

 /**
  * Implement @hook_node_grants 
  */
 function MODULENAME_node_grants($account, $op) {

  $grants =array();
  $grants['Node_Edit_Permission_Content'][]=array($account->uid);
  $grants['Node_Edit_Permission_OtherRole'][]=array($account->uid);
 return $grants;
}

/**
 * Implement @hook_node_access_records
 */
function MODULENAME_node_access_records($node) {

  $grants = array();

  if ($node->type == 'node_type') { 
    $user_id_content = /* list of user id which you want to block */;

     // Revoke Permissions from these Users
    if (!empty($user_id_content ) {
      foreach ($user_id_content as $uid) {
        if (isset($uid)) {

          $grants[] = array(
            'realm' => 'Node_Edit_Permission_Content',
            'gid' => $uid,
            'grant_view' => 1,
            'grant_update' => 0,
            'grant_delete' => 0,
            'priority' => 0,
          );
        }
      }
    }

    $user_id_other_role = /* list of user id which you want to block */;

     // Grant Permissions from these Users
    if (!empty($user_id_other_role ) {
      foreach ($user_id_other_role as $uid) {
        if (isset($uid)) {

          $grants[] = array(
            'realm' => 'Node_Edit_Permission_OtherRole',
            'gid' => $uid,
            'grant_view' => 1,
            'grant_update' => 1,
            'grant_delete' => 0,
            'priority' => 0,
          );
        }
      }
    }
  }

  return $grants;
}
1
  • Thanks for the sample code, Rahul. But I found a way to do this using modules.
    – radj
    Jul 17 '14 at 9:38
0

This can be accomplished using Workflow Access submodule in Workflow.

Steps:

  1. Enable Workflow Access submodule (assuming Workflow is already used like in OP)
  2. Go admin/config/workflow/workflow/manage
  3. Click the access link on the workflow that applies to the node type
  4. Uncheck the roles that should not be able to edit in the given listed states

When I posted this info, I was using Workflow (and the submodules) version 2.3 and the author could still edit the node after performing the steps above. After updating to 2.4 today, it has worked fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.