Jump to content

Hook into pages listings.


spoetnik
 Share

Recommended Posts

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

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

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;
	}
});

 

  • Like 1
Link to comment
Share on other sites

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

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.

  • Like 2
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...