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 "bypass node access" permission. Such users have unrestricted access to all nodes. user 1 will always pass this check.
Next, all implementations of hook_node_access() will be called. Each implementation may explicitly allow, explicitly deny, or ignore the access request. If at least one module says to deny the request, it will be rejected. If no modules deny the request and at least one says to allow it, the request will be permitted.
If all modules ignore the access request, 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 (lists of nodes generated from a select query, such as the default home page at path 'node', an RSS feed, a recent content block, etc.), the process above is followed except that hook_node_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 a dynamic query created by db_select() and add a tag of "node_access". This will allow modules dealing with node access to ensure only nodes to which the user has access are retrieved, through the use of hook_query_TAG_alter(). Tagging a query with "node_access" does not check the published/unpublished status of nodes, so the base query is responsible for ensuring that unpublished nodes are not displayed to inappropriate users.
Note: Even a single module returning NODE_ACCESS_DENY from hook_node_access() will block access to the node. Therefore, implementers should take care to not deny access unless they really intend to. Unless a module wishes to actively deny access it should return NODE_ACCESS_IGNORE (or return nothing) to allow other modules or the node_access table to control access.
To see how to write a node access module of your own, see node_access_example.module.
File
- core/
modules/ node/ node.module, line 2600 - The core module that allows content to be submitted to the site.
Functions
Name | Location | Description |
---|---|---|
hook_node_access |
core/ |
Controls access to a node. |
hook_node_access_records |
core/ |
Set permissions for a node to be written to the database. |
hook_node_access_records_alter |
core/ |
Alter permissions for a node before it is written to the database. |
hook_node_grants |
core/ |
Inform the node access system what permissions the user has. |
hook_node_grants_alter |
core/ |
Alter user access rules when trying to view, edit or delete a node. |
node_access |
core/ |
Access callback: Checks a user's permission for performing a node operation. |
node_access_acquire_grants |
core/ |
Gets the list of node access grants and writes them to the database. |
node_access_grants |
core/ |
Fetches an array of permission IDs granted to the given user ID. |
node_access_needs_rebuild |
core/ |
Toggles or reads the value of a flag for rebuilding the node access grants. |
node_access_rebuild |
core/ |
Rebuilds the node access database. |
node_access_view_all_nodes |
core/ |
Determines whether the user has a global viewing grant for all nodes. |
node_list_permissions |
core/ |
Helper function to generate standard node permission list for a given type. |
node_node_access |
core/ |
Implements hook_node_access(). |
node_permissions_get_configured_types |
core/ |
Returns an array of node types that should be managed by permissions. |
node_query_entity_field_access_alter |
core/ |
Implements hook_query_TAG_alter(). |
node_query_node_access_alter |
core/ |
Implements hook_query_TAG_alter(). |
_node_access_rebuild_batch_finished |
core/ |
Performs post-processing for node_access_rebuild(). |
_node_access_rebuild_batch_operation |
core/ |
Performs batch operation for node_access_rebuild(). |
_node_access_write_grants |
core/ |
Writes a list of grants to the database, deleting any previously saved ones. |
_node_query_node_access_alter |
core/ |
Helper for node access functions. |
_node_search_query_alter |
core/ |
Exclude nodes from the search query in the special situations. |