1

There is only one Content Type in my site and two vocabularies ,say, vocabulary1 and vocabulary2. Now I don't want some roles to access some content due to their vocabulary.

Can I set access permission to roles due to the content's vocabulary???

thanks!

2 Answers 2

0

Yes. There are a number of ways.

1 Look at taxonomy_access http://drupal.org/node/200631. This permissions model almost duplicated 'organic groups' functionality with taxonomy. Organic groups is another way of restricting content to a particular 'community of interest' which is likely to be related to a particular information slice. Two possible module/solution oriented approaches.

The next two solutions involve module/code writing.

2. Create a custom menu that runs the display. This could invoke a view block or any other block. Write an access callback. e.g.

// test interface for the editors report. It is intended to be put in a block.
$items[HOTTOPICSNOTIFY_MODULE_NAME . '/editors-report/%'] = array(
    'title' => 'Editors Report',
    'access callback' => 'hottopicsnotify_access_callback',
    'access arguments' => array(3),
    ...
  );

Then in the callback write your logic. % may be the taxonomy term, meaning that you can use this to query against allowed users.

Check out the menu examples module at api.drupal.org/api/examples/menu_example

3 Create node-access realms and assign them to people. e.g. when you save a node under a taxonomy make sure it has a realm relating to the taxonomy

/**
 * 
 * 
 * This marks a node as being applicable to a particular type of permission related to a taxonomy.
 * 
 * 
 * @param type $node
 */
function hottopics_node_access_records($node) {
  $grants = array();

  if ($node->type == 'hot_topic_research' || $node->type == 'hottopics') {
    $grants[] = array(
      'realm' => 'view_hottopics_fish_biology',
      'gid' => 1,
      'grant_view' => 1, // unpublished content is fine.
      'grant_update' => 1,
      'grant_delete' => 1,
      'priority' => 100, // bigger numbers make this more authoritative
    );

  }


  return $grants;
}

See hook_node_access_records

Then hook_node_grants gets called when the user tries to access the content, or it is brought up in a views index. This is the strength of this approach, you can use existing views module generated blocks.

/**
 * Provide access to a realm to a user. 
 * 
 * 
 * @param type $account
 * @param type $op
 * @return int
 */
function hottopics_node_grants($account, $op) {
  $grants = array();

  if ($op == 'view') {
    // Hot topics editorial board gets all hot topic grants
    $roles = array_values($account->roles);
    if (array_search('editorial board admin', $roles) !== FALSE || array_search('editorial board member', $roles) !== FALSE) {
      $grants['view_hottopics_fish_biology'] = array(1);
    }

  }
  return $grants;
}

See hook_node_grants api.drupal.org/api/drupal/modules!node!node.api.php/function/hook_node_grants/7

1
0

Have you tried these Drupal modules (quotes included are from their project pages):

Access control for user roles based on taxonomy categories (vocabulary, terms).

  • Automatically controls access to nodes (based on their taxonomy terms).
  • Configuration page for each user role.
  • Three node access permission types: View, Update, Delete.
  • Two term access types: View tag, Add tag.

The ACL module, short for Access Control Lists, is an API for other modules to create lists of users and give them access to nodes. It has no UI of its own and will not do anything by itself; install this module only if some other module tells you to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.