Hello!
I maintain a Kirby website with strict user rights.
Users with editor rights can only delete pages created using specific templates.
To achieve this, I use the page.delete:before hook.
What I want:
Editors should now be able to delete programme_arrangement pages,
that include programme_arrangement_event_virtualpage and taartifaxcalendar_arrangement_event_manual pages.
But not to delete single
programme_arrangement_event_virtualpage and taartifaxcalendar_arrangement_event_manual pages.
Right now, this only works if I include all the templates in the list of deletable templates.
Does anyone have a good approach to achieve that? ![]()
'page.delete:before' => function ($page, $kirby) {
// get user role
$role = kirby()->user()->role()->name();
if( $role === 'admin') {
// all good, you can delete everything
return;
}
// else …
// you are an editor, so you have restricted rights
switch ($page->intendedTemplate()->name()) {
// editors can only delete pages with those templates:
case 'job':
case 'article':
case 'person':
case 'programme_arrangement':
case 'programme_arrangement_event_virtualpage': // child of programme_arrangement page, comes from an api
case 'programme_arrangement_event_manual': // child of programme_arrangement page, created in kirby
// Allow deletion
break;
default:
throw new Exception('You do not have the necessary permissions to delete this page. Please contact an administrator.');
}
},
thank you!