Writing Directly To node_access Table
I've written a module that allows an admin to specify access to a project node (using the Project module) at a user level. There is an admin page with a separate form for each project in a collapsible fieldset where the user can select which users have access for each project. I'm using hook_node_access_records() and hook_node_grants() to write access records to node_access. The one big problem I have is that hook_node_access_records is only called when the node is saved. I would like to allow the admin to be able to set the access on the admin page and have it take effect right away, instead of then having to go in and save each project node for the records to be written to node_access. Is there a problem with writing directly to the node_access table, such as in the submit function for my form? That way, the access records would already be available the next time the node is access. If I do that, do I have to do something like call node_access_rebuild at some point after the data has been written to the table? Thanks. Steve
On Dec 13, 2007, at 10:12 PM, Steve Edwards wrote:
the user can select which users have access for each project
http://drupal.org/project/og_project is probably the way you should solve this problem. That module needs a lot of love, but has enormous potential. Cheers, -Derek (dww)
you can use something like: node_access_write_grants($node, $grants, 'ejrn'.$article->jid); constructing correctly the $grants array. I have found other odds though. node_access_write_grants does not know how to do update. So in my module: //unfortunately, the node_write_access function does not do update //so we need to update the authors access rights by ourselves because there the gid = user->uid //and delete would get rid of that completely function _ejournalaccess_grant_update($nid = 0, $grants = array()) { db_query("UPDATE {node_access} SET grant_view=%d, grant_update=%d, grant_delete=%d WHERE nid=%d AND realm='%s'", $grants['view'], $grants['update'], $grants['delete'], $nid, $grants['realm']); } however right solutions for me would be to maintain a separate table with authors uid, in that way gid can be general roman On Dec 14, 2007 7:12 AM, Steve Edwards <killshot91@comcast.net> wrote:
I've written a module that allows an admin to specify access to a project node (using the Project module) at a user level. There is an admin page with a separate form for each project in a collapsible fieldset where the user can select which users have access for each project. I'm using hook_node_access_records() and hook_node_grants() to write access records to node_access. The one big problem I have is that hook_node_access_records is only called when the node is saved. I would like to allow the admin to be able to set the access on the admin page and have it take effect right away, instead of then having to go in and save each project node for the records to be written to node_access. Is there a problem with writing directly to the node_access table, such as in the submit function for my form? That way, the access records would already be available the next time the node is access. If I do that, do I have to do something like call node_access_rebuild at some point after the data has been written to the table?
Thanks.
Steve
Quoting Steve Edwards <killshot91@comcast.net>:
Is there a problem with writing directly to the node_access table, such as in the submit function for my form? That way, the access records would already be available the next time the node is access. If I do that, do I have to do something like call node_access_rebuild at some point after the data has been written to the table?
You've eluded to the problem with your other questions of course. The issues with writing to the table yourself becomes what happens when module bar also updates node_access. And then module baz also. It becomes a nightmare of what modules are doing what updates. The better solution would be to call node_access_write_grants yourself. Earnie -- http://for-my-kids.com/ -- http://give-me-an-offer.com/
for your own custom site, thats fine. for Contrib, thats a problem becuase you don't know what other node access modules are running. Their grants might have higher priority. I guess you could ship your module with a hook_requirements() that yells if another node access module is found. On Dec 14, 2007, at 1:12 AM, Steve Edwards wrote:
I've written a module that allows an admin to specify access to a project node (using the Project module) at a user level. There is an admin page with a separate form for each project in a collapsible fieldset where the user can select which users have access for each project. I'm using hook_node_access_records() and hook_node_grants() to write access records to node_access. The one big problem I have is that hook_node_access_records is only called when the node is saved. I would like to allow the admin to be able to set the access on the admin page and have it take effect right away, instead of then having to go in and save each project node for the records to be written to node_access. Is there a problem with writing directly to the node_access table, such as in the submit function for my form? That way, the access records would already be available the next time the node is access. If I do that, do I have to do something like call node_access_rebuild at some point after the data has been written to the table?
Thanks.
Steve
participants (5)
-
Derek Wright -
Earnie Boyd -
Moshe Weitzman -
Roman Chyla -
Steve Edwards