You are here

function _module_grants_user_node_access in Module Grants 6.3

Same name and namespace in other branches
  1. 6.4 module_grants.module \_module_grants_user_node_access()

Similar to user_access() but also takes node info into account. Returns a node operation, to be checked by module_grants_node_access().

Parameters

$revision_op: Revision operation for which associated user permission is checked, e.g. 'view revisions'

$node:

Return value

bool FALSE if the $revision_op is known to Module Grants but not permitted on this node, 'view', 'update' or 'delete' otherwise

1 call to _module_grants_user_node_access()
module_grants_node_revision_access in ./module_grants.module
Menu options dealing with revisions have their revision-specific permissions checked via user_access(), before being tested for the associated node-specific operation. Return a boolean indicating whether the current user has access to the requested…

File

./module_grants.module, line 379
Module to apply access grants to pre-published content just as they are to published content and to make multiple content access modules work together in the expected way.

Code

function _module_grants_user_node_access($revision_op, $node) {
  switch ($revision_op) {
    case 'view revisions':

      // Suppress Revisions tab when there's only one revision -- consistent with core.
      if (!user_access('view revisions') || $node->num_revisions == 1) {
        return FALSE;
      }
      break;
    case 'view revision list':

      // Suppress Revision summary when there's only one revision.
      if (!user_access('view revisions') || $node->num_revisions == 1) {
        return FALSE;
      }
      break;
    case 'revert revisions':
      return user_access('revert revisions') ? 'update' : FALSE;
    case 'delete revisions':

      // Don't need 'delete revisions' permission when deleting node of 1 revision
      return user_access('delete revisions') || $node->num_revisions == 1 ? 'delete' : FALSE;
    default:
      drupal_set_message(t('Unknown Module Grants operation %op', array(
        '%op' => $revision_op,
      )), 'warning', FALSE);
  }
  return 'view';
}