renobird Posted April 17, 2014 Share Posted April 17, 2014 I need to prevent access to the page tree for a particular role (intern). The goal is the jail them to a set of custom admin pages. I have a clumsy solution that I've been using for a while that involves checking for the intern role as part of the rendering the navigation in my admin theme. It works, but now with admin themes being modules, I need something that isn't tied to a theme. ProcessPageList needs page-edit permission. I can't take that away because they need to be able to edit some pages. Any suggestions would be appreciated. Link to comment Share on other sites More sharing options...
Wanze Posted April 17, 2014 Share Posted April 17, 2014 Hi reno, I think it is doable with two hooks. One hook would return false for Page::viewable() for the ProcessPageList page. Another Hook can be used to redirect your users to a custom admin page after login. I've only used the second one in a project, but I think something like this should work: // This needs to be an autoload module public function init() { $this->addHookBefore('ProcessHome::execute', $this, 'rootPage'); $this->addHookAfter('Page::viewable', $this, 'viewable'); } /** * Redirect users with custom-role to another page after login */ public function rootPage(HookEvent $event) { if ($this->user->hasRole('custom-role')) { $this->session->redirect('custom-admin-page/'); } } /** * Don't give users with custom-role access to Pages page */ public function viewable(HookEvent $event) { $page = $event->object; $user = $this->user; if ($page->id == 3 && $user->hasRole('custom-role') { $event->return = false; } } 13 Link to comment Share on other sites More sharing options...
renobird Posted April 18, 2014 Author Share Posted April 18, 2014 Wanze, Thanks — very much appreciated. I just couldn't seem to get my head around this on my own. Testing now. Will report back shortly. Cheers! Link to comment Share on other sites More sharing options...
renobird Posted April 18, 2014 Author Share Posted April 18, 2014 Wanze, Works perfectly! Thanks again. 1 Link to comment Share on other sites More sharing options...
Pete Posted April 20, 2014 Share Posted April 20, 2014 This is great as it's Something I've wanted to do on a couple of projects the last few weeks, thanks! 1 Link to comment Share on other sites More sharing options...
Raymond Geerts Posted April 20, 2014 Share Posted April 20, 2014 This is something i was thinking about a couple of days ago. I was wondering if it would be possible to serve somekind of dashboard page instead of the page tree. Looks like this is the base for that to build it upon. 1 Link to comment Share on other sites More sharing options...
kongondo Posted April 20, 2014 Share Posted April 20, 2014 Wanze. Thanks for sharing this (and to Reno for asking the question!)! Everyday I continue to be awestruck by the simplicity, cleverness and power of ProcessWire. With about 11 easy-to-follow lines of code, without touching the core, without bashing the system into submission by throwing all sorts of plugins at it and without compromising security and future updates, this opens up a whole new world of possibilities all at the drop of a hat.....Fantastic! 4 Link to comment Share on other sites More sharing options...
Pete Posted April 20, 2014 Share Posted April 20, 2014 Raymond - did you see my ProcessDashboard module? 1 Link to comment Share on other sites More sharing options...
Raymond Geerts Posted April 20, 2014 Share Posted April 20, 2014 Raymond - did you see my ProcessDashboard module? http://modules.processwire.com/modules/process-dashboard/ Thanks, that is awsome and probably what i need for a project im currently working on. I need to serve a small list of pages and the ability to add new pages to a fixed parent without showing the page tree. Link to comment Share on other sites More sharing options...
einsteinsboi Posted November 13, 2014 Share Posted November 13, 2014 This looks like just what I need but what I'm puzzled about is where do I put this code? Do I create a new module with this code or? Hi reno, I think it is doable with two hooks. One hook would return false for Page::viewable() for the ProcessPageList page. Another Hook can be used to redirect your users to a custom admin page after login. I've only used the second one in a project, but I think something like this should work: // This needs to be an autoload module public function init() { $this->addHookBefore('ProcessHome::execute', $this, 'rootPage'); $this->addHookAfter('Page::viewable', $this, 'viewable'); } /** * Redirect users with custom-role to another page after login */ public function rootPage(HookEvent $event) { if ($this->user->hasRole('custom-role')) { $this->session->redirect('custom-admin-page/'); } } /** * Don't give users with custom-role access to Pages page */ public function viewable(HookEvent $event) { $page = $event->object; $user = $this->user; if ($page->id == 3 && $user->hasRole('custom-role') { $event->return = false; } } Link to comment Share on other sites More sharing options...
kongondo Posted November 13, 2014 Share Posted November 13, 2014 @Mary, Yes, you need to create an autoload module...You would need the other bits required in a module, e.g. the install and uninstall methods...Shout if you need any help.. 1 Link to comment Share on other sites More sharing options...
einsteinsboi Posted November 13, 2014 Share Posted November 13, 2014 @Mary, Yes, you need to create an autoload module...You would need the other bits required in a module, e.g. the install and uninstall methods...Shout if you need any help.. I've never created or tried to create a PW module... Time to leap into the docs again... I'm sure I'll be shouting soon... thanks for your help kongondo Link to comment Share on other sites More sharing options...
kongondo Posted November 13, 2014 Share Posted November 13, 2014 Here's a simple autoload module example that is part of the Blog module suite. And here's some resources. Have fun! 1 Link to comment Share on other sites More sharing options...
einsteinsboi Posted November 13, 2014 Share Posted November 13, 2014 Here's a simple autoload module example that is part of the Blog module suite. And here's some resources. Have fun! Thank you, will dig into this in the morning when the brain is fresh. Almost 1am here now Link to comment Share on other sites More sharing options...
netcarver Posted November 13, 2014 Share Posted November 13, 2014 It's about time this was pulled together as a configurable module. So here it is on github and in the module DB. You can configure a set of roles and a target redirect page under the module config. I've done very limited testing here - hence it being marked as alpha in the module DB - so please let me know if it works for you. A word of thanks to both Wanze and kongondo are in order as they pulled most of the material together that I used for this! 11 Link to comment Share on other sites More sharing options...
Alexander Posted January 26, 2015 Share Posted January 26, 2015 @kongondo @netcarver @einsteinsboi Is it possible, that something was changed for this module in last PW dev? I use PW 2.5.15 and have strange issue. When I try to edit page I get page witch pointed in "redirect restrict user to" on top of normal edit page. Like: <code of "redirect restrict user to page"> <code of normal page edit page> Link to comment Share on other sites More sharing options...
adrian Posted January 28, 2015 Share Posted January 28, 2015 Steve - thanks for the module - it has proven very useful, however I wonder if you'd consider having multiple rules so it would be possible to redirect some roles to one page and other roles to a different page, etc? I might end up making the changes myself and submitting a PR if you don't have the time to tackle it, but hoping you might 3 Link to comment Share on other sites More sharing options...
creativejay Posted February 16, 2015 Share Posted February 16, 2015 I had some trouble getting this to work, but it magically started to work after a nth reinstall. Thanks for this, it's doing exactly what I need! Link to comment Share on other sites More sharing options...
valan Posted July 14, 2015 Share Posted July 14, 2015 I've installed http://modules.processwire.com/modules/process-dashboard/ and redirected some custom role to this page after login. ... after that browser freezes in endless "waiting" mode when user (with that custom role) attempts to login. Any ideas why this happens? P.S. PW 2.6.4 Edit: two bugs discovered (1) infinite redirects caused by process-dashboard. Had no time yet to understand why... (2) hidePageTree redirects only to /admin/smth while smth could be in /admin/somefolder/smth Link to comment Share on other sites More sharing options...
KarlvonKarton Posted September 13, 2016 Share Posted September 13, 2016 This module redirects to the custom page when page/ , But it does not redirect when page/list/ In the latter situation the pagetree is still visible. What can I do to prevent that? Is this a good practice to prevent it? public function viewable($event) { $page = $event->object; $user = $this->user; if ( ($page->id == 3 || $page->id == 8) && $user->hasRole('custom-role')) { $event->return = false; } } ps: thus with the extra added $page->id = 8 Link to comment Share on other sites More sharing options...
pmarki Posted September 14, 2016 Share Posted September 14, 2016 16 hours ago, KarlvonKarton said: This module redirects to the custom page when page/ , But it does not redirect when page/list/ In the latter situation the pagetree is still visible. What can I do to prevent that? Is this a good practice to prevent it? public function viewable($event) { $page = $event->object; $user = $this->user; if ( ($page->id == 3 || $page->id == 8) && $user->hasRole('custom-role')) { $event->return = false; } } ps: thus with the extra added $page->id = 8 you can check its path: if ($page->path == '/admin-page-name/page/list/') $event->return = false ; Link to comment Share on other sites More sharing options...
NorbertH Posted September 18, 2018 Share Posted September 18, 2018 Processwire 3.0.98 Calling /processwire/page/ Puts me in an endless loop. It redirects to processwire/page/?login=1 Over and over again. Link to comment Share on other sites More sharing options...
dotnetic Posted October 23, 2018 Share Posted October 23, 2018 (edited) It seems all solutions, including my own one from here don't work with AdminThemeUikit. So I proposed a change to the getPrimaryNavArray function which you can read on github and enables us to hide the "pages" menu item from the top navigation. Vote for it, if you like. EDIT: Actually, there is a working module from @netcarver - http://modules.processwire.com/modules/admin-restrict-page-tree/ My own function had an error and now I replaced it with the mentioned module. @bernhard Maybe this interesting for you also?! Edited October 23, 2018 by jmartsch Found a working solution 1 Link to comment Share on other sites More sharing options...
adrian Posted October 23, 2018 Share Posted October 23, 2018 @jmartsch - what about this module from @netcarver - http://modules.processwire.com/modules/admin-restrict-page-tree/ 1 Link to comment Share on other sites More sharing options...
dotnetic Posted October 23, 2018 Share Posted October 23, 2018 @adrian Yes, this module works flawless, and I had an error in my own hook, so there IS a way to hide the "page" navigation item already. Don't know, why it worked before, and now it did not. Also I don't know why I did not tried this module, because I was aware of it. However, I still think my pull-request is a valid option, for changing the navigation. 2 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