adrian

Admin Restrict Branch

Recommended Posts

Hi everyone,

Some critical updates this morning:

1) The module stopped doing anything in recent versions of PW 3 - I don't exactly when, but this is now fixed.

2) I also added support for restricting the new Pages > Tree dropdown menu that was added in 3.0.55

Please let me know if you find any problems with these changes or if you find any other situations where the module is no longer working. Given the rapid development of new ways to access the page tree that are being added to PW, I strongly recommend thoroughly testing your site if this module is protecting critical info from certain users. Hopefully everything is already taken care of for the current PW dev version, but with the UiKit admin theme, there could be possible breaks.

Thanks for testing and letting me know!

  • Like 3

Share this post


Link to post
Share on other sites

@adrian Is it possible with this module to hide specific pages under home or I should stay with the hardcoded HideOtherUserPages module?

Share this post


Link to post
Share on other sites
6 hours ago, PWaddict said:

@adrian Is it possible with this module to hide specific pages under home or I should stay with the hardcoded HideOtherUserPages module?

This module is for restricting users to a single branch of the page tree rather than hiding various ones throughout the entire tree. You'll need one of those other options for that. Maybe a module could be put together with more flexibility, but there are lots more issues when hiding specific pages.

Share this post


Link to post
Share on other sites
1 hour ago, adrian said:

This module is for restricting users to a single branch of the page tree rather than hiding various ones throughout the entire tree. You'll need one of those other options for that. Maybe a module could be put together with more flexibility, but there are lots more issues when hiding specific pages.

I selected Specified Branch Parent and then on the user's profile field I selected the Home branch. Then on the Branch edit exclusions I selected a page under the Home that I want to hide but it's still visible. What am I missing?

Share this post


Link to post
Share on other sites
5 minutes ago, PWaddict said:

I selected Specified Branch Parent and then on the user's profile field I selected the Home branch. Then on the Branch edit exclusions I selected a page under the Home that I want to hide but it's still visible. What am I missing?

Sorry, I think you have misunderstood how this works. If you are using the "Specified Branch Parent" - that is where you select the branch that you want the user restricted to. The "Branch Edit Exclusions" are just for things like external PageTable branches etc that the user still needs edit access to, even though they are outside their restricted branch.

Does that clear things up?

Share this post


Link to post
Share on other sites
1 hour ago, adrian said:

Sorry, I think you have misunderstood how this works. If you are using the "Specified Branch Parent" - that is where you select the branch that you want the user restricted to. The "Branch Edit Exclusions" are just for things like external PageTable branches etc that the user still needs edit access to, even though they are outside their restricted branch.

Does that clear things up?

Ok now I understand, thanks. I will stay then with the hardcoded HideOtherUserPages module.

Share this post


Link to post
Share on other sites

@adrian

I am working on a multisite project using single database. I forked multisite.module by Antti and another fork by Soma and started to adapt it for my needs. Luckily I found your module. I tried it out and it fits 90% to my needs and already saved a lot of work. Thanks for this great module. :rolleyes:

To get it working properly I need to make some changes. I think these changes could also be an enhancement of your module and you maybe want to take it.

First of all I need an option to set  branchRootParentId via hook which is currently not possible since the related function isn't hookable and private too.
It would be nice if you could change the visibility of the function getBranchRootParentId() to protected and make it hookable.
As far I can see there is no reason (security) to refrain from this.

