Hide parts of the panel for user role

Hi,

I’m currently working on a site, where I need to have 3 user roles: admin, partner and client. Admins obviously should be able to do anything. Clients shouldn’t be able to enter the panel at all, which I guess I’ll be able to figure out.

Partners on the other hand can enter the panel, but some parts of it should be hidden from them, like specific pages. I’ve tried using hooks but I couldn’t find one that completely hides a page. Is there another way to do this?

Thanks
Robert

You can define that via the access permission in the user blueprint.

For that the best option currently is to use blueprints based on user role in your index.php.

<?php

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

$kirby = new Kirby();
$user  = $kirby->user();

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

} elseif ($user && $user->role() == 'sponsor') {
   $kirby = new Kirby([
       'roots' => [
           'blueprints' => __DIR__ . '/site/blueprints/sponsor',
       ],
   ]);
}

echo $kirby->render();

You could also use models in combination with before hooks.

1 Like

Thanks for the quick answer, @texnixe That should solve my problem! :blush: