i created a few small projects with great success. Now I have a new project with a set of features I am not sure how to handle in kirby.
Besides some basic pages, forms etc. the page should allow users to administrate/modify one single page within the web project. Think of it like a small business directory page. Each business gets a kirby user account and can then edit one single page. The structure of this page is identical for all users. In addition for one such page there should exist a collection of events, also manageable by this user (subpages?), and the project has a dedicated site where all events from all users should be listet.
I am thinking on how to structure the content and how to handle the permissions.
As far as I know, there exist no per-page permissions in Kirby. Also the other sites need to be hidden in the panel.
I attempted to use groups for this, nut then I have as many groups as users.
Can I use some specific naming scheme to build this functionality. Like storing a field âuserâ within a page, and only if they match, the user can edit the page or create new subpages?
Any plugins for this? I would like to quickly hack a working demo together in order to estimate
the effort or if I have to switch cms for this project.
Kirbyâs permissions allow you to control access via user roles rather than single users. However, you could use route hooks to prevent individual users from actually accessing a page (although that would not hide those pages from the panel).
If you use custom pages sections like the Pagesdisplay Section plugin, you could however, filter the pages a user gets to see by user, assuming that you store which user can access a page in a field in the page.
thank you for your fast reply. I tried to implement your suggestions within a fresh kirby installation including the demo data. The notes have a user field already, so my idea was to assign a few users to different notes and try to filter them.
I tried different versions of the query, but all result in the same error:
Der Bereich "notes" konnte nicht geladen werden: Argument 1 passed to Kirby\Toolkit\Collection::filterBy() must be of the type string, null given, called in /Users/durpex/tmp/kirby/kirby/src/Toolkit/Query.php on line 98
With this page method defined in a plugin. Alternatively, if you only need it for a specific page type, you can define the method in a page model instead.
thank you again for pointing me in the right direction.
Hardcoding values works fine now, but using the plugin I get the following error:
Der Bereich ânotesâ konnte nicht geladen werden: Invalid query result - Result must be of type Kirby\Cms\Pages, Kirby\Cms\Field given.
I used your example from above.
Just to be sure: all filter queries documented here should work theoretically? So I could use a function to diplay all notes for the admin user group and only specific ones for others.
Another idea that could come in handy: Is it possible, using the âuser.create:afterâ Hook to create a page if a user within a specific user group is created and setting this new user for the page? Reading the documentation it seems that â$page->createChildâ should work.
This results in the same error message.
This is the section in site.yml:
sections:
# The `notes` section reuses the pages section defined in `/site/blueprints/sections/notes.yml`
notes: #sections/notes
headline: Notes
type: pagesdisplay
query: site.find("notes").getUserPages()
I was running into the same question just now and realised that the kirby api had changed a lot since 2019 and consequently the solution by @texnixe might not be the best anymore. i would propose changing the accessibility of the page in question by overwriting the function isAccessible() in the note.php model class.
class NotePage extends Page
{
function isAccessible(): bool
{
$user = kirby()->user();
if (!parent::isAccessible()) {
return false;
}
if ($user->role()->name() === "editor") {
$arr = $user->can_edit_notes()->yaml();
return A::has($arr, $this->uuid());
}
return true;
}
}
the field can_edit_notes of the user blueprint with the role editor is of type pages, so you (as admin) can add notes which the user of role editor can edit.
you have to lock down the permissions of role editor to prohibit edits of field can_edit_notes on their own.
i would propose locking down permissions of the editor role. a complete role blueprint could look like this.