Drupal 10, the latest version of the open-source digital experience platform with even more features, is here.I've been struggling with trying to manage proper access control for our Views with permissions and PHP in our blocks. I think what we really need is a Views access plugin. Basically, we need to sub-class views_plugin_access.










Comments
Comment #1
ergonlogicI've implemented a Views access plugin for hosting_packages, and along the way, I've started moving all Views-related code into a views/ directory. I figure to do the same for the rest of our modules that expose anything to Views. I've also pushed some clean-up of Views exposed forms to Eldir, and removed the PHP we were injecting for block visibility in Hostmaster. This is all in 'dev/views-access' branches.
Currently the access plugin is about as basic as can be:
We might want to add some options here, at some point, but for now, I've hard-coded the access rules in our callback:
I've update the default views that ship with hosting_package to use this access plugin. It appears to work, but could use more testing. Next is hosting_site.
Comment #2
ergonlogichosting_site has had the same treatment. For some reason the 'access()' method never seems to be called for page displays, so I've stuck with permission-based access there.
While there's still the matter of moving the rest of our modules' views stuff into views/ directories, I don't think there's any need for more access plugins at this point.
Comment #3
ergonlogicCross-referencing: #725952: implement node-level access permissions for platforms
Comment #4
ergonlogicCross-reference: #976684: let account managers view all clients
Comment #5
ergonlogicIn removing the PHP we were injecting into our blocks, but since access control isn't enforced for UID1, you sometimes get views where they shouldn't be. I'll put it back, I guess. We can control this directly in Views-7.x-3.x.
Comment #6
anarcat CreditAttribution: anarcat commentedcan't we pass the node id down in the access callback instead of doing this hackish technique?
Do not use numeric identifiers but use constants instead.
I am kind of confused as to why this plugin is necessary - shouldn't views respect existing node_access rules? I understand if we needed to hack our way around platform's access control limitations (i.e. #725952: implement node-level access permissions for platforms) but for sites, shouldn't views just respect existing permissions?
Comment #7
ergonlogicNo, we can't pass arguments to block Views in D6. We'll be able to clean this up in Aegir 3, so this deserves a @todo.
This is to control access to the View at all, not individual results.
Comment #8
anarcat CreditAttribution: anarcat commentedOh I see, so I don't think I see any blockers here then.
Comment #9
ergonlogicMerged into 6.x-2.x on hosting, hostmaster and eldir.