Default views created by this module, signup_available_signups and signup_current_signups, enables any user (including anonymous user) to view signups of other users (even if the user does not have permission to view all signups). Just replace x with any user id in the following URLs, and you will be able to view their signups.
http://example.com/user/x/signups/
http://example.com/user/x/signups/current
http://example.com/user/x/signups/available
You could restrict the user by adding this code snippet to the argument validation of both signup_available_signups and signup_current_signups views.
<?php
global $user;
$self = ($argument == $user->uid) ? TRUE : FALSE;
$permitted = user_access('view all signups');
if ($permitted || $user->uid == 1) {
return TRUE;
}
else if ($self) {
return TRUE;
}
else {
return FALSE;
}
?>
So what the code snippet above does is, it restrict users to view only their current/available signups. It will only allow an admin or users with "view all signups" permission to view other user's signups and/or all signups.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 367297-5.signup_views_access_plugin.patch | 11.56 KB | dww |
| #3 | 367297-3.signup_views_access_plugin.patch | 4.47 KB | dww |
Comments
Comment #1
zd370 commentedsince user 1 will have all permissions by default no need to check for user 1...
remove
<?php ?>from the snippetComment #2
dwwArgument validation is the wrong time to test for this, since at that point, returning FALSE results in a 404 (page not found), not a 403 (access denied). The best way to solve this problem is to define our own access plugin (something like "View per-user signup lists" in the UI), add an option to define which argument to use for the access check, etc. Then in the appropriate access methods, check this option, call the helper to grab the current (validated) value of that argument, and do our logic to decide if the given $account should have access to see the per-user issue queue for the given argument. I should hopefully be able to work on this sometime on Friday @ DCDC, if all goes well. See also #380734: project/issues/user a 404 when not logged in, which needs to be solved in almost exactly the same way.
Comment #3
dwwUgh, this was a more complicated than I hoped, but I've basically got this working now. This patch adds a new views access plugin that has knowledge of the view arguments and enforces the logic that a user either needs the 'view all signups' permission, or to be trying to view a list of their own signups, to be granted access. I'm marking this "needs work" since this patch doesn't yet fix the default signup views to take advantage of the new plugin. Before I do that, I want to see if merlinofchaos is willing to try to generalize this as a feature for views itself.
Comment #4
zd370 commentedthanks dww for going to this extent for patching the issue...
Comment #5
dwwThis fixes a few minor problems with the access plugin code, and updates the default views to use it. I also fixed the default views in a few related ways while I was at it:
- the argument now uses the user argument validator
- the argument handler now sets the page title based on the UID in the URL
- for the block display, the argument is overridden to use the UID from the currently logged in user as the default argument
Pretty sure this is now everything we need. Anyone care to test this? You'll need to apply the patch, clear your views cache, revert these views if you've customized them, and rebuild your menu.
Comment #6
zd370 commentedI will give it a try, as I am using your module on my site already.
Comment #7
dwwMinor wording change to the description on the argument selector in the access plugin itself. Otherwise, same code. I committed something similar for project_issue just now (#380734: project/issues/user a 404 when not logged in) so I'd like to get this in ASAP. Any testing results would be much appreciated. Thanks!
Comment #8
gregglesI tested this on two sites. One is of dubious history - a local install - and I got weird results.
The second is slightly more reliable and everything worked perfectly. So, I'd call this RTBC from a functional perspective.
Comment #9
zd370 commentedtested on my site... working...
Comment #10
dwwYeah, I'm just hesitant to commit this patch until views 6.x-2.4 is officially released, since people are going to be confused and things will be broken if they try running signup 6.x-1.0-rc4 and views 6.x-2.3... :( Otherwise, yes, I think this is RTBC.
Comment #11
zd370 commentedI am sure you know Views 2.4 came out a few days ago. I was wondering, if you are going to commit this patch.
Comment #12
dwwYes, I will, thanks for the reminder. More testing (especially for folks upgrading) would be welcome.
Comment #13
dwwCommitted to HEAD and DRUPAL-6--1. I'm hoping to release RC4 in the very near future, which will include this fix.
Comment #15
michellezeedru commentedSorry to comment on a closed issue, but I am using 6.x-1.0-rc4 and do not see this issue resolved. The "Signups" tab still appears to an anonymous user on all user profile pages, with access to a list of signups. I expected this to go away with the fix above. Am I missing a permissions setting somewhere? Are my expectations incorrect? Thanks for the help.
Comment #16
dwwYou'll need to clear your views and menu caches after upgrading to RC4.
Also, make sure the anonymous role doesn't have the 'view all signups' permission.
Comment #17
michellezeedru commentedThanks for your response. I confirmed that I have flushed all caches, and "Administer All Signups" permission is not granted for Anonymous role. Anything else I can check?
Comment #18
crosendahl commentedThe default for the View 'signup_current_signups' allows anyone to access the view, which is likely what you're seeing.
Edit the View and change Access from 'none' to 'View per-user signup lists'.
That solved the problem for me.
Comment #19
michellezeedru commentedThanks for the suggestion #18, but the access for that view was already set to View Sign Up User List. I tried playing with this, though, setting it by role, but didn't seem to make a difference.
Comment #20
michellezeedru commentedHow is "View per-user signup lists" as a views setting supposed to work. Should this option be listed on my permissions page? It's not.
Comment #21
BenK commentedSubscribing....
Comment #22
zdean commentedsubscribing...