User permisions for specific page and it's subpages

Thanks, it’s possible set all blueprint as read only?

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

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.

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.

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?

Hm, you’re home.yml is not called home.yml for the news users but _home.yml, maybe that’s the problem.

No, I’m logged as admin, so $dir = __DIR__ . '/blueprints/home.yml'; should be working…

The its maybe the missing pages prefix::

'pages/home' => $dir

No :frowning: I try it with prefix, still This page has no blueprint setup yet

Hm :thinking: then I don’t know, it worked when I tested this with site.yml but I didn’t test other blueprints.

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:

53

My mistake :scream: 'page/home' => $dir instead 'pages/home' => $dir.

Thanks for patience :wink:

@texnixe Can you test your plugin within language variables? Thanks a lot!

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

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.

And how can I load different blueprints in this scenario please?

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.

Great news: The issue seems to have been fixed in the latest dev branch. In my test it worked.

So I can use solution with Kirby() to get user role and language variables will working too?

Yes.