Node access rights

  1. 7.x drupal-7.x/modules/node/node.module node_access
  2. 6.x drupal-6.x/modules/node/node.module node_access

The node access system determines who can do what to which nodes.

In determining access rights for a node, node_access() first checks whether the user has the "administer nodes" permission. Such users have unrestricted access to all nodes. Then the node module's hook_access() is called, and a TRUE or FALSE return value will grant or deny access. This allows, for example, the blog module to always grant access to the blog author, and for the book module to always deny editing access to PHP pages.

If node module does not intervene (returns NULL), then the node_access table is used to determine access. All node access modules are queried using hook_node_grants() to assemble a list of "grant IDs" for the user. This list is compared against the table. If any row contains the node ID in question (or 0, which stands for "all nodes"), one of the grant IDs returned, and a value of TRUE for the operation in question, then access is granted. Note that this table is a list of grants; any matching row is sufficient to grant access to the node.

In node listings, the process above is followed except that hook_access() is not called on each node for performance reasons and for proper functioning of the pager system. When adding a node listing to your module, be sure to use db_rewrite_sql() to add the appropriate clauses to your query for access checks.

To see how to write a node access module of your own, see node_access_example.module.

File

drupal-6.x/modules/node/node.module, line 1966
The core that allows content to be submitted to the site. Modules and scripts may programmatically submit nodes using the usual form API pattern.

Functions

Namesort descending Location Description
hook_access documentation-6.x/developer/hooks/node.php Define access restrictions.
hook_node_access_records documentation-6.x/developer/hooks/core.php Set permissions for a node to be written to the database.
hook_node_grants documentation-6.x/developer/hooks/core.php Inform the node access system what permissions the user has.
node_access drupal-6.x/modules/node/node.module Determine whether the current user may perform the given operation on the specified node.
node_access_acquire_grants drupal-6.x/modules/node/node.module Gets the list of node access grants and writes them to the database.
node_access_grants drupal-6.x/modules/node/node.module Fetch an array of permission IDs granted to the given user ID.
node_access_needs_rebuild drupal-6.x/modules/node/node.module Flag / unflag the node access grants for rebuilding, or read the current value of the flag.
node_access_rebuild drupal-6.x/modules/node/node.module Rebuild the node access database. This is occasionally needed by modules that make system-wide changes to access levels.
node_access_view_all_nodes drupal-6.x/modules/node/node.module Determine whether the user has a global viewing grant for all nodes.
node_access_write_grants drupal-6.x/modules/node/node.module Writes a list of grants to the database, deleting any previously saved ones.
node_db_rewrite_sql drupal-6.x/modules/node/node.module Implementation of hook_db_rewrite_sql
_node_access_join_sql drupal-6.x/modules/node/node.module Generate an SQL join clause for use in fetching a node listing.
_node_access_rebuild_batch_finished drupal-6.x/modules/node/node.module Post-processing for node_access_rebuild_batch.
_node_access_rebuild_batch_operation drupal-6.x/modules/node/node.module Batch operation for node_access_rebuild_batch.
_node_access_where_sql drupal-6.x/modules/node/node.module Generate an SQL where clause for use in fetching a node listing.