I set Workbench Access to base their permissions on menu:
- Menu of My Site
- - AAA
- - - BBB
- - - - CCC
- - - - - DDD
- - - - - - XXX
AAA,BBB,CCC,DDD,XXX - basic pages, their workbench sections are set to themselves,
i.e. DDD is in section DDD.
Now I create user. Now in order to edit "XXX" he has to be set as an editor of: "Menu of My Site", "AAA" or "XXX".
Any middle ones "BBB", "CCC", "DDD" doesn't give him permission of editing "XXX".
Is it messed up with my site? Maybe some inconsistencies in base or maybe this is how it was designed to work?
If I may provide some further details or logs - please let me know.
Comments
Comment #1
ExceptionHandler commentedDoes my report mean anything? Am I wrong saying that there's something wrong with this? I'm suprised because this feature is quite essential.
I looked into the code and found this dependency:
1st situation (attachment s1.png picture). Then I edit workbench_access.module, I put
print_r($info)on line 465, so in this case (opening node pointed by CCC) I see output:
Array ( [0] => 389 [1] => 390 [2] => 391 [3] => 437 )which corresponds perfectly to menu item which user is set to an editor. ( AAA: 389, ..., DDD: 437 )
Now I change to 2nd situation (attachment s2.png picture). Now I see (still at CCC) seeing output:
Array ( [0] => main-menu )which is not what you would expect considering output in previous case..
Is this how it should be? Maybe this was your purpose to make section descendancy only in case of 1st item in hierarchy or 2nd, and in case of 3rd level (or any higher) it doesn't inherit permission, only applies to single level.
/Sorry for any language inaccuracies, I'm doing my best to describe it./
Comment #2
ExceptionHandler commentedMy temporary solution:
Step 1: Add new function in workbench_access.module:
Step 2: now in file menu.workbench_access.inc, add else condition around line 130 to make it look like:
I hope some of module maintainers will finally make statement - is it bug/feature ;)
Comment #3
agentrickardCertainly looks like a bug. Not sure how to reproduce. Been working on #1101638: Default menu form support instead.
Comment #4
ExceptionHandler commentedI would be happy to help by providing some details needed to reproduce it. Should be easy though as I recreated it myself on new instance of drupal quickly.
Comment #5
agentrickardA nice bullet list of steps would be perfect, thanks.
Comment #6
ExceptionHandler commentedCode I pasted in one of my previous posts shows that list of editable nodes includes proper nodes only when user has mlid of root or first level children.
/ if it's not quite a list you expected – tell me /
Comment #7
jbylsma commentedI also ran into this issue. Here's my test menu system (ultra verbose!):
Nothing fancy. Next, a chart of capturing what a user within Workbench Access can edit, depending on the assigned section level.
X axis: User can update
Y axis: Assigned section level
The problem comes from the menu_workbench_access_tree and _workbench_access_menu_build_tree. menu_workbench_access_tree is only designed to work with root level (where $mlid == 0) or first level (where $mlid is one of the first level menu items). Items deeper than the first level don't trigger any of the _workbench_access_menu_build_tree code, which allows an initialized tree array to pass back the menu's name (root level) as a valid area. The proper section level (the direct descendent of the section) stills works because of the "Simple equivalence check" at the beginning of workbench_access_in_tree.
Though I didn't see the code in #1422868-2: Menu hierarchy - permissions descendancy before, my implementation was fairly similar. The patch was written against 7.x-dev.
Comment #8
jbylsma commentedHit enter too fast...
Comment #9
jbylsma commentedWhy not one more comment. Needs review. I haven't checked against "Allow multiple section assignments."
Comment #10
agentrickardNeeds better documentation of the changes and the new parameter. A test would be ideal, but difficult.
Comment #11
jbylsma commentedSorry, I should have remembered to document the parameter in the code. Were you also looking for better documentation of the recursive function in the code or a further explanation here on d.o (or something else)?
Are there are menu tests so far to extend? I quickly grepped the source but didn't see much.
Comment #12
Taxoman commentedComment #13
agentrickardBetter inline documentation of the recursive function.
Comment #14
agentrickardCleaned up version of the patch. Seems to work.
Comment #15
agentrickardCommitted.
Comment #16
fearlsgroove commentedThis change appears to be hiding top level menu items from being available as editorial sections. Reversing just this patch and clearing cache resolves the issue.
Comment #17
agentrickard/me gets irrational when no one tests patches before they get committed.
Comment #18
agentrickardI cannot replicate that issue using the Workbench Access form element. If you are using the native menu form, of course you cannot assign something to the top-level, because the Menu system doesn't allow it.
Comment #19
fearlsgroove commentedIt's not on the section element on the form, it's when deciding which menu entries are accessible as sections at admin/config/workbench/access/sections
Comment #20
agentrickardUm...
Comment #21
agentrickardWhen you say top-level, do you mean the Menu itself or the 1st-level children? Because I am missing 1st-level children.
Comment #22
agentrickardHere's a patch.
Comment #23
fearlsgroove commentedThat's right first level children are missing. Sorry for the unclear description.
Comment #24
agentrickardCross-post!
Note that screenshots are really helpful with this issue.
Comment #25
fearlsgroove commentedCross post ... That seems to fix it. Looks good to me
Comment #26
agentrickardCommitted!
Comment #27
jbylsma commentedAfter disappearing and now returning, I found an issue where empty menus don't return the "All of {menu}" option. Mostly unnecessary screenshot attached. I'll dig in this morning.
Comment #28
jbylsma commentedThe problem stems from having the initial $tree population within the menu_tree_all_data() $menu loop. If the menu is empty, menu_tree_all_data returns an empty array.
In an attempt to make life easier, I've attached two patches:
Comment #29
agentrickardI went with the easier patch. There is some strange logic that needs re-thinking here, but the fact is that we still need the array loop and, if I recall correctly, the check for mlid == 0. These are provided in the case that we have multiple top-level menu items (e.g. two access control menus) and in case the top-level menu item is not, for some reason, configured for access control.
Comment #30
jbylsma commentedThat's cool. My test case was a couple of variations on a skeleton D7 install, so while it seemed right, I figured it'd be smarter to make two patches. Functionality seems to be working as expected with the current patch, but I won't muck with the status.
btw, thanks for your work and attentiveness on this module!
Comment #31
agentrickardWell, we keep committing and then fixing this issue, so one more won't hurt.
Comment #32
agentrickardComment #33
jbylsma commentedAll second level or lower menu items were matching, which is fixed. Switched $mlid to TRUE if an menu item matches and added a conditional to type check for that. Added a little documentation.
If I have the bandwidth to write menu tests, I will, but I doubt that is going to happen anytime soon.
Comment #34
agentrickardCan you give a clear example of the error this fixes? A screen shot might help. In the original patch re-roll, I removed the TRUE check logic because it seemed unnecessary and inelegant.
Comment #35
jbylsma commentedSure thing. I copied out the administer menu page on a test site and diagrammed the issue with new columns.
During the child item check (!empty($link['below'])), if the child element's mlid is passed, then the built tree will detect the match and return that item, along with any item below it. That's why A1 and A1a are editable in the screenshot.
The $mlid TRUE functionality being set during a match specifies that all child elements should match. I'm OK refactoring it to be something nicer, though I'm not sure what you'd prefer.
Comment #36
agentrickardWe were Doing It Wrong. We should only check 'below' if the parent item is valid.
Comment #37
jbylsma commentedThis patch only works if the section is on the root level; the code will not check descendents for a match if the root level doesn't match. It does work as expected if the user is assigned "All of menu" or first level item.
Using the previous screenshot, only B1 gets "Actual update/delete," and that's because the simple check in workbench_access_in_tree matches.
Comment #38
agentrickardI can't replicate that in my tests. The patch seems to be working fine.
Comment #39
agentrickardAnyone? Reviews?
Comment #40
azarzag commentedThe patch on #36 seems to be working fine for me too
Comment #41
agentrickardWe're working on tests for this now -- see #1878338: Test for Menu access control. I think the blocker is that it fails if you don't have all menu items used as active editing sections.
Comment #42
jbylsma commentedI've extended the menu test to check update abilities throughout the menu hierarchy. I've created a regular site that mirrors what the tests are doing and it appears as if the tests are properly returning (with a fair amount of failures). Also included is the renaming of the menu test nodes, which made it a little easier to diagnose!
Both #1422868-33: Menu hierarchy - permissions descendancy and #1422868-36: Menu hierarchy - permissions descendancy do not allow a user to update the assigned section. I wrote the test expecting a user to be able to update the assigned section's node. What is the expected update behavior for an assigned section's node?
#36 also has errors on the second level access tests, #33 does not.
Patch is not being tested because of the failing tests.
Comment #43
agentrickardOK, I committed the form issue, clearing the way for fixing up these fails.
Comment #44
agentrickardHere's a re-roll that merges 36 with 42, and lets allow the tests to fail here for now.
Comment #46
agentrickardAlright, thanks to @jbylsma, I think I cracked the problem here. menu_tree_all_data() returns a nested array, so if we don't start at the top level, we never get into the proper loop.
This patch fixes up the latest and takes part of the approach from #33. Tests are green. So the question is whether they are _sufficient_.
Comment #48
agentrickardHm. That tests green on my system. Minor re-roll to prevent an empty $account.
Comment #50
agentrickardSigh. These are related to using random array items.
Comment #51
agentrickardOne more time.
Comment #52
jbylsma commentedReviewed in on a vanilla D7 install and (with three level hierarchy) and a production site clone. Both appear to be working without issue :)
Comment #53
agentrickardGoing once? Going twice?
I'm going to commit this tomorrow unless someone objects.
Comment #54
agentrickardAlright. Committed.
Big hat tip to @jbylsma for the test coverage.
Comment #55.0
(not verified) commentedgramma fix