Hi,

it would be great if you could integrate attached patch, allowing other modules to step in to the grants generation process and allow changing them. For example, you can integrate special conditions to the grants. OR, you could create a simple module to solve #461360: Node Access based on user reference from related node for you. Possibilities are open :-)

Such module will then have to implement function:

function hook_nodeaccess_userreference_grants_alter(&$grants, $node) {
}

And do whatever it wants with the grants.

CommentFileSizeAuthor
naur_change_grants.patch705 bytesmeba

Comments

danielb’s picture

I do not think this module is the place for such a thing. If anything, it should be Drupal's node access system to implement this feature. Anything you can do here with drupal_alter could be done just by doing what this module already does - checking form submission values and providing node access hooks.
What do you need this for? I would like to see more discussion on this.

meba’s picture

First, I have taken this feature from Organic Groups, it's implemented the same way in og_access. Second - it's really important to mention how Drupal 6 node access system works: Once access is allowed, nothing can deny it.

Now what exactly I need - I am referencing users in the node to allow access. But if the workflow state (Workflow module) of the node is "expired", I need to disallow access no matter that users are referenced.

Using a current system, I can't create own module and disallow access if workflow state == expired. NAUR will still allow it -> access is allowed. That's why I need to alter the grants. I am succesfully using the same feature from OG and it works flawlesly.

Drupal will never support such thing in current versions. I am happy to post a solution for Drupal 7, but 6.x and 5.x are not accepting modifications except bugfixes. That's why I would like to see this patch in. We can remove it for Drupal 7 later.

meba’s picture

My implementation:

/**
  * Implementation of hook_nodeaccess_userreference_grants_alter().
  *
  * Check if workflow state is 9 (expired) and remove access to everybody for this realm.
  */
function og_csr_roles_nodeaccess_userreference_grants_alter(&$grants, $node) {
  if ($node->_workflow == 9) {
    for ($i = 0 ; $i < count($grants); $i++) {
      $grants[$i]['grant_view'] = 0;
    }
  }
}
danielb’s picture

Status: Needs review » Active

OK well if OG provides this, then at least there is some precedent for it, and I won't feel as awkward doing it.

The ideal solution would be to use db_rewrite_sql in the same way the node access system does to add some joins/wheres for the workflow condition - but this is probably rather difficult.

In Drupal 7 the database layer will provide a hook_query_alter which has been recommended for use as an alternative to using node access.

I will get around to committing this when I can.

danielb’s picture

There also another drupal 7 issue of interest here http://drupal.org/node/309007

meba’s picture

Exactly. Once this lands in D7, this patch won't be needed. But for D6, we have no other way :( Thanks for considering including it, it might help others and will help my new site free of patches.

meba’s picture

Daniel, did you have time to look commit this issue? Is there anything I can do to help? Let me know, thanks!

danielb’s picture

Status: Active » Fixed

I've made a new release just for this.

Status: Fixed » Closed (fixed)

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

hefox’s picture

Was looking At the new release to see what has changed and saw this.

It is possible to alter grants outside of having a hook in the module since grants have priority. Simply get all the grants (I use static), alter at will, return with a higher priority. I made a module for this, but haven't released it since it was for a client, but it's how I combined for a project using og_access, workflow_access, this module, and a custom module.

Ah, too late but all well.

Anonymous’s picture

hefox, I'm desperately trying to find a way to combine og_access and workflow_access and came across your post. Do you have an example of what you mean by "Simply get all the grants (I use static), alter at will, return with a higher priority."? Many thanks!