天天看點

drupal自定義node權限

使用HOOK_node_access_records    和    HOOK_node_grants(圖形化組合(個人了解沒有權威性,僅供參考)) 這兩個鈎子 代替 HOOK_node_access 

1/ 首先介紹下HOOK_node_access  他是用寫代碼的方式來判斷使用者有沒有權限來通路,編輯,删除一個node的權限,如下:
//這裡根據你的條件做以下傳回
           
return NODE_ACCESS_IGNORE;
           
<pre name="code" class="php">    return NODE_ACCESS_DENY;
           
return NODE_ACCESS_ALLOW;
           
}
           

2/ 使用HOOK_node_access_records    和    HOOK_node_grants這個圖形化組合

    首先聲明  HOOK_node_grants  這個鈎子會在node的以下3種情況中被調用,并且向node_access表中添加相應的記錄, 如下:

    3種情況分别是: 這三個函數都在node.module裡面

       node_save

       node_access_rebuild   這裡包括一個batch(_node_access_rebuild_batch_operation)

$grants[] = array(
           
'realm' => 'node_access_custom_edit',
           
'gid' => $gid,
           
'grant_view' => 1,
           
'grant_update' => 1,
           
'grant_delete' => 1,
           
'priority' => 0,
           
);
           
</pre><p></p><p></p><pre name="code" class="php">      $grants[] = array(
           
'realm' => 'node_access_custom_author',
           
'gid' => $node->uid,
           
'grant_view' => 1,
           
'grant_update' => 1,
           
'grant_delete' => 1,
           
'priority' => 0,
           
);
           
return $grants;
           
}
           

    其次權限比較:

      在HOOK_node_access 中 使用這個函數  

              module_implements('node_grants') 将所有node_grants實作, 如下:

function node_access_example_node_grants($account, $op) {

  $grants = array();

  // First grant a grant to the author for own content.

  // Do not grant to anonymous user else all anonymous users would be author.

  if ($account->uid) {

    $grants['node_access_example_author'] = array($account->uid);

  }

  // Then, if "access any private content" is allowed to the account,

  // grant view, update, or delete as necessary.

  if ($op == 'view' && user_access('access any private content', $account)) {

    $grants['node_access_example_view'] = array(NODE_ACCESS_EXAMPLE_GRANT_ALL);

  }

  if (($op == 'update' || $op == 'delete') && user_access('edit any private content', $account)) {

    $grants['node_access_example_edit'] = array(NODE_ACCESS_EXAMPLE_GRANT_ALL);

  }

  return $grants;

}

進行real  gid  為一組  多個 取or的條件進行查詢  詳情請看node_access函數實作,

剩下的你就到背景圖像化界面配置就好了。