Furthermore there are 2 unexpected behaviours or potential issues:

  1. In Processwire the breadcrumb 'Pages' is prepended to breadcrumbs in the PageEdit area of the root page only. @see ProcessPageEdit::setupBreadcrumbs()
    This behaviour is different in your module. The breadcrumb is prepended in any Editor not only for the branchRootParent since $this->wire('breadcrumbs')->count() returns always 0. Is this wanted like that?
    I would prefer the default behavior here. I found a working solution. If you like I could post an issue on github.
     
  2. The BranchRootParent is not prepended to the Pagetree under PagesTab.
    ProcessPageList::executeNavJSON() doesn't prepend branchRootParent here. This couldn't be solved inside your module.
    I can see a PW issue here. ProcessPageList::executeNavJSON() should use $config->rootPageID instead of hardcoded 1

    Possible Solution
    // in ProcessPageList::executeNavJSON
    // Line 489 from
    if(!$parentID) $parentID = 1;
    // to 
    if(!$parentID) $parentID = $config->rootPageID;
    
    // Line 494 from
    if($parentID === 1 && $parentViewable) $items->prepend($parent);
    // to
    if($parentID === $config->rootPageID && $parentViewable) $items->prepend($parent);
    
    // Line 523 from
    $numChildren = $id > 1 ? $page->numChildren : 0;
    // to
    $numChildren = $id != $config->rootPageID ? $page->numChildren : 0;
    
    // Line 551 from
    if($page->id > 1 && $page->numChildren) {
    // to
    if($page->id != $config->rootPageID && $page->numChildren) {
    
    //in your module
    public function ready() {
    $this->wire('config')->rootPageID = $this->branchRootParentId;
    // ...
    }

 

  • Like 2

Share this post


Link to post
Share on other sites
On 5/7/2017 at 5:34 AM, kixe said:

@adrian

I am working on a multisite project using single database. I forked multisite.module by Antti and another fork by Soma and started to adapt it for my needs. Luckily I found your module. I tried it out and it fits 90% to my needs and already saved a lot of work. Thanks for this great module. :rolleyes:

 

Working on a similar project, a kind of site parameterised site cloner. All in one PW install for maintenance commodity. Would love to see the outcome of this discussion :)

Share this post


Link to post
Share on other sites

Hi @kixe - thanks for all your thoughts here. Hopefully you know that I have been away and not just ignoring your post!

On 5/7/2017 at 3:34 AM, kixe said:

First of all I need an option to set  branchRootParentId via hook which is currently not possible since the related function isn't hookable and private too.
It would be nice if you could change the visibility of the function getBranchRootParentId() to protected and make it hookable.

The latest version has the getBranchRootParentId function hookable.

 

On 5/7/2017 at 3:34 AM, kixe said:

In Processwire the breadcrumb 'Pages' is prepended to breadcrumbs in the PageEdit area of the root page only. @see ProcessPageEdit::setupBreadcrumbs()
This behaviour is different in your module. The breadcrumb is prepended in any Editor not only for the branchRootParent since $this->wire('breadcrumbs')->count() returns always 0. Is this wanted like that?
I would prefer the default behavior here. I found a working solution. If you like I could post an issue on github.

The reason I did this is because when a user is restricted to a branch of the page tree, there is no "Home" breadcrumb, so I added this to give them easy access back to the root of the pages they have access to. I am curious about the working solution you have though - maybe it takes care of what we both want?

 

On 5/7/2017 at 3:34 AM, kixe said:

The BranchRootParent is not prepended to the Pagetree under PagesTab.
ProcessPageList::executeNavJSON() doesn't prepend branchRootParent here. This couldn't be solved inside your module.
I can see a PW issue here. ProcessPageList::executeNavJSON() should use $config->rootPageID instead of hardcoded 1

I think that regardless of the interaction with this, module those "1" values shouldn't be hardcoded in the PW as you noted - maybe you could submit a PR to Ryan to fix those? As for the actual prepending of BranchRootParent to the Pagetree under PagesTab, do you mean here:

595d410885623_ScreenShot2017-07-05at12_41_40PM.png.c958f147dce322a2066dd0a1bfe6c4a7.png

Test One and Test Two and children of the BranchRootParent and as you note, the BranchRootParent itself is not shown. Not critical, but I agree it would be nicer if it was, but from some quick looking around I don't think it's going to be possible at the moment without manually prepending the BranchRootParent to the markup returned by  ProcessPageList::executeNavJSON - certainly possible, but not pretty.

Any thoughts on my comments?

I'd certainly like to help as much as possible for you on this, so just let me know.

Cheers,
Adrian

 

  • Like 1

Share this post


Link to post
Share on other sites

@adrian First of all: Welcome back!

5 hours ago, adrian said:

The latest version has the getBranchRootParentId function hookable.

Great, Thanks!

Check out my fork to see the changes I made.
https://github.com/kixe/AdminRestrictBranch/tree/kixe

Everything is working pretty good together with the small changes in ProcessPageList::executeNavJSON()

6 hours ago, adrian said:

I think that regardless of the interaction with this, module those "1" values shouldn't be hardcoded in the PW as you noted - maybe you could submit a PR to Ryan to fix those?

Ryan is very busy and there are some other unsolved issues I am interested in. Furthermore there are many other places in the core where '1' is used instead of $config->rootPageID. I think it should be consistent but its not so easy to change this.

 

Share this post


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


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By BitPoet
      Since I was stuck to my flat today I took up a wish and rolled a Process module / CKEditor plugin combo that adds @-autocomplete like the mentions here in the forum to CKEditor fields. It's configurable, but only in module settings for now, the positioning of the select list is quite off and there's still some visual work to be done, so it is in early alpha state.
      Nonetheless, if you want to take a look, here it is:
      https://github.com/BitPoet/ProcessMention

       
      After installation, you may want to look into the "Additional selector" entry in the module's settings. You will most likely want to limit results to certain templates there.
       
      Edit: Updated to version 0.0.30 with fixed positioning of the dropdown.
      Edit2: Settings are configurable in field context now. If pwmentions is enabled, the according settings are shown on the "Input" tab.
       
    • By thuijzer
      https://github.com/thuijzer/processwire-FieldtypeBusinessHours
      Fieldtype Business Hours
      ProcessWire Fieldtype for entering business hours (opening hours)
       
      Input format
      Leave a day empty when closed on that day
      Times are in 24 hour format.
      9:00-12:00 9:00-12:00, 13:00-17:30 16:00-2:00  
      Usage in templates
      Days are from 1 to 7 where 1 is Monday and 7 is Sunday (ISO-8601)
      echo $page->field_name->isNowOpen() ? 'Now open' : 'Now closed'; if($page->field_name[1] == null) { echo 'Closed on Monday'; } if($page->field_name[2]->inRange('11:00')) { echo 'Tuesday at 11:00 open'; } echo $page->field_name[1]; echo $page->field_name[1]->getEntries()->getFrom()->format('H:i');  
    • By hellomoto
      I was working on this:
      class PWCRM extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Client Relationship Management', 'version' => .001, 'singular' => true, 'autoload' => true ); } public function init() {} public function ready() { $this->pages->addHookBefore('render', $this, 'accessHook'); $this->pages->addHookAfter('render', $this, 'hookAfterPageRender'); } public function accessHook(HookEvent $event) { $page = $this->wire('page'); if (!strpos($page->template->tags, 'crm')) return; if (!$this->wire('user')->hasRole('crm')) $this->wire('session')->redirect($this->wire('config')->urls->login);//throw new Wire404Exception(); } public function hookAfterPageRender(HookEvent $event) { $page = $event->object; echo $page->template->tags; if (!strpos($page->template->tags, 'crm')) return; echo $this->wire('config')->urls->templates; include_once($this->wire('config')->urls->templates.'functions.inc'); $pagehtml = $event->return; $pagehtml = str_replace( '</head>', '<link id="css_crm" rel="stylesheet" href="'.$this->wire('config')->urls->templates.'css/crm.css"> </head>', $pagehtml ); $event->return = $pagehtml; //$event->replace = true; } } I have tried placing the hooks into the init() function, and more... Neither method is effective. The echoes now output, but no redirection (although I have the access settings for the top-level template for this set to render a 404 for underprivileged users, which it does, overriding this, but nonetheless this should work aside from that.
      Then I wrote this up quick:
      <?php namespace ProcessWire; class MaintenanceMode extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Maintenance Mode', 'version' => 1, 'summary' => 'Disables the website frontend for non-superusers.', 'singular' => true, 'autoload' => true, 'permanent' => false ); } public function init() { $this->addHookBefore('Page::render', $this, 'displayDecide'); } public function displayDecide($event) { $page = $event->object; if ($page->template == 'admin' || $this->wire('user')->hasRole('superuser')) return; // replace the method hooked $event->replace = true; $event->return = "Patience please while we undergo some brief maintenance work."; } } which likewise avails nothing. What the hell is my problem here? 
    • By adrian
           Tracy Debugger for ProcessWire
      The ultimate “swiss army knife” debugging and development tool for the ProcessWire CMF/CMS
       

       
      Integrates and extends Nette's Tracy debugging tool and adds 30+ custom tools designed for effective ProcessWire debugging and lightning fast development
      The most comprehensive set of instructions and examples is available at: https://adrianbj.github.io/TracyDebugger
      Modules Directory: http://modules.processwire.com/modules/tracy-debugger/
      Github: https://github.com/adrianbj/TracyDebugger
      A big thanks to @tpr for introducing me to Tracy and for the idea for this module and for significant feedback, testing, and feature suggestions.