Closed (outdated)
Project:
User Points
Version:
6.x-1.x-dev
Component:
Code: userpoints
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
2 Feb 2011 at 18:26 UTC
Updated:
24 Feb 2018 at 10:15 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
berdirWhat if we do it the other way round, I help you to write a patch for this? :)
See http://drupal.org/patch/create
What this needs:
- Declare variable in hook_permission(). Maybe call it 'view all userpoint transactions' or something like that. Make sure to do it with a constant to be consistent with the others.
- Update the access callback to include that. Maybe other places too, not sure.
Comment #2
__Sander__ commentedI'll give it a try!
Up to the moment, I am good enough in php, and have been reading the Drupal code a lot, but have not yet tried making patches
Comment #3
__Sander__ commentedOk there.
I am modifying the following things:
- definition in the beginning define('USERPOINTS_PERM_VIEW_TRANS', 'view all userpoints transactions');
- hook_perm - adding USERPOINTS_PERM_VIEW_TRANS
Now about important things. The system with view list permission is a bit buggy.
The module currently uses the userpoints_access_my_points function via the menu access system to determine, whether to give access to /myuserpoints/*. Hence all permission checks should be made in that function.
However, that function cannot currently perform the needed checks since it does not know, which user we are requesting userpoints for - ourself or other user.
Therefore I am adding
'access arguments'=>array(1) in the hook_menu definition of myuserpoints
Then I am completely rewriting userpoints_access_my_points
putting all the logic there.
And I am removing all permission checks from userpoints_list_my_userpoints()
Now you won't result in getting the link "view details" but resulting in 403 when you follow this link
Hope this helps!
I am patching against 1.2
The code of userpoints_access_my_points follows here.
Comment #4
__Sander__ commentedThe comments in that issue (http://drupal.org/node/1048706) reminded me...
What's currently incorrect is that the permission to view details differs from the situation when "view details" is printed in user profile.
If everybody has the permission to view, but not the permission to admin, then that link is always there, but most users result it 403 when following it...
Comment #5
berdirSee #877446: perm:view userpoints, view link is displayed on other user's profiles, that should be fixedi n 6.x-1.x-dev.
Comment #6
__Sander__ commentedOk, I think I'll switch to dev then and provide a patch based on it...
Comment #7
__Sander__ commentedA new patch for the latest dev.
The changes are minimal now!
Looks like I've repeated a part of the dev changes in my previous patch to the release version
Comment #8
berdirWhen you post a patch, set the Status to needs review. I didn't even notice that there was a patch before. The test bot will then automatically test your patch (mainly that the patch applies correctly, there aren't many tests yet unfortunately*).
Patch looks good, the only change that I would suggest is checking both the ADMIN and the VIEW_TRANS permission, so that your change is backwards compatible with existing sites (aka, they don't need to change permissions unless they want to).
* It would be awesome if you could write some tests for the myuserpoints page (access denied/allowed checks for all possible permission configurations: own page, other page, admin permission, view trans permission, neither). This would make it easier for me to commit this feature (because it is guaranted to work and won't be broken by another change) and make it more stable in general.. there were tons of bugs around that in older versions...
Comment #9
berdirNote: The testbot will fail to apply this patch, because the path to the changed file is inconsistent (once with userpoints directory and once without). You can either change that manually or use git to create the patch (recommended but with an initial learning effort if you don't know it already. But knowing git can be a huge timesaver in general).
Again, if you have any questions regarding tests or git, you can always join IRC (http://drupal.org/irc) and join #drupal-games (or #drupal-gitsupport for general git questions)
Edit: I was obviously wrong, the patch applied, forgot that only the second file name is relevant.
Comment #10
__Sander__ commentedThanks for guiding me :) I am slowly learning GIT, in fact I've already applied for moving my own module out of the sandbox, but for the moment I still do not know GIT well enough.
Is there any manual about writing tests for modules?
Comment #11
berdirI wrote a blog post about it a while ago, see http://blog.worldempire.ch/story/writing-automated-tests-drupal-7. That is for Drupal 7, but writing tests works almost the same for 6.x and 7.x
Basically, you want to start with something like this:
- Create 3 users (one with ADMIN permission, one with VIEW_TRANS permission, one with just VIEW)
- Give the normal user some points
- Try to view the myuserpoints page of the third user with all three users, should all work
- Try to view another myuserpoints page with the third user, should not work
- Visit the profile page, which should only contain a link to that page if allowed to view it (again, for all combinations above, combine it with the check above)
Setting to needs work because of the permission check change suggested in #8.
Comment #12
__Sander__ commentedOk there, I changed the permission check (that was trivial of course) and learned how to make a patch with the use of git.
The patch I am uploading now has been made with the use of git.
P.S. Since the code is being modified, the changes of my patch are becoming more and more simple, but that's actually a good place to learn all those thing about patches, git and workflow!
Comment #14
__Sander__ commentedAttempt 2
Comment #15
manuel.adanClosing this as outdated, 6.x version is no longer maintained.