One problem that I've seen crop up several times in the Module Grants issue queue is that multiple node access modules don't interact in the way that the user would expect. One of the reasons for this, I think, is because the requirement that node access be granted for each and every node access module is too strict based on how most node access modules have been built.

Let me give an example. Let's say I have several node types, and am using a workflow with Workflow Access on only one of them. And let's also say that I'm using TAC-lite to limit access on a taxonomy that's only being used on one node type -- a different one that has the workflow. Here's what happens with Module Grants -- because the node type with the taxonomy doesn't have a workflow, all access is blocked to it because Workflow Access has nothing to say about it. And vice versa, all access is blocked to the node type with a workflow because TAC-lite has nothing to say about it. Only in the case where we want both TAC-lite and Workflow Access to operate on a particular node type does one get the expected behavior.

My solution for this is to add a configurable setting that, when enabled, enforces access for multiple node access modules only when *both* of them have a row in the node access table for that particular nid. In other words, it enforces an AND between multiple node access modules only when they have an explicit setting.

Attached is a patch that adds this setting. It works great on my local setup where I'm using Workflow Access and a second custom node access module that acts a lot like TAC-lite. Without it, I'd have to add empty shell workflows to multiple node types.

I think there's even an argument for making this the default setting, and using the setting to turn on the stricter implicit AND. But regardless, I think this option makes Modules Grants more useful in a wider range of applications.

CommentFileSizeAuthor
module_grants_explicit.patch3.99 KBmcarbone
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

RdeBoer’s picture

Great idea Marco! Makes a lot of sense to me.
I will have a closer look at your patch soon.
Rik

RdeBoer’s picture

Assigned: mcarbone » RdeBoer
Status: Needs review » Needs work
mcarbone’s picture

I see that you've taken this over, but I wanted to point out a bug I found in my code. The line that checks for realms should actually be:

        $result = db_result(db_query("SELECT COUNT(*) FROM {node_access} WHERE nid = %d AND realm IN ('" . implode("','", array_keys($module_grants)) . "')", $nid));

Otherwise the single quotes will be escaped to avoid sql injection. Since there's no risk of sql injection from $module_grants, it's safe to implode that directly in the query.

RdeBoer’s picture

Thanks! I hope to get to do this soon.

RdeBoer’s picture

This feature is now available for download in version 6.x-2.3.

RdeBoer’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

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