0

in a drupal 7 site i have been given to maintain, it seems that permissions are not working as expected. I check and uncheck the buttons for a certain user role, but that user role always has the right to edit any node that belongs to this particular type. 1. What could be the cause for this? 2. If this is not working from the gui, how i could achieve something similar with code? I would appreciate an example

1

In /admin/people/permissions Under "Node" category you can uncheck the permission "Edit content X" for your desired role.

I would recommend using this module if your site has a lot of modules/permissions since due max upload vars limitation by PHP could led to not storing your chages when submitting the form.

Also by code you can implement hook_node_access and put there some logic. Take a look on how core does it.

/**
 * Implements hook_node_access().
 */
function node_node_access($node, $op, $account) {
  $type = is_string($node) ? $node : $node->type;

  if (in_array($type, node_permissions_get_configured_types())) {
    if ($op == 'create' && user_access('create ' . $type . ' content', $account)) {
      return NODE_ACCESS_ALLOW;
    }

    if ($op == 'update') {
      if (user_access('edit any ' . $type . ' content', $account) || (user_access('edit own ' . $type . ' content', $account) && ($account->uid == $node->uid))) {
        return NODE_ACCESS_ALLOW;
      }
    }

    if ($op == 'delete') {
      if (user_access('delete any ' . $type . ' content', $account) || (user_access('delete own ' . $type . ' content', $account) && ($account->uid == $node->uid))) {
        return NODE_ACCESS_ALLOW;
      }
    }
  }

  return NODE_ACCESS_IGNORE;
}
| improve this answer | |
  • permissions via GUI do not take into effect. The module also did not help. How the above code should be transformed to a module, so as a user role cannot edit a certain content type? – hevi Jan 18 at 10:19
0

In answer to your first question, this existing answer about debugging access permissions should be able to help you uncover what is causing this unexpected behavior.

https://drupal.stackexchange.com/a/17435/34061

| improve this answer | |

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.