Section or tab view permission

Just a simple question for a problem I encountered in a website i’m building with kirby.
Is it possible to assign a view permission to a single section or tab ? I want to make it visible ony for the admin role but i can’t find anything useful on this matter in the documentation. Also is there a list of permissions anywhere ?

No, that’s not possible, you can only assign permissions on a per-view basis. What you can do is assign different blueprints bases on user role: User permisions for specific page and it's subpages - #13 by texnixe

Thank you.

Hi there, I’m uplifting the same question for tab or section specific permissions in the latest 3.9.5? Possible now?

No, that’s still not possible via permissions, only via programmatic blueprints or role specific blueprints.

Hi, thanks for the cookbook, I’ve tried but I can’t get it work.
I have 4 different types of users:
/users/admin.yml
/users/copyrights.yml
/users/editor.yml
/users/guest.yml

For all users excepts the “guest”, all the blueprints and tabs within should be available like by default.
but for the specific “guest” users, I need to “hide” some tabs from 2 differents blueprints… I’ve tried the method described in the cookbook but I can’t hide these tabs.
Something I don’t understand in the cookbook:
in the original blueprints folder /site/blueprints, I need to give specific permissions to these 3 blueprints:

  • photography.yml
  • album.yml
  • copyright.yml

in the plugins/programmable-blueprints/blueprints I have:

  • album.admin.yml
  • album.guest.yml
  • copyright.admin.yml
  • copyright.guest.yml
  • photography.admin.yml
  • photography.guest.yml
  1. What do I do with the originals 3 blueprints in the /site/…? Does the plugin overide the original path?
  2. In order to make it worked, do I need to create specific yml of each of the 3 blueprints for all the 4 users type?

Many thanks,

Nicolas

Keep in mind that any blueprint present in /site/blueprints overwrites your plugin blueprints. Therefore, you have to remove those, otherwise it doesn’t work as expected.

So it does mean I have to create a specific blueprint for each user? That means for my 3 blueprints and my 4 users, I will need to have 12 blueprints specically named for each user in the plugins/programmable-blueprints/blueprints folder? Is that correct?

No, if several users roles share the same blueprints, you don’t have to duplicate the blueprint for those roles, only use a different one for those roles that need a different one.

What I wrote above is that you should not put the blueprints into the site folder for this setup, but define them in your plugin.

That means, I’m moving all the 3 blueprints that needs specific permissions from the site/blueprints → /site/plugins/programmable-blueprints/blueprints/
and I’m duplicating and renaming only the “guest” ones like so:
album.guest.yml
copyright.guest.yml
photography.guest.yml

correct?

Nicolas

in other words, is it possible to register only the “guest” blueprint with the following code?

<?php

use Kirby\Cms\App as Kirby;

Kirby::plugin('cookbook/programmable-blueprints', [
    'blueprints' => [
        'album' => function () {
            if ($user = kirby()->user() && $user->isGuest()) {
                return Data::read(__DIR__ . '/blueprints/album.guest.yml');
            }
        },
        'photography' => function () {
            if ($user = kirby()->user() && $user->isGuest()) {
                return Data::read(__DIR__ . '/blueprints/photography.guest.yml');
            }
        },
        'copyright' => function () {
            if ($user = kirby()->user() && $user->isGuest()) {
                return Data::read(__DIR__ . '/blueprints/copyright.guest.yml');
            }
        }
    ]
]);

And let the other “role” blueprints in the original /site/blueprints?

But if I’m logged in with the “guest” role with the original 3 blueprints temporarly off, it won’t work.

Many thanks,

No, that’s not possible.

I can only repeat:

If you register a page blueprint called for example album in your plugin and then put a blueprint with the same name into the `/site/blueprints/pages´ folder, this blueprint will overwrite the blueprint defined in your plugin.

what we do in the plugin with those if statements is to tell Kirby:

Hey, we need a page blueprint called album, but please, when you see a user role x, please use the file album.x.yml, otherwise use the file album.y.yml`.

Okay, I still can’t make it worked. It seems there’s a conflict.
The “index.php” code is:

<?php

use Kirby\Cms\App as Kirby;

Kirby::plugin('cookbook/programmable-blueprints', [
    'blueprints' => [
        'album' => function () {
            if (($user = kirby()->user()) && ($user->role() == 'guest')) {
                return Data::read(__DIR__ . '/blueprints/album.guest.yml');
            }
            else {
                return Data::read(__DIR__ . '/blueprints/album.yml');
            }
        },
        'photography' => function () {
            if (($user = kirby()->user()) && ($user->role() == 'guest')) {
                return Data::read(__DIR__ . '/blueprints/photography.guest.yml');
            }
            else {
                return Data::read(__DIR__ . '/blueprints/photography.yml');
            }
        },
        'copyright' => function () {
            if (($user = kirby()->user()) && ($user->role() == 'guest')) {
                return Data::read(__DIR__ . '/blueprints/copyright.guest.yml');
            }
            else {
                return Data::read(__DIR__ . '/blueprints/copyright.yml');
            }
        }
    ]
]);

Could the “programmable blueprints” interfere with assigned permissions?
Like in the users/guest.yml, I have

permissions:
  access:
    account: false
    panel: true
    site: true
    languages: false
    system: false
    users: false
  files:
    *: false
    read: true
  languages: false
  pages:
    *: false
    read: true
  site:
    update: false
  user: false
  users: false

But if I login with the “guest” access, I can’t see the needed pages, only “site” and “home”??

When I follow the cookbook recipe, and I’m login with “admin”, the blueprints assigned to all other users except the “guest” can’t be read?

With the “index.php” code above, when I delete the 3 blueprints in the site/blueprints folder:

  • photography.yml
  • album.yml
  • copyright.yml

None of the users role would work anymore?!?

Any help would be super nice…

Wait, you have to register them as pages/album etc., not just as album

1 Like

aahh, I’ve missed that one! It works! Many thanks. Such a good feedbacks. Love it.

Oh, I’ve encountered a bug, even if a guest user have no right to edit anything, in the following field:

          comments:
            label: Remarques
            translate: true
            type: list
            size: large

It works with Firefox but with Safari (16.6) or either Chrome (115), the comments field despite the fact it’s not editable for “guest”, you can still enter something but the “guest” is not able to save the changes. But once you’re login as an admin, the page is locked because the changes made by the “guest” has not been saved.

I’ve posted a bug report here

@texnixe dear sonja. this was very helpful in my case. i have only one (big) issue. i am trying to rewrite the tabs by using a yaml as a starting point.

  1. i have a yaml for a page, for instance “notes.original.yml”
  2. i read it in my plugin and start manipulating depending on the user role
  3. i return the yml
  4. done!

since the notes.yml file does not exist anywhere, this works fine. BUT… i wanted to do this for site.yml and it does not work, because kirby is throwing an error that site.yml does not exist :confused: as if somehow kirby checks before my plugin returns the yml data.

  1. i have site.original.yml
  2. i do the same as above
  3. kirby throws:

Kirby\Cms\Site::blueprint(): Return value must be of type Kirby\Cms\SiteBlueprint, null returned

but as you mentioned before, if i leave the site.yml file, then my plugin cannot overwrite it. any ideas?

@texnixe scratch that! it is working now… i just rewrote a bit and changed my if else… maybe i had an error somewhere ^^ not sure. all is good!

just on last thing… it seems the site function is getting called 3 times whenever i visit the site in panel

<?php

use Kirby\Cms\App as Kirby;

Kirby::plugin('scd/scd-smartblueprints', [
    'blueprints' => [
        'site' => function () {
            kirbylog('running site');
            $basicBlueprint = Data::read(kirby()->root() . '/site/blueprints/site.original.yml', 'yaml');
            return $basicBlueprint;
        },
    ]
]);
[2023-10-25 10:58:54] INFO running site
[2023-10-25 10:58:55] INFO running site
[2023-10-25 10:58:55] INFO running site

it doesnt really bother me, but doesnt seem to be good for performance. I am running Kirby 4.0.0-beta.2