i try to implement some roles with permissions. the dics state “panel.page.visibility” is available but my editor with ‘panel.page.visibility->false’ can still make a page visible. why? what have i missed?
thats my /site/roles/editor.php file:
<?php
return [
'name' => 'Editor',
'default' => false,
'permissions' => [
'*' => true,
'panel.site.update' => false,
'panel.page.visibility' => false,
'panel.user.*' => false,
'panel.user.read' => true,
'panel.user.update' => function() {
if($this->user()->is($this->target()->user())) {
// users are allowed to edit their own information
return true;
} else {
// other users can't be edited
return false;
}
}
]
];
Do i have to check the ‘visibility’ permission with own code like the ‘user.update’ one?
If you set visibility to false, the status button in the sidebar should actually disappear, so that the editor should not have a chance to even try it. Maybe I didn’t understand your problem right?
Yes, thats what i want. But… the button(s) are there and no permission restrictions for the page want work. the one for user (just edit myself) works well.
strange… I’ll try to put this permission test to a blank starterkit… maybe it works there. But…if… it doesn’t solve my problem with the project site.
EDIT: fresh starterkit… a “admin” and “editor” config under/site/roles/ and the role definition in site/config/config.php… the same: all page restrictions ignored.
@texnixe: Another question: is the $page element available in the roles-files?
I need to check for a soecific template name. How can i get the used template?
My usecase: i use the “modules plugin”. The editors should create pages with modules, Hide/delete/edit/reorder modules…BUT they should not make the main page (where the modules are) visible. This should only be possible for the Admin.
So my idea was to check for the template name in the role editor file… something like in the demo just with template-name:
'panel.page.create' => function() {
if($this->state() === 'ui') {
// always show the button
return true;
}
if($this->target()->data()['title'] !== 'Some specific title') {
return 'You are only allowed to add pages with some specific title';
}
return true;
}
If we didn’t remove that feature, it should actually work in the config file, for Kirby it’s just the same (but of course separate files are much easier to read). But you should never define roles in site/rolesand the config. Thanks for updating the docs, that was a bit confusing before.
Yes, partly: the error message kicks in on every page action (auto…save). How can i check for a visibility change (before and after?) a save action to prevent a change of it?
Is there a vivibility flag/data somewhere in the objects?