Custom blueprint for different roles

Hiya!
I’m currently diving into Kirby 3 and loving it so far.
For an online publication, I’ve set up two roles – admins who can edit everything and authors who should only be able to edit posts they’re the author of as well as create new blog posts.
I’ve successfully used hooks to prevent anyone who isn’t an admin from updating any page he’s not the author of.
However, instead of showing errors when someone tries to update a page without the necessary permissions, it would be more elegant to hide the page altogether. Essentially, I’d like to show one site blueprint to the admin, with a list of all pages, and one site blueprint to users with an ”author” role, with only those pages they are the authors of. (And an option to create a new blog post.)
I realise Kirby 3 is still quite young, but if anyone has any pointers as to how to achieve that, I’d appreciate it!

Cheers,
David

Hi David,

Check this example, it allows you to switch to different panel according to the user role.
It use the “custom folder setup” Kirby concept to choose which blueprint folder will be used by Kirby
“candidate” and “evaluator” are custom roles created in /site/blueprints/users/
“blueprintcandidate” and “blueprintevaluator” are folder created in site/ to host panel config files

This code must be added into the index.php file

require __DIR__ . '/kirby/bootstrap.php';

$kirby = new Kirby();

$current_user = $kirby->user();

if ( $current_user && $current_user->role() == 'candidate' ):
   $kirby = new Kirby([
       'roots' => [
           'blueprints' => __DIR__ . '/site/blueprintcandidate',
       ],
   ]);

elseif ( $current_user && $current_user->role() == 'evaluator' ):
   $kirby = new Kirby([
       'roots' => [
           'blueprints' => __DIR__ . '/site/blueprintevaluator',
       ],
   ]);
endif;

echo $kirby->render();
5 Likes

Thanks so much Gilles,
I’ll look into that – wouldn’t have thought of that option.
Cheers,
David

Hello David,
Would you agree to share your code?
I would like to know how you did it.
Pleasure, I thank you in advance. :slight_smile:

I haven’t had time to look at it yet, hopefully tomorrow. I’ll post my solution here once it’s done. :slight_smile:

Thank you, Gilles, for this solution. It helped me with a similar scenario. I find it a good workaround until the permission system in Kirby 3 gets updated.