2

I have a content type named "Files". I have given access for users with roles editor 1, editor 2 and editor 3 to update and delete their own content.

Now If a user with editor 1 creates a files content. I need to allow other users with same role (editor 1) to update and delete the content.

I tried Content Access Module but it doesn't helps.

Can anyone give me a working example for this scenario.

2 Answers 2

1

The permission on "own content" is connected to the node's author's uid and only relates to role in that a user with the role holding that permission can edit a node they created.

How I would solve your use case is with a hook_node_access in a custom module. https://api.drupal.org/api/drupal/modules!node!node.api.php/function/hook_node_access/7 WARNING: I just threw this together as an example, I did not test, and you need to put in the right role values.

hook_node_access($node, $op, $account) {
  if( $op !== 'update'){
    // not my use-case
    return NODE_ACCESS_IGNORE;
  }

  $author = user_load($node->uid);
  if( in_array( 'role1', $author->roles) && in_array( 'role1', $account->roles) ) {
    // the user editing has the same role as the author
    return NODE_ACCESS_ALLOW;
  }
  // repeat ... etc.

  // we did not find what we were looking for, continue with normal access check
  return NODE_ACCESS_IGNORE;
}
0

It seems to me that with the Rules module (together with the Content Access module you already have) you can get this to work ... The rule to create in this case woud be a variation of what's described in Tutorial: editorial workflow with rules (within the paragraph "Create rules to publish the content").

In this case, the "action" would be to "Grant access by role".

Your Answer

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