Use hook_node_access to deny access to nodes

Created on 7 March 2015, about 10 years ago
Updated 24 April 2025, 12 days ago

For comments it does make sense to use hook_menu_alter, as there is no better way of limiting comment access.

However for nodes this module should use hook_node_access (instead of hook_menu_alter) as this is the correct way of setting view/update/delete permissions on nodes.

This should clear a couple of issues in the queue related to this module not denying access in combination with other modules / use cases.

In my case, this module did not deny access in combination with the revisions module enabled. To solve this, I had to implement hook_node_access in a custom module returning NODE_ACCESS_DENY in case _edit_limit_user_acccess returns FALSE (which is bad as I'm forced to call your internal function).

In addition edit_limit_node_access is being called as a 'helper function' instead of as a hook which it is. Instead of returning NODE_ACCESS_DENY/ALLOW/IGNORE, it returns TRUE/FALSE in the module's code:

/**
 * Helper function to determine if the user has permissions to use whatever grants node_access()
 * grants to this user, as determined by the additional site membership checks.
 */
function edit_limit_node_access($op, $node, $account = NULL) {
  module_load_include('inc', 'node', 'node.pages');
  if (node_access($op, $node, $account)) {
    switch ($op) {
      case 'update':
        if (user_access('bypass edit limits')) {
          return TRUE;
        }
        return _edit_limit_user_acccess($node);
    }
  }
  return FALSE;
}
🐛 Bug report
Status

Closed: outdated

Version

1.0

Component

Code

Created by

🇩🇪Germany gbyte Berlin

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024