illycz
February 18, 2019, 1:12pm
1
I need solution where user role can edit only “blog” part of page.
So I need define permissions for edit blog page and subpages (articles).
In docs there is part about page blueprint based permissions https://getkirby.com/docs/guide/users/permissions#getting-more-specific , but it’s look like there is no option for set specific role which can do something.
Is it possible with Kirby 3?
Thanks
texnixe
February 18, 2019, 1:28pm
2
No, currently you cannot set role based permissions in blueprints. You could, however, set up different sets of blueprints based on user roles.
Maybe check out the guide for an intro: https://getkirby.com/docs/guide/users/permissions
Your indentation above is not correct, permissions should be on the same level as the title.
So
permissions:
access:
panel: false
creates users with no Panel access.
sort of, you can assign different blueprint folders per user role like this:
index.php
<?php
require __DIR__ . '/kirby/bootstrap.php';
$kirby = new Kirby();
$user = $kirby->user();
if ($user && $user->role() == 'candidate') {
…
I just played around a bit, and registering blueprints conditionally in a plugin based on user role also works:
<?php
if(($user = kirby()->user()) && $user->role() == 'client') {
$dir = __DIR__. '/blueprints/client/site.yml';
} else {
$dir = __DIR__ . '/blueprints/site.yml';
}
Kirby::plugin('my/plugin', [
'blueprints' => [
'site' => $dir
]
]);
But note that blueprints with the same name in the regular blueprints folder do override these settings.
illycz
February 19, 2019, 9:28pm
3
Thanks, it’s possible set all blueprint as read only?
texnixe
February 20, 2019, 6:18am
4
If you set the options like this…
options:
changeSlug: false
changeName: false
update: false
changeStatus: false
changeTemplate: false
delete: false
changeTitle: false
…a user can’t do anything with the page anymore.
1 Like
illycz
February 21, 2019, 11:22am
5
This is not working for me:
<?php
if(($user = kirby()->user()) && $user->role()->name() == 'news') {
$dir = __DIR__. '/blueprints/_news/_home.yml';
} else {
$dir = __DIR__ . '/blueprints/home.yml';
}
Kirby::plugin('soma/permissions', [
'blueprints' => [
'home' => $dir
]
]);
User with “news” role still see regular home.yml blueprint.
texnixe
February 21, 2019, 11:24am
6
Do you still have a home.yml in /site/blueprints/pages
? A regular blueprint will always override the ones defined in a plugin.
To avoid conflicts, I’d remove all standard blueprints and put them all into the plugin.
illycz
February 21, 2019, 12:33pm
7
When I remove standard home blueprint, homepage load default blueprint.
When I remove default blueprint site white This page has no blueprint setup yet
.
I don’t know if it’s problem with paths or?
texnixe
February 21, 2019, 12:36pm
8
Hm, you’re home.yml is not called home.yml for the news users but _home.yml, maybe that’s the problem.
illycz
February 21, 2019, 12:47pm
9
No, I’m logged as admin, so $dir = __DIR__ . '/blueprints/home.yml';
should be working…
texnixe
February 21, 2019, 12:49pm
10
The its maybe the missing pages
prefix::
'pages/home' => $dir
illycz
February 21, 2019, 1:09pm
11
No I try it with prefix, still This page has no blueprint setup yet
texnixe
February 21, 2019, 1:12pm
12
Hm then I don’t know, it worked when I tested this with site.yml
but I didn’t test other blueprints.
texnixe
February 21, 2019, 1:23pm
13
Ok, I just tested this and works perfectly for me.
I disabled the default home.yml.
Then in my plugin:
<?php
if(($user = kirby()->user()) && $user->role()->name() == 'client') {
$dir = __DIR__. '/blueprints/client/home.yml';
} else {
$dir = __DIR__ . '/blueprints/home.yml';
}
Kirby::plugin('texnixe/permissions', [
'blueprints' => [
'pages/home' => $dir
]
]);
And the structure of my plugins folder:
illycz
February 21, 2019, 1:52pm
14
My mistake 'page/home' => $dir
instead 'pages/home' => $dir
.
Thanks for patience
illycz
February 21, 2019, 4:54pm
15
@texnixe Can you test your plugin within language variables? Thanks a lot!
illycz
February 21, 2019, 5:08pm
16
The problem is within kirby()
while Kirby is not initialized yet: https://github.com/getkirby/kirby/issues/1307#issuecomment-451964007 .
Can I get user role in different way?
Thanks
texnixe
February 21, 2019, 5:19pm
17
The alternative would be to use a default folder setup based on user role when Kirby is initialized. It would be great is the blueprint extension would take a callback rather then just a plain array.
illycz
February 22, 2019, 7:27am
18
And how can I load different blueprints in this scenario please?
texnixe
February 22, 2019, 7:32am
19
Maybe check out the guide for an intro: https://getkirby.com/docs/guide/users/permissions
Your indentation above is not correct, permissions should be on the same level as the title.
So
permissions:
access:
panel: false
creates users with no Panel access.
sort of, you can assign different blueprint folders per user role like this:
index.php
<?php
require __DIR__ . '/kirby/bootstrap.php';
$kirby = new Kirby();
$user = $kirby->user();
if ($user && $user->role() == 'candidate') {
…
This option here allows you to define different blueprint folders based on user roles. It doesn’t work on an individual blueprint basis, though.
I currently have no other idea, since I don’t see a way to work around the problem with calling Kirby too early to get the user role.
texnixe
February 22, 2019, 9:51am
20
Great news: The issue seems to have been fixed in the latest dev branch. In my test it worked.