In responce to http://drupal.org/node/1048706 - I've got a request.
It would be nice if there was a permission to view all userpoints transaction but not to edit them.
It is something between USERPOINTS_PERM_ADMIN and USERPOINTS_PERM_VIEW
If you need any help analyzing the minimal code changes required for that, just let me know!

Comments

berdir’s picture

What 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.

__Sander__’s picture

I'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

__Sander__’s picture

Version: 6.x-1.x-dev » 6.x-1.2
StatusFileSize
new2.96 KB

Ok 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.

function userpoints_access_my_points() {
	global $user;  

 if ($user->uid === 1 || user_access(USERPOINTS_PERM_ADMIN)) {
    return TRUE;
  } // root, admin perms

   if (user_access(USERPOINTS_PERM_VIEW_TRANS)) {
    return TRUE;
  } // view all transaction perms

  // User which are displaying points for
  $uid = (int)arg(1);
  if ($uid) {
    if ($uid != $user->uid) {
      // If not the same as logged in user
      return FALSE;
    }
  }

  return (user_access(USERPOINTS_PERM_VIEW) || user_access(USERPOINTS_PERM_VIEW_OWN));
  // viewing transactions of myself


}
__Sander__’s picture

The 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...

berdir’s picture

__Sander__’s picture

Ok, I think I'll switch to dev then and provide a patch based on it...

__Sander__’s picture

StatusFileSize
new1.31 KB

A 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

berdir’s picture

Version: 6.x-1.2 » 6.x-1.x-dev
Status: Active » Needs review

When 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...

berdir’s picture

Note: 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.

__Sander__’s picture

Thanks 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?

berdir’s picture

Status: Needs review » Needs work

I 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.

__Sander__’s picture

Status: Needs work » Needs review
StatusFileSize
new1.14 KB

Ok 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!

Status: Needs review » Needs work

The last submitted patch, 1048966-git.patch, failed testing.

__Sander__’s picture

Status: Needs work » Needs review
StatusFileSize
new1.39 KB

Attempt 2

manuel.adan’s picture

Component: Code: userpoints_basic » Code: userpoints
Issue summary: View changes
Status: Needs review » Closed (outdated)

Closing this as outdated, 6.x version is no longer maintained.