This is a subissue of #1391216: Views integration for the 6.x-2.x and 7.x-1.x version.
Problem/Motivation
It should be possible to check for address access before a Views display is rendered. For example, if user A may not see any addresses of user B, he shouldn't have access to user's B address page either.
Steps to reproduce
- Create an address based View.
- Create a contextual filter for User ID.
- Create a page display with a path something like
user/%/addresses2.
If you would finish here, users are able to view eachothers address listings, even if they shouldn't have access. At this point you have two options:
- Set display access restrictions by role or permission. The downside of this is that users may not be able to view their own address listing.
- Add an address access filter, to remove addresses from the Views results that the user may not see. The downside of this is that it doesn't work with pager and that the users still have access to the address listing page (though it would be empty for users with limited access).
This feature is a requirement for #1433034: Redesign the address book page using Views.
Proposed resolution
Implement a views access plugin that can check for address access based on the contextual filters (arguments) of the View. For a page display with a contextual filter for User ID, the access plugin would check if the current logged in user has access to any addresses of the representing user. For a page display with a contextual filter for address ID, the access plugin would check if the current logged in user has access to the single address.
As this access plugin will only work properly for path based displays, implement also a argument validator plugin. The argument validator would do the same: it would check if the current user has access to:
- For User ID contextual filter: addresses of this user.
- For Address ID contextual filter: this address.
The argument validator plugin can not replace the access plugin, because arguments are only validated when someone tries to access the display (e.g. navigates to the page) and not when a link to the page is used in a menu.
Remaining tasks
- Implement a views access plugin.
- Implement a argument validator for checking address access based on an User ID.
- Implement a argument validator for checking address access based on an Address ID.
- Write tests.
User interface changes
New options in address based Views.
API changes
None.
I'm working on it.
Comments
Comment #1
megachrizThis patch implements three Views plugins:
It also has automated tests to test if the plugins work as expected.
See the "Proposed resolution" in the issue summary for more information.
Comment #2
megachrizA re-roll of #1 + minor changes. I have also tested pieces not covered by the automated tests: I've tested if the default user validations in the argument validator 'User: address access' still work and they work.
If this passes tests, then I think it's ready for commitment!
Comment #3
megachrizCommitted #2.
Moving to 6.x-2.x.
Comment #4
megachrizPatch for the 6.x-2.x version. It was quite a challenge to write the argument validator plugins in a way that they work with both Views 6.x-2.x and Views 6.x-3.x, but I think it succeed. Let's look if the testbot agrees. Since the testbot only will test against Views 6.x-2.x, I will perform tests locally against Views 6.x-3.x.
Comment #6
megachrizYeah, the parent for the argument validator "uc_addresses_user_address_access" isn't set right. This should not be the class name, but the name the parent argument validator is registered to Views, which in this case is "user" (see
user_views_plugins()in views/modules/user.views.inc).I had that one right earlier, but I accidentally had removed it when working on other issues.
New patch should go better.
Comment #7
megachrizCommitted #6 with minimal changes. I tested manually if the default user validations in the argument validator 'User: address access' still worked. For Views 2, the restrict by role didn't work, so I fixed that (I forgot to set the option "validate_user_restrict_roles" before letting the validator "views_plugin_argument_validate_user" validate the argument).
I also tested locally if the Views test passed with Views 3 and that was the case.
Setting version back to the one it was originally reported for and mark it as fixed.