Jump to content

Access to list users


alejandro
 Share

Recommended Posts

Hello,

I've created an "editor" role and there is a template (blog post page) with a page reference field where it should be able to choose an user (post author) but it seems it doesn't have access:

   "You don't have access to list page /alambre/access/users/"

What permission should I add to the editor role? Already added view/edit in user template.

Thanks in advance.

Link to comment
Share on other sites

1 hour ago, adrian said:

Not sure if that's the best approach ?

With page reference fields I think you want to go with a custom selector and add "check_access=0" to the selector.

Your way seems better to me ? thanks.

Curiously using "page list" as input field type shows all pages tree, using a "select" shows only users.

Link to comment
Share on other sites

4 hours ago, alejandro said:

Curiously using "page list" as input field type shows all pages tree, using a "select" shows only users.

See this note:

2018-11-01_100551.png.83ad813fadc90b81653a9bd1f43e5161.png

Because of this requirement this input type won't be suitable for non-superusers to select users because you don't have the possibility to specify check_access=0. 

  • Like 3
Link to comment
Share on other sites

There is a hacky way around this. This comes direct from the ready.php file from one of my sites - in this case it's for the autocomplete inputfield, but maybe something like this would be useful for you also?

// hack to overcome this: https://github.com/processwire/processwire-issues/issues/550
$this->addHookBefore('Pages::find', function(HookEvent $event) {
    $selector = $event->arguments(0);
    if(is_string($selector) && strpos($selector, 'template=user') !== false && strpos($selector, 'name|first_name|last_name%=') !== false) {
        $selector .= ', check_access=0';
    }
    $event->arguments(0, $selector);
});

 

  • Like 3
Link to comment
Share on other sites

1 hour ago, adrian said:

This comes direct from the ready.php file from one of my sites - in this case it's for the autocomplete inputfield, but maybe something like this would be useful for you also?

PageListSelect is different because it doesn't get pages via Pages::find, but rather gets the children of individual pages if they are listable.

This is what I came up with:

$wire->addHookAfter('Page::listable', function(HookEvent $event) {
    $page = $event->object;
    // Page is listable if it is the Users parent or a user page and the current user has a given role
    if(($page->id === 29 || $page->template == 'user') && $this->wire()->user->hasRole('editor')) {
        $event->return = true;
    }
});

$wire->addHookBefore('ProcessPageList::find', function(HookEvent $event) {
    $selector = $event->arguments(0);
    $page = $event->arguments(1);
    // Don't check access if getting children of the Users parent and the current user has a given role
    if($page->id === 29 && $this->wire()->user->hasRole('editor')) {
        $event->arguments(0, $selector . ', check_access=0');
    }
});

 

  • Like 3
  • Thanks 1
Link to comment
Share on other sites

  • 2 months later...
On 1/11/2019 at 5:59 AM, Steven Brown said:

Great point thanks for the guidance its really knowledgeable discussion. 

@Robin S and @adrian, a great discussion and follow-up solution(s).  This is the type of stuff that makes this Forum so valuable and worth reading on a daily basis.

  • Like 3
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...