My way to restrict a role
I run XAMPP Version: 7.2.15, PHP/7.2.15, on Win10 64Bit as my development system.
What I have done to test:
- I installed a new starterkit 3.2.5.
- I updated to Kirby 3.3.0-rc.2 (I could not download the newer rc-version).
- I changed the content of the existing file
\index.php
to:
<?php
require __DIR__ . '/kirby/bootstrap.php';
$kirby = new Kirby();
$user = $kirby->user();
if ($user && $user->role() == 'editor') {
$kirby = new Kirby([
'roots' => [
'blueprints' => __DIR__ . '/site/blueprints/bp_role_editor',
],
]);
};
echo $kirby->render();
- I created a new directory
\site\blueprints\bp_role_editor
and then a new directory\site\blueprints\bp_role_editor\users
. - I added a new file
\site\blueprints\bp_role_editor\site.yml
that looks like:
title: Website for Editor role
### site\blueprints\bp_role_editor\site.yml
columns:
- width: 1/3
sections:
parts:
headline: Pages for Editor role
type: pages
templates:
- notes # only this template-type is shown for this role at this menu level
create: false # avoid new pages at this menu level
delete: false
- width: 2/3
fields:
infofield:
type: info
label: Info for Editor role
text: |
This is the panel start page for the role "editor".
- I added a new file
\site\blueprints\bp_role_editor\users\editor.yml
that looks like:
title: Editor with Editor role
description: The Editor uses the panel to edit only the notes page and note pages as well as his own user fields.
permissions: # for this role, may be you want to make changes here!!!
access:
users: false
settings: false
site:
update: false
pages:
delete: false
user:
changeRole: false
changeName: false
delete: false
sections: # user fields for this role itself
meta:
type: fields
headline: User data
fields:
phone:
label: Phone [bp_role_editor\users\editor]
type: text
width: 1/2
mobile:
label: mobile Phone
type: text
width: 1/2
- I created a new directory
\site\blueprints\bp_role_editor\pages
and then I copied the file\site\blueprints\pages\notes.yml
to\site\blueprints\bp_role_editor\pages\notes.yml
and the file\site\blueprints\pages\note.yml
to\site\blueprints\bp_role_editor\pages\note.yml
.
We can add user permissions for this role in these new files. - I created a new directory
\site\blueprints\bp_role_editor\sections
and then I copied the file\site\blueprints\sections\notes.yml
to\site\blueprints\bp_role_editor\sections\notes.yml
. - I copied the file
\site\blueprints\bp_role_editor\users\editor.yml
to\site\blueprints\users\editor.yml
.
This new file is for the admins in the panel! To show this, you can make some changes (e.g. text) in the file\site\blueprints\users\editor.yml
. So only in the file copy I deleted every textbp_role_editor\
. - I addded an admin (for me !) in the panel and then as admin I added a new user with the role
editor
as my test user. - Now I can test this new user with the role
editor
and his permissions.
Notes:
- I don’t need any routes for this.
- Yes, I know that I have some files, I copied, for each role a second time. But the setup is simple. Maybe we can work with symbolic links for the directories in the steps 7 to 8. But that depends on the installation and its OS. Or may be we can use routes or config options for this???
I don’t know…
Good luck!