Closed (won't fix)
Project:
Drupal core
Version:
6.x-dev
Component:
menu system
Priority:
Normal
Category:
Task
Assigned:
Reporter:
Created:
26 Feb 2007 at 18:28 UTC
Updated:
7 Mar 2007 at 23:31 UTC
Jump to comment: Most recent file
Originally I wanted to flat out permissions store but that did not fly. So I use roles. I believe the speedup is signifcant as we now store per page mid per rid menu items in menu_roles_cache thus do not access check all those items. Also this should let you grant 'administer comments' prviledge and see that item while 'administer' is not seen.
The patch is not tested at all for non-uid 1 users.
This is what to test: make it so that a role has empty menu and check the relevant variable is filled. Try the above mentioned 'administer comments' thing. Try various combinations, like granting a permission to two roles and give both roles a user, will the menu item double?
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | menu_70.patch | 17.84 KB | chx |
| #13 | menu_69.patch | 22.12 KB | chx |
| #12 | menu_68.patch | 25.39 KB | chx |
| #10 | menu_67.patch | 25.8 KB | chx |
| #8 | menu_66.patch | 24.81 KB | chx |
Comments
Comment #1
dopry commentedHere is an updated version with a proper system_install for mysql.
Working from a fresh install, everything is fine from install.php to initial uid 1 creation. I can add a new user. The form redirects me back to the new user form after I submit a new user user.
However once I logout and login as another user blocks disappear and all pages return not found or access denied.
Comment #2
chx commentedThis still does not work but it has no errors at least.
Comment #3
chx commentedThis works for a change. Known issue: when u grant 'administer comments' perm. then the 'comments' menu link wil be indented , bad HTML etc because line 488 checks for depth instead of 'effective depth' or whatever. This function needs some love apparently.
Comment #4
chx commentedFixed the problem. And fixed comment/reply/%node while at it...
Comment #5
dopry commentedThe patch seems to work well. The code style is pretty clean. I'm having one issue with a fresh install where the menu_roles_cache data isn't quite right. Its inconsistent if I call menu_rebuild as uid=1 and menu_rebuild as another role.
to reproduce start with HEAD patched with menu_65.patch and empty db.
Run installer.
create admin user.
add a new user.
add access comment permissions to 'new user'.
logout as admin
login as 'new user'
I don't see create content or the link to administer comments until I navigate to the 'My Account' page.
It seems to be purely a caching issue. If I run menu_rebuild using the devel module as 'new user' the menu is fine. If I delete from menu_roles_cache while logged in as 'new user' it rights it self as well. It seems menu_tree or _menu_tree may be at fault as that is where data is inserted into menu_roles_cache.
It could probably use some doc around the recursion in _menu_tree.. It took me a moment to wrap my head around it, and I'm not sure I understand it just yet...
Comment #6
dopry commentedI meant add administer comments permission to 'authenticated user' role instead of add access comments permission to 'new user';
/me goes to sleep now.
Comment #7
m3avrck commentedStarting with a fresh install...
"Create content" block is shown and I have not even created UID=1 yet. Clicking the link to "node/add" says no node types have been added yet. Block still appears for "anon" users even after other accounts have been created. Still says "no content types defined".
Confirmed caching oddity. I created an "admin" role with all permissions checked. Then logged in as this user. When the login finished, I saw two links: "My account" and "logout" -- strange. I clicked "My Account" then the rest of the menu tree appeared. Actually, upon more testing, the whole menu tree disappears when I click on "create content" with this account. Once I click on on "create page" then it appears again. Seems the node/add default page is buggy.
Had another role called "mod" with a different user. Upon logging in, same "my account" and "logout" no other links. Clicking on "my account" and "create content" appears. I gave this user "administer nodes" and "administer content types" but none of those permissions show up in the menu tree. "administer taxonomy" doesn't either. I was then able to take this user to "/admin" and see the whole menu structure. If I clicked on "users" it said page awaits rewrite, menu structure disappeared, and no sublinks. Appears I could reach the root admin menus but no sub ones (except for the ones I had permission to).
Hope that helps!
Comment #8
chx commentedTry this. More SQL powah, and no dependency on $depth for the navigation block renderer -- it is sorted by depth but depth itself tells very little about the visible depth of the item, that's the crux of this issue.
Comment #9
chx commentedComment #10
chx commentedPhew! This was hard. So very hard. But I think we are there. I tried to write a novel for a comment because the query in there is quite complicated.
Comment #11
dries commentedI tried looking at this patch but it's too complex. I'll have to spend more time with it, but it would be helpful if (a) it was simplified and (b) better documented.
From what I can tell, there are multiple levels of caching and quite a few special cases ("0 means already checked"), etc. Also, I'm not a fan of parameters like '$access_check = TRUE' -- they are a source of security bugs.
While I do appreciate the work that went into this, I think we'll want to simplify this code quite a bit. Otherwise, it won't be very accessible to other people.
Comment #12
chx commentedLet's see again what this issue is about. I am covering two things: one, a feature is missing, two, access checking everything with PHP is not too speedy. Alas, there are a few menu items that are not permission checked (in core, these are user/%, logout, node/add/*. While could standardize on a "create $node_type" permission, the "not anonymous" is not really a permission. This means that we need to have dynamic access checking, no matter how hard we try.
As $access_check defaults to TRUE and as it's a menu internal function, I do not see this a potential security hole.
There are not multiple levels of caching, just one.
Please ask questions and I will comment more about them. There are already many comments, I tried to comment on every icky part.
I was able to simplify the code a bit (and this fixes a bug where too few things were loaded into the cache).
To understand the code, one could skip the cache loading query and I added a comment saying that.
Comment #13
chx commentedAlternative approach. As core has only 68 visible menu items it's not too big an effort to user_access each. Of course, there is some effort to skip that.
I tried to make user_access speedier.
Comment #14
ChrisKennedy commentedI made a separate issue to pull out the comment.module changes as they aren't related to permission checking: http://drupal.org/node/124742
Comment #15
chx commentedThe alternative, simpler approach is of equal speed to Drupal 5. I switched on all modules for Drupal 5 (minus menu) and Drupal 6 and ab -n 200 'd the front page. D5 and HEAD both produced figures between 4.5-4.6 requests/s on my machine. However, when adding all permissions to anonymous, then it happened: D5 remained the same but HEAD jumped to 4.8 requests/s, I reran ab to confirm it, but it's consistent. I am not surprised at all, this is what I hoped to happen because we jump over the admin/* permissions checking.
I removed the comments fix.
Comment #16
fgmFWIW, I find that this "feature" is counter-intuitive: in usual situations (file systems on *nix, win32, netware, NDS eDirectory...) not granting an access to the parent in a tree blocks access to all of its children, and forcing access to a child node with a specific ACL automatically opens a "traverse" (*nix: "x", NDS: "f") permission to parent nodes to allow logical access to that child, instead of magically displacing it in the tree depending on the permissions of the user.
Is there any reason why our menu system should behave differently ? Consistency with preexisting access models might ease learning this part of Drupal.
Comment #17
pwolanin commentedI'd agree that blocking access to children if parents are blocked makes more sense, though this places a (quite reasonable) burden on developers to make sure their menu structure and module-defined permissions are in sync.
Comment #18
chx commentedHappy, happy!