Jump to content
spoetnik

Hook into pages listings.

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?

Share this post


Link to post
Share on other sites

When you say page listings you mean Listers? 

Share this post


Link to post
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?

 

Share this post


Link to post
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

Share this post


Link to post
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 😞  

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...