Currently, to programmatically create or revoke grants on nodeaccess, we need to build $form and $form_state elements. Would be better to expose these operations as an API.

Comments

vlad.pavlovic’s picture

I couldn't agree more, this is definitely on my TODO list.

bogdog400’s picture

Issue summary: View changes

Yes, BUMP. Something that would make this all a bit less dangerous and complex. Building a $form is a waste just to take it apart.

samwilson’s picture

+1

bogdog400’s picture

I've been experimenting with this by just inserting the right line into the database table, nodeaccess. Is this dangerous? Are there some caching issues?

samwilson’s picture

Yes, I guess that works for individual-node permissions? (Does it?) I've been playing with similar things for the default content type and role-permissions by setting the nodeaccess_TYPENAME variable. So to e.g. give authenticated users read access to 'page' type nodes, the following:

$grants = array(array(
  'gid' => 2, // 2 is 'authenticated user'
  'realm' => 'nodeaccess_rid',
  'grant_view' => 1,
  'grant_update' => 0,
  'grant_delete' => 0,
));
variable_set('nodeaccess_page', $grants);

But really it all feels too hacky... :)

vlad.pavlovic’s picture

Added two new hooks: hook_nodeaccess_grants_alter and hook_nodeaccess_grant_alter

These will allow modification to all grants and individual grants, respectively.

vlad.pavlovic’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

bogdog400’s picture

Thanks very much. I haven't tried it yet, but I'm grateful you put in the time.