jcodyb
1
I’m trying to allow a role able to only view/edit pages with the unlisted status. I tried adding this to the appropriate model:
public function isReadable(): bool
{
if ($user->role('photographer') && $this->status('unlisted') ||
$this->kirby()->user()->isAdmin()) {
return true;
}
return false;
}
I get $user is undefined. I’m probably misunderstanding something fundamental about how the code is supposed to work.
jcodyb
2
Ok updated, this code doesn’t throw any errors but I’m still able to edit pages that aren’t “unlisted”
public function isReadable(): bool
{
if (($user = $this->user()->role('photographer')) && $this->status('unlisted') ||
$this->kirby()->user()->isAdmin()) {
return true;
}
return false;
}
texnixe
3
The syntax is wrong
public function isReadable(): bool
{
if (($user = kirby()->user()) && (($user->role()->name() === 'photographer' && $this->status() === 'unlisted') || $user->isAdmin())) {
return true;
}
return false;
}
jcodyb
4
It seems so obvious now, thank you. I’m slowly learning!