Closed (fixed)
Project:
Web Links
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
27 Feb 2015 at 07:34 UTC
Updated:
10 Apr 2015 at 18:34 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
jonathan1055 commentedThe core Node module creates the following permissions (key and description)
Here is a summary of all the permissions we provide in weblinks_weblinks_permissions()
'access web links'
- used in weblinks_menu() to give to access /weblinks page, all /weblinks/x pages, weblinks/goto/x and weblinks/user/x.
- used in weblinks_blocks_block_view() to return nothing if not allowed.
- Key should be renamed to 'access weblinks' so that it is consistent with all the other permissions.
'create weblinks'
- Can be removed as this is provided by 'create weblinks content' in core.
- Some usages may need to be altered to the core text value.
'edit own weblinks'
- Can be removed as this is provided by 'edit own weblinks content' in core.
- Some usages may need to be altered to the core text value.
'view my weblinks'
- used in weblinks_menu() to grant access to tab at user/x/weblinks
- used in weblinks_blocks_block_view() to return empty 'user' block if no access.
'edit group weblinks'
- in weblinks_weblinks_preprocess() sets $edit_group but this variable is not used. Can remove this variable.
- in weblinks_group_access() used to determine menu access for group adding/editing
- This could be improved: can now check _weblinks_get_vocid() which has become more strict than just module_exists('taxonomy')
- Why does the user need two of our permissions 'administer weblinks' and'edit group weblinks'? This makes the 'edit group weblinks' redundant if you also need 'administer weblinks'. I propose we drop 'administer weblinks' from weblinks_group_access()
'administer weblinks'
- weblinks.module, in weblinks_node_access() gives update & delete authority on any weblinks node,
- in weblinks_node_view() adds edit and delete links
- Provides four admin urls in weblinks_menu(), used in weblinks_group_access() and in weblinks_get_tree()
- weblinks.user.inc, in _weblinks_user_access_check() when adding 'edit' and 'delete' operations to the table of user links
- weblinks_checker.module, in weblinks_checker_menu() to control access to Checker admin url
'view click count'
- only used in weblinks_weblinks_preprocess() when adding the click data
I will start on a patch to do the above.
Comment #2
GStegemann commentedOK so far, apart from:
That's an 'or' condition. Which means: when an user has 'administer weblinks' permission the user has implictely the 'edit group weblinks' permission. And also when the user has 'administer taxonomy' permission.
Comment #3
jonathan1055 commentedThanks, yes when I came to make the code change i realised I had mis-read that code line. It is eactly right and can stay as-is.
Comment #4
jonathan1055 commentedTo avoid the automated tests crashing with exceptions when testing the permissions, we need to protect three bits of code in weblinks.test, by using
if (isset($fieldset[0]))Here's a patch which does that, which I would like to commit first, then the testing can run properly.
Comment #5
GStegemann commentedOK.
Comment #7
jonathan1055 commentedHere's a patch which addresses all of the above. In addition, it also has the following:
This patch will fail the automated testing because I have not changed the test files to use the new core permission names. This is on purpose, just to show that our tests do check the permissions. I have also tested each of the permissions manually as our test coverage is not 100%.
Comment #9
jonathan1055 commentedAs expected we had failed tests. Here's the full patch with the test files updated too.
Comment #10
GStegemann commentedI will test the patch now. One first remark:
Spelling 'clciked' needs to be corrected.
Comment #11
jonathan1055 commentedThanks. I forget to run a spell checker. I have also just noticed that in my
git diffI included weblinks.admin.inc when it should have been weblinks.user.inc. There are no changes in admin.inc, but the patch does need the changes to user.incI will do that right now - so hold off testing for two mins
Comment #12
GStegemann commentedThe update function failed on my test site:
Comment #13
jonathan1055 commentedAh, yes I was a bit concerned about this. It's becuse you have already granted the core permission 'create weblinks content' to a role which I am trying to update from 'create weblinks'. I think the function is therefore going to have to do more than just simple updates, it first has to delete the weblinks versions if a core version exists. I'll work on that.
In the meantime, here is an individual patch just for the user.inc changes which got missed, if you want to test them. You can apply this patch on top of the one you've just done.
Comment #14
GStegemann commentedYes, I have already granted core permissions to the roles.
Thanks. But I will wait for your next complete patch.
Comment #15
GStegemann commentedA second question:
Is that OK to allow access to the Links page only to Web Links administrators? That seems too restrictive.
Comment #16
jonathan1055 commentedLook at the comment just above:
This is not the main weblinks url, it is the extra one we provide on the 'config' page, for admins to get back to the main page. As that config page is only available to admins we should restrict this tab too.
Comment #17
GStegemann commentedSorry, I missed the comment. Yes, then the change is correct.
Comment #18
jonathan1055 commentedHere's the full patch with improved update function. For each of the two old permissions we are deleting, first get the roles (if any) which already have the new core permission. Then any rows for these roles with old permission are deleted, before we update any which are left. I've explained this is the code too.
Comment #19
GStegemann commentedMany thanks.
One more question:
This variable seems not to be used later. What is the intended purpose? To count the number of deleted and re-added permissions?
Comment #20
GStegemann commentedPatch tested and works basically, apart from:
The 'edit' and/or 'delete' links are not provided for other authorized users, applicable permissions assigned. The links are only provided for Web Links Admins.
Comment #21
jonathan1055 commentedThanks for testing - good to hear that it is basically working. I agree that it seems fine with all my testing, but I always appreciate your thoroughness in checking.
In reply to #19, you'll notice that the variable has a double $. This is a method to create a new variable name from an existing variable's value. In the code below, we loop through an array of two items, because the processing required is virtually identical, hence better for maintainability if done in a loop rather than duplicate blocks of near-identical code. The only differences required are the permission names and a variable to count the total changes.
The line
$$key = 0;can be worked out like this: When you see a double $ resolve the second one with the variable, i.e. $key has the value 'create' so $$key is the variable $create. Hence that line is the same as$create = 0;But the benefit is that on the second loop, that line becomes$edit_own = 0;These variables hold the sum of the two db operations, and are written out in the final messageIn reply to #20
Do you mean they are not provided in the current patch but should be? or they should only be provided for admins but currently are given to more users?
The existing code (pre-patch) gives both of these links if the user is looking at their own links and has 'edit own weblinks' permission or they have 'administer weblinks' regardless of who's links they are viewing. All I changed here was to separate out the 'edit' and 'delete' permission checks.
Comment #22
GStegemann commentedYou're welcome.
Regarding $$key: thanks for you great explanations. Until now I didn't know this PHP feature. So I have learned something new.
Yes. Currently the links only appear when an user has the Web Links Admin permission. Maybe the code didn't work before.
Comment #23
jonathan1055 commentedIt's always nice when one learns something new :-)
This is not the behaviour which I get. I've create a role which has 'edit own weblinks content' and does not have 'administer weblinks' and I get the edit link. If I add 'delete own weblinks content' I then also get the delete link. This is working as expected for me, so somehow your site is behaving differently.
Here is some debug for you to add at the top of your _weblinks_user_access_check so we can see in more detail what is happening.
Comment #24
GStegemann commentedJust to clarify: the edit and delete links are shown on the 'My Web Links' page, as expected.
But not on the main Web Links page. See attached screen shot, right bottom corner. But I have found the reason now. In weblinks_node_view the edit/delete links will only be added when the current user has 'administer weblinks' permission:
Wouldn't it be better to make this also dependent on the user specific permissions?
Comment #25
jonathan1055 commentedAh, and there I was thinking you were talking about some code I had changed in the patch ;-)
Yes, those edit and delete links are only shown when the user has 'administer weblinks' permission. If we were to do this properly, it would mean not having a static variable $admin but checking the $node being displayed each time, as a user may have 'edit own weblinks content' but not have 'edit any weblinks content'. So in this case we should only show the links on their own nodes, not for others.
That may be a useful addition, as providing these links does save one click during edit/delete which could be helpful for weblinks editors. I can add this to the next patch.
Comment #26
GStegemann commentedI realized later that these links will be created weblinks_node_view and not in weblinks_user_form.
Sure.
Yes, please. Thanks.
Comment #27
jonathan1055 commentedHere's the new patch, plus an interdiff showing the chnages between #18 and #27.
I realised that if we were improving the edit and delete links on the main page we should do the same on the user page. To test this fully you need to give a user the permission to view other users account pages. Then you can see whether they get the edit and/or delete links if they have 'edit any weblinks content' etc.
Comment #28
GStegemann commentedTested your patch now.
Works basically. However, but when logged in as an user w/o 'administer weblinks' permission but with 'access web links' permission access to any of the Web Links pages is forbidden. That is wrong in my opion.
Comment #29
gnxtsolutions commentedOk Thanks, May be this helpful
Comment #30
jonathan1055 commentedThanks for testing, but your error surprises me. I've tried to replicate but cannot - are you sure you did not have the old permissions remaining from before the patch. Can you clear the cache and 'rebuild menus' from the devel menu link, then try again.
Comment #31
jonathan1055 commentedMaybe we should add calls to
drupal_flush_all_caches()andmenu_rebuild()at the end of update_7004 ?Comment #32
GStegemann commented'rebuild menus' did the trick. Now the patch works as expected.
Regarding update #7004: yes, we should do so.
Comment #33
jonathan1055 commentedHere's a patch with menu_rebuild() added, my commented lines removed and a typo fixed in blocks.test
Comment #34
GStegemann commentedThanks. Tested and works.
Comment #36
jonathan1055 commentedExcellent, thank you.
I made two minor changes - (a) moved 'View click count' up in the display list of permissions to be after 'Access weblinks' as this feels a better place for it, and (b) expanded the description for 'Administer' rather than just repeat the permission title.
Comment #37
GStegemann commentedYour last minute changes are OK.
Comment #38
jonathan1055 commentedThanks. I'd never commit something which you had not seen which was anything other than minor and I am pretty certain you are OK with. If I ever do, don't hesitate to call me on it ;-)
Comment #39
GStegemann commentedBelieve me. I would do that ;-)