Hi all,
we need a custom site permission to make some pages only be visible for the group of students. This is configured in the pages frontmatter/header like so:
access:
site.student: true
So far, everything works. But our pages will be mainly edited by using gravs admin plugin from not so “IT-based” people. And the plugin’s gui does know about our custom permission. And thus it does not list it in the available options/perms under “Page Access” (“Security” Tab). I already found out, that this list is populated from the plugins …/plugins/admin/permissions.yaml file. If I add the custom permission to that file, it gets actually listed as wanted in the gui. But editing plugin files directly seems to be bad practice, since my changes get lost when updating grav or the plugin. It there a way to extend or overwrite the permissions.yaml e.g. within /user - in a similar way as plugin main configurations can be overridden?
@anon76427325: Thanks a lot for your fast and really helpful feedback!!
Even through the above solution worked out as promised, I finally tweaked it a bit. Reading permission as shown above from yaml and bulk-adding them using addActions method had the backside, that I had to re-define all permissions (already defined by admin plugins permissions.yaml again). But I ideally wanted my plugin to only add the new custom perms and leave everything else unchanged. This I finally got using the following adaption of the above:
public function onRegisterPermissions(PermissionsRegisterEvent $event): void
{
$permissions = $event->permissions;
$customSitePermissions = $this->config()['site']['permissions'];
foreach($customSitePermissions as $p) {
$action = new Action("site.".$p["name"], ["label"=>$p["label"], "type"=>'access']);
$action->setParent($permissions->getAction("site"));
$permissions->addAction($action);
}
}
…this way my custom actions are read into from my plugins config, e.g.: