I have a number of pages within the same parent, each of which has a user field to identify the user who created the page:
user:
label: User
type: user
required: true
These users are also in a specific role such that they can only create pages of this type, and no other. I’ve managed to get some permissions going to this end.
<?php
// https://getkirby.com/docs/panel/permissions
// https://getkirby.com/docs/panel/roles
return [
'name' => 'Sales',
'default' => false,
'panel' => true,
'permissions' => [
'*' => true,
'panel.access' => true,
'panel.access.options' => false,
'panel.access.users' => false,
'panel.page.*' => false,
'panel.page.create' => function() {
return $this->target()->page()->template() === 'partners'; // allow creating children of the Partners node
},
'panel.page.read' => function() {
return
'partners' === $this->target()->page()->template()
|| (
('partner' === $this->target()->page()->template())
&& 'dshannon' === $this->username()
);
},
'panel.page.update' => function() {
return $this->target()->page()->template() === 'partner'; // allow creating children of the Partners node
},
'panel.widget.*' => false,
'panel.widget.pages' => true,
'panel.site.update' => false,
'panel.user.*' => false,
]
];
What I’d like is to filter the pages list to only show those created by the currently logged in user. My attempt so far from the above is:
'panel.page.read' => function() {
return
'partners' === $this->target()->page()->template()
|| (
('partner' === $this->target()->page()->template())
&& ???? === $this->username()
);
},
The first portion of the conditional allows the user to access the parent page in the panel. The second portion, the first part of it, shows the pages within the parent. Fine. The last portion is where I attempt filtering by the current username.
https://getkirby.com/docs/cheatsheet/permissions/panel-page-read Is pretty brief and only gives an example using the template field. I’ve tried doing $this->target()->page()->user() === $this->username()
to no avail. Is this possible?