I've been trying to use the feature added in #1231248: Add create permissions but referenced users don't seem to be gaining any create permissions.
As I understand it, if I have a content type "Parent" with a user_reference field attached to it and I set the field to grant create permission for the content type "Child" then any user that is referenced in any Parent node should be able to create a Child node. Is this the way it's supposed to work?
Assuming that's the intent for the feature, there seem to be some issues in the code that are preventing the feature from functioning properly:
- The condition at line 384 is expecting an object but receiving an array, so it can never be TRUE.
- Using my Parent/Child example, the $field_data variable is only set when $node is a Parent, because a Child doesn't have a user_reference field attached. Therefore the condition is only TRUE if you try to grant permission to create a Parent, not a Child.
- The call to field_get_items() fails because it receives a string instead of a node object.
- The code seems to be trying to check whether the user is referenced in a specific node, rather than in any Parent node.
I've modified the code to get it doing what I think it's supposed to do. I've also added support for entityreference fields since the SQL query only worked for user_reference fields. See attached patch.
Could someone confirm my understanding of the feature and test the patch?
| Comment | File | Size | Author |
|---|---|---|---|
| nodeaccess_userreference-create_grants.patch | 3.94 KB | morbiD |
Comments
Comment #1
danielb commentedYou're probably right, I will test out your patch when I get a chance.
Comment #2
danielb commentedI've committed your patch based on your excellent explanation and a quick glance at the code.
Thanks!