Jump to content

Admin Restrict Branch Select


teppo
 Share

Recommended Posts

Admin Restrict Branch Select is an add-on / companion module for Admin Restrict Branch. With this module enabled, you can manually select more than one branch parent per user via the branch_parent field, and users with more than one option selected will be able to switch between those while editing site content. Switching between branches is done via a select field injected at the top of the page tree.

Note that users are still limited to one branch at a time: this module will not make it possible to view multiple branches at the same time.

When the module is installed, it will automatically update the branch_parent field if deemed necessary, i.e. if it isn't yet configured to allow selecting multiple pages. You can make changes to the field later, if you want to restrict selectable options by template, use asmSelect instead of PageListSelectMultiple, etc. 

This is an early beta release, so be sure to test carefully before enabling this module in production!

https://processwire.com/modules/admin-restrict-branch-select/

https://github.com/teppokoivula/AdminRestrictBranchSelect

  • Like 10
Link to comment
Share on other sites

Good day, @teppo!

I am having trouble installing the module from the modules directory. I am getting this error:

ProcessModuleInstall: File could not be downloaded (https://github.com/teppokoivula/AdminRestrictBranchSelect/archive/master.zip) 404 Not Found: (tried: curl)

Could you please check, if the download URL is correct.

Link to comment
Share on other sites

2 hours ago, Ivan Gretsky said:

Good day, @teppo!

I am having trouble installing the module from the modules directory. I am getting this error:


ProcessModuleInstall: File could not be downloaded (https://github.com/teppokoivula/AdminRestrictBranchSelect/archive/master.zip) 404 Not Found: (tried: curl)

Could you please check, if the download URL is correct.

Thanks — looks like the modules directory defaults to master branch, while GitHub defaults to main instead. Fixed now.

  • Like 1
Link to comment
Share on other sites

Thanks, the module now installs from the directory as it should.

But I must be missing something while configuring it. I assign two branches to a user, then login and get this error:

AdminRestrictBranch: You don't have permission to view this branch of the page tree.

I was thinking that the module will redirect the user after login to a branch he has access to. But this doesn't happen. Could you please suggest am I missing or misconfiguring something?

Link to comment
Share on other sites

Thanks for the tips, @adrian!

My setting is User Specified Branch Parent, as it is on your screenshot. I am visiting /admin/page/. Didn't know I could even link to a specific branch via URL. I did everything to clear the cache if that could affect it somehow, but with no luck. Still getting this error.

Link to comment
Share on other sites

@Ivan Gretsky - sorry for the trouble - could you please debug which of these conditions (https://github.com/adrianbj/AdminRestrictBranch/blob/4964a3f5b83338f7313f7c6daeefe6c6793640b0/AdminRestrictBranch.module.php#L228) is resulting in the error message?

And if it's the last one, then figure out where in this method: https://github.com/adrianbj/AdminRestrictBranch/blob/4964a3f5b83338f7313f7c6daeefe6c6793640b0/AdminRestrictBranch.module.php#L236

or in this hook (https://github.com/teppokoivula/AdminRestrictBranchSelect/blob/3ac88e7f4da482a5a16dad1abe3f221fdaeb2742/AdminRestrictBranchSelect.module.php#L54) in @teppo's module it's returning "1", rather than one of the allowed branch parents?

BTW - are you having the same issue with ARB without this addon module?

  • Like 2
Link to comment
Share on other sites

On 3/22/2021 at 7:32 PM, Ivan Gretsky said:

But I must be missing something while configuring it. I assign two branches to a user, then login and get this error:


AdminRestrictBranch: You don't have permission to view this branch of the page tree.

I was thinking that the module will redirect the user after login to a branch he has access to. But this doesn't happen. Could you please suggest am I missing or misconfiguring something?

Doesn't sound like you're missing anything, and yes — the module should automatically redirect the user to the first branch configured for them. So far I've been unable to reproduce this issue. Just in case I installed a new ProcessWire site with only default site profile + AdminRestrictBranch + AdminRestrictBranchSelect, and everything worked as expected.

Following the suggestions Adrian made above should give us a better idea of what's going on, but one more thing I'm wondering is that what version of ProcessWire you're running?

The module should work on 3.0.123 and above, but I've only tested it on 3.0.165, so it could have something to do with that. It kind of sounds like AdminRestrictBranch::init() might run before AdminRestrictBranchSelect::init(), or the latter might not run at all; either would at least explain the error you're seeing. A simple way to test if this is happening would be adding some debug code (bd(), or just die() with some sensible message) in both methods and seeing which gets executed first (should be AdminRestrictBranchSelect::init()).

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

@adrian, @teppo, thanks to both of you. I think I spotted the problem. There is the Page Edit Per User module installed on the same project that causes errors in some cases. I manages to get Admin Restrict Branch Select to work.

But I now face another less mysterious problem with frontend editing. It is available only for the branch that is currently selected. So when I switch from Branch A to Branch B in admin, Branch A is no longer editable on the frontend. It must be the way the module is intended to work. But is there a way to make the Page List in admin show only the currently selected branch, but keep the edit permissions to all of the selected branches? I think that even seems to be more expected from the user point of view, so maybe a might be a good improvement for the module)))

  • Like 1
Link to comment
Share on other sites

@Ivan Gretsky - glad you got the issue with the other module sorted out. Regarding the edit permissions for all allowed branches, I completely agree that this should be how it works. Even without Teppo's add-on module I think ARB should probably support this because there is the option to only restrict editing rights but still show all branches so this could be a nice enhancement. Can't promise a delivery timeframe for it but I'll do my best.

  • Like 1
Link to comment
Share on other sites

@teppo - something I just discovered is that if you uninstall this module it can result in the issue that @Ivan Gretsky was seeing where you can no longer access the page tree, or you can actually see everything (depending on what you have set for the "If no match, give all access or no access?" setting) because the settings for the "branch_parent" field are not reverted on uninstall.

I have a feeling this won't matter if/when I implement Ivan's request for support multiple branches for edit restrictions in the core ARB module, but in the meantime, this may bite someone if they're not careful.

  • Like 1
Link to comment
Share on other sites

9 hours ago, adrian said:

@teppo - something I just discovered is that if you uninstall this module it can result in the issue that @Ivan Gretsky was seeing where you can no longer access the page tree, or you can actually see everything (depending on what you have set for the "If no match, give all access or no access?" setting) because the settings for the "branch_parent" field are not reverted on uninstall.

I have a feeling this won't matter if/when I implement Ivan's request for support multiple branches for edit restrictions in the core ARB module, but in the meantime, this may bite someone if they're not careful.

That's a good point. Version 0.3.0 reverts field settings during uninstall.

Seems that altering data is not necessary: even if the field contains multiple values (in database), only one is returned with the new settings. I'm not 100% certain that this won't cause any unexpected side effects, but for the time being it seems to work fine... ?

  • Like 1
Link to comment
Share on other sites

  • 1 year later...

Good day, friends!

I am back to using the mighty ARB and this super useful addon to it. Thank you for your time and talent!

The old issue

On 4/5/2021 at 5:57 AM, adrian said:

this won't matter if/when I implement Ivan's request for support multiple branches for edit restrictions in the core ARB module

@adrian, it seems like you didn't find time for it yet. Is there a chance you come back to this in the near future?

The new issue

I just found that the changes that ARBS adds to the Page List also apply to  the children tab on the page edit screen. I see this is an unintended side effect that looks like a bug. @teppo, is there an easy way to change this behavior?

 

P.S Created github issues (this one and this one) for your convenience.

Link to comment
Share on other sites

  • 10 months later...

Hey @teppo perhaps you could give me hint, I'm facing an really annoying bug and don't know how to debug further:

I've installed your module first on a dev-server then tried to migrate the settings to the live server. On the dev server everything is running as expected, and you're module is working fine, but on the live server i get the message:

You don't have permission to view this branch of the page tree.

When I disable your Module the (first and then only) selected branch is shown as it should be via module "Admin Restrict Branch" .

Same settings on both websites: ProcessWire 3.0.210 © 2023 @ PHP 8.1.9

What I've noticed so far: When I do

 
db($event);  in .../AdminRestrictBranchSelect/AdminRestrictBranchSelect.module.php:114

the $event->return; is false on live website but true on dev server:

630012215_2023-02-1412_47_07-BaumProcessWireawo-dachau.deMozillaFirefoxPrivaterModus.png.6c735fba93a6f51ee585d0edc12fa1cb.png 679422028_2023-02-1412_49_43-SeitenProcessWireawo.vieregg.designMozillaFirefox.thumb.png.48b9707f86b45ac36f527f58273dc67c.png

Any ideas on how to debug further?

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

×
×
  • Create New...