alejandro Posted October 31, 2018 Share Posted October 31, 2018 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 More sharing options...
alejandro Posted October 31, 2018 Author Share Posted October 31, 2018 I think I found the solution. Edited the admin template to allow editor role to view it. Link to comment Share on other sites More sharing options...
adrian Posted October 31, 2018 Share Posted October 31, 2018 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. 4 Link to comment Share on other sites More sharing options...
alejandro Posted October 31, 2018 Author Share Posted October 31, 2018 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 More sharing options...
Robin S Posted October 31, 2018 Share Posted October 31, 2018 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: 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. 3 Link to comment Share on other sites More sharing options...
adrian Posted October 31, 2018 Share Posted October 31, 2018 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); }); 3 Link to comment Share on other sites More sharing options...
Robin S Posted October 31, 2018 Share Posted October 31, 2018 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'); } }); 3 1 Link to comment Share on other sites More sharing options...
adrian Posted October 31, 2018 Share Posted October 31, 2018 1 minute ago, Robin S said: PageListSelect is different because it doesn't get pages via Pages::find, but rather gets the children of individual pages if they are listable. Good point ? Link to comment Share on other sites More sharing options...
Steven Brown Posted January 11, 2019 Share Posted January 11, 2019 Great point thanks for the guidance its really knowledgeable discussion. 1 Link to comment Share on other sites More sharing options...
cstevensjr Posted January 15, 2019 Share Posted January 15, 2019 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. 3 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