You are here

function permissions_by_term_node_access in Permissions by Term 7

Same name and namespace in other branches
  1. 8.2 permissions_by_term.module \permissions_by_term_node_access()
  2. 8 permissions_by_term.module \permissions_by_term_node_access()

Implements hook_node_access().

Forwards user by drupal_access_denied(); to an access denied page, if a single restricted node is called.

File

./permissions_by_term.module, line 328
Allows access to terms in a vocabulary to be limited by user or role.

Code

function permissions_by_term_node_access($node, $op, $account) {
  if (isset($node->nid) && $op == 'view') {
    $node = node_load($node->nid);
    $secured_areas = field_get_items('node', $node, 'field_secured_areas');
    if (!empty($secured_areas)) {
      global $user;
      foreach ($secured_areas as $term) {
        $term_secured_areas = $term;
        if (isset($term_secured_areas['tid']) && permissions_by_term_allowed($term_secured_areas['tid'], $user) === TRUE) {
          $user_is_allowed_to_view = TRUE;
        }
        if (!isset($user_is_allowed_to_view)) {
          $user_is_allowed_to_view = FALSE;
        }
      }
    }
    if (isset($user_is_allowed_to_view) && $user_is_allowed_to_view === FALSE) {
      return NODE_ACCESS_DENY;
    }
  }
}