Closed (fixed)
Project:
User Relationships
Version:
6.x-1.0-beta7
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
4 Mar 2008 at 15:47 UTC
Updated:
30 Jul 2008 at 21:14 UTC
Jump to comment: Most recent file
Comments
Comment #1
sprsquish commentedHey, thanks for this.
There are some issues though. They're the same problems I ran in to when I was trying to write this very same plugin type.
When node_access is called the op and node are passed in. After some checks node_access_grants is called. This is basically a wrapper around hook_node_grants that ensures a uid is set. If a user isn't passed in node_access_grants sets it as the current user then passes that on to all node_grants hooks. The user object and the operation are sent to the hooks. In this case it's the current user and to operation they'd like to perform. So the patch you sent looks up all the relationships the current user has, adds them to the list then adds the current user to the list. In essence you're giving access to the current user and all their friends.
Like I said, I've hit these same problems before. I don't really see them being solved well without the node being passed into hook_node_grants
Comment #2
sprsquish commentedComment #3
jbrown commentedI don't think you understand the node access system correctly. Its pretty much the hardest thing to get your head around in Drupal.
http://api.drupal.org/api/group/node_access/5
Here is how my module works:
user_relationship_private_nodes_node_access_records() is called when the node is saved to determine the author of the node (gid - grant id) and what relationships (realms) the viewer can have to be permitted to view the node. This information is stored in {node_access}.
When the nodes are to be viewed, user_relationship_private_nodes_node_grants() is called to determine what relationships (realms and gids) the user who is attempting to view the node has.
node_access() or (db_rewrite_sql() for listings) then looks up {node_access} to determine if the viewer has at least one realm with the gid (uid) of the node author.
Comment #4
sprsquish commentedoooohhhh.. okay, I think I see it now. It does work, it's just really inefficient, which is really no fault of yours.
Then the only issue I have with the module is that it queries the user_relationships and user_relationship_types tables directly. It should use the API for those operations.
Comment #5
jbrown commentedI think it is really efficient. The Drupal node access system is really clever.
user_relationship_private_nodes_node_access_records() is only called when saving the node or rebuilding {node_access} (when the modules page gets submitted).
user_relationship_private_nodes_node_grants() is only called once per page view. When viewing a node listing db_rewrite_sql() modifies the query to join with {node_access}. Obviously there is overhead, but it is considerably quicker than doing a query per node.
I have attached an updated version of the module. It only does one query in user_relationship_private_nodes_node_grants().
What API functions do you recommend I use?
Comment #6
jbrown commentedby the way, the Devel Node Access module in the devel package is really useful when trying to understand the drupal node access system
Comment #7
jbrown commentedThe was a minor bug where sometimes the node author could not view the node. This is now fixed.
Comment #8
jbrown commentedOkay - latest version.
It now uses user_relationships_types_load() and user_relationships_load().
I think it would be great if:
The module keeps getting smaller!
Comment #9
sprsquish commentedThank you so much for your work on this. I'm gonna dig deeper in to how the node access system works cause I clearly don't understand it well enough.
After I got done with it, the module actually grew and got a name change. I added support for update and delete and made the name more generic. I also added support for one-way relationships.
Here's the patch, let me know if it works for you and what you think. I'll commit it after I get your okay.
BTW, if you're using git I have some invites to GitHub. I'll send it over if you want it, then we wont need this patch process.
Regarding your other requests:
Comment #10
jbrown commentedI like it.
Why do you only allow the node author to change the node access permissions? This even prevents uid 1 from changing it. Surely if a user has the right to edit the node, then they should be able to edit the node access permissions.
There should be a user permission called something like 'control user relationship node access'.
Also, I think the view/edit/delete permissions should be in table format with each relationship type having a row. A bit like on admin/user/access .
There could also be a node type configuration where the admin can configure whether each of view/edit/delete node access permissions are allowed for that node type.
The other points:
Comment #11
jbrown commentedAlso, see this: http://groups.drupal.org/node/4261
Comment #12
sprsquish commentedThinking back on it, I'm not exactly sure why I set it up so only the author could set permissions. That's been redacted.
I added the permission. I think it's a good way to go.
Don't know why I hadn't thought of using a table for the view. I was stuck on the Content Access way of doing it (floated divs) and didn't like that so much.
I'll work out the more fine grained permissions later
Attached is a diff of only the changes listed above.
Comment #13
sprsquish commentedAdded to both the 2.x and 3.x branches
Comment #14
sprsquish commentedand now 6.x-1.x
Comment #15
jbrown commentedIt was great working with you.
Comment #16
mariusooms commentedHi...I realize it it's 4 months later now, but quoting jbrown:
"There could also be a node type configuration where the admin can configure whether each of view/edit/delete node access permissions are allowed for that node type."
Will this still be implemented? It's a bit silly when I have all the permissions for the node module set up so that users can only create, edit and delete their own content. So in the node view I'd only like to see the option 'view'. The other two choices don't apply, so why even list them. Does that make any sense?
Kind regards,
Marius