Si un admin a au moins un projet assigné, il ne voit que ses projets. S'il n'en a aucun, il voit tous les projets (comportement précédent). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
23 lines
845 B
PHP
23 lines
845 B
PHP
<?php
|
|
|
|
Kirby::plugin('adrienpayet/pdc-authorized-projects', [
|
|
'userMethods' => [
|
|
'currentProjects' => function() {
|
|
$listed = page('projects')->children()->listed();
|
|
if ($this->role() == 'admin' && $this->hasNoAssignedProjects()) {
|
|
return $listed;
|
|
}
|
|
return $listed->filter(fn($project) => $project->users()->toUsers()->has($this));
|
|
},
|
|
'archivedProjects' => function() {
|
|
$unlisted = page('projects')->children()->unlisted();
|
|
if ($this->role() == 'admin' && $this->hasNoAssignedProjects()) {
|
|
return $unlisted;
|
|
}
|
|
return $unlisted->filter(fn($project) => $project->users()->toUsers()->has($this));
|
|
},
|
|
'hasNoAssignedProjects' => function() {
|
|
return page('projects')->children()->filter(fn($p) => $p->users()->toUsers()->has($this))->isEmpty();
|
|
},
|
|
]
|
|
]);
|