spoetnik Posted July 2, 2019 Posted July 2, 2019 I am building a module, to restrict access based on a saas_id. I would like to add a selector to all page listings like: saas_id=user()->saas_id what would be a good hook to use?
spoetnik Posted July 2, 2019 Author Posted July 2, 2019 See my module:https://github.com/spoetnik/SaaS On all selected templates, a 'saas_id'-field is added, and populated. I would like to add a selector to all selectors in to filter by saas_id. I could add the selector in all my templates, but that's error-prone, so I prefer to have a hook to add it. Maybe this post could be a starting point?
Zeka Posted July 2, 2019 Posted July 2, 2019 Maybe you can hook to Page::viewable, so all methods like $pages->find which filters access conteroll will also filter such pages $this->addHook('Page::viewable', function($event) { if($this->wire('pages')->saas_id !== $this->wire('user')->saas_Id) { $event->return = false; } }); 1
szabesz Posted July 3, 2019 Posted July 3, 2019 11 hours ago, Zeka said: Maybe you can hook to Page::viewable, so all methods like $pages->find which filters access conteroll will also filter such pages $this->addHook('Page::viewable', function($event) { if($this->wire('pages')->saas_id !== $this->wire('user')->saas_Id) { $event->return = false; } }); Simply hooking into Page:viewable might not be enough, see: Meaning $pages->find() works independent of Page::viewable ?
LostKobrakai Posted July 3, 2019 Posted July 3, 2019 If this is about tenancy management I'd strongly suggest using ryan's dynamic roles module (with all the known fixes) as a base. I once started to make it more flexible, so that you don't need a group per tenant, but rather it would match keys (e.g. tenant name or id). I just never came far because of other priorities. It shouldn't be super hard to do. 2
spoetnik Posted July 3, 2019 Author Posted July 3, 2019 Thanks @LostKobrakai. Looked into the 'Dynamic Roles' Its looks like an abandoned module from Ryan, but the up-to-date fork from @matjazp works. I saw your comment, , and that's exactly the same problem I have with this module. I would love to use this module as a base, or write a pull-request to have this functionality, but I am not skilled enough to do that. The hook into 'PageFinder::getQuery' scares me to add the selector ```saas_id=user()->saas_id``` to my Saas module.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now