spoetnik Posted July 2, 2019 Share 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? Link to comment Share on other sites More sharing options...
elabx Posted July 2, 2019 Share Posted July 2, 2019 When you say page listings you mean Listers? Link to comment Share on other sites More sharing options...
spoetnik Posted July 2, 2019 Author Share 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? Link to comment Share on other sites More sharing options...
Zeka Posted July 2, 2019 Share 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 Link to comment Share on other sites More sharing options...
szabesz Posted July 3, 2019 Share 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 ? Link to comment Share on other sites More sharing options...
LostKobrakai Posted July 3, 2019 Share 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 Link to comment Share on other sites More sharing options...
spoetnik Posted July 3, 2019 Author Share 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. Link to comment Share on other sites More sharing options...
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