I need to restrict editors to edit one page only.
The easiest way to do that would be redirecting from panel home to the page (if role == 'editor').
No idea how to do that. I tried:
using a route, but can’t intercept panel pages with a pattern.
with hooks, but did not find a hook that triggers on panel login. Also, I’d like to trigger the redirect whenever an editor tries accessing the panel homepage, not only after login.
Thaks @texnixe.
As mentioned earlier, I’d need to trigger the redirect every time an editor tries accessing the panel homepage, not only after login. This is because he/she might click on the site name in the panel breadcrumb.
Can anyone think of a way to do this with a route or some other sort of redirect?
I thought it could be done with a route.before hook, but that only works when reloading the page, not when clicking a link.
What you could try instead is log in the user from the frontend, reroute to the allowed page and use permissions and access hooks to prevent access to other parts of the Panel.
@texnixe,
I’m already using permissions to prevent access to some panel pages, and will probably end up using this approach.
The outcome is a bit dirtier since the user is prompted an error message when trying to access the forbidden page (e.g. ! The page “options” cannot be found).
Do you also get that if you set options in blueprints like this:
Title: Page hidden for editors
options:
read:
editor: false
This should actually hide all pages not available to editors even in the Dashboard. The extra site.yml is still the better alternative on top, because you can then create a nicer layout for this special use case.
If you implement the above hints from @texnixe with my link, you can use the default.yml file in the editor blueprint path to create a special error message. The prerequisite would be that for all pages, that the editor should edit, there is a separate *.yml file in his blueprint path.
The file site.yml is his start page in the panel, which can look completely different than e.g. for admins.
You can also hide unwanted entries in the top left menu for the editor, depending on your requirements.
@texnixe I tried that but the outcome didn’t seem consistent. I’ll try to explain better.
My site.yml has a single list of pages that should be accessible to editors
Till here all is good.
Then there needs to be an index of the pages of the site, visible only to admins. I tried two ways to obtain this.
Option A - Using a standard pages section
The pages are actually hidden to editors (by setting read to false for editors in the pages’ blueprints), but they can still see an empty list and can still create new pages.
I know I can use user blueprints to avoid creation, but then editors can’t create the only kind of pages they’re supposed to (new stories, that are children of page map).
Option B - Using a field of type pages
I manually added the pages to this field to create the index but they are still visible to editors even if in their blueprint I set read to false for editors.
# site.yml continues (B)
...
sections:
...
section:
type: fields
fields:
index:
type: pages
disabled: true # this is to create a static, non editable list
Hm, I have to look into that. That setting shouldn’t be in site.yml, though, but in the blueprints for the parent pages where the user is not allowed to create subpages. Or do you mean, prevent the editors to create first level pages? But that should be solvable by creating different site.yml blueprints for editors and admins.
Oh this would be perfect!
Can you clarify what role the plugin plays in this, or where I should place this code? (I thought in index.php but I’m not sure anymore )
Create a new folder in /site/plugins and put an index.php into it.
I don’t know if your solution will work or not, you have to test it.
The solution @gillesvauvarin first came up with is fine if you create custom blueprint folders per user roles. If you only want to change single blueprints, the plugin approach is the better solution.
I tried (A) using two different folders (/site/blueprints/admin/site.yml and /site/blueprints/editor/site.yml) but it gives me an error: Call to a member function options() on null.
If (B) I leave the original /site/blueprints/site.yml (intended for editors) and just change the setting for admin roles to /site/blueprints/admin/site.yml, the original one overwrites the admin one as you predicted.