feat: admin voit tous les projets seulement si aucun ne lui est assigné

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>
This commit is contained in:
isUnknown 2026-03-04 14:44:00 +01:00
parent cd1b374d10
commit 7425a1493d

View file

@ -3,20 +3,21 @@
Kirby::plugin('adrienpayet/pdc-authorized-projects', [
'userMethods' => [
'currentProjects' => function() {
if ($this->role() == 'admin') {
return page('projects')->children()->listed();
$listed = page('projects')->children()->listed();
if ($this->role() == 'admin' && $this->hasNoAssignedProjects()) {
return $listed;
}
return page('projects')->children()->listed()->filter(function($project) {
return $project->users()->toUsers()->has($this);
});
return $listed->filter(fn($project) => $project->users()->toUsers()->has($this));
},
'archivedProjects' => function() {
if ($this->role() == 'admin') {
return page('projects')->children()->unlisted();
$unlisted = page('projects')->children()->unlisted();
if ($this->role() == 'admin' && $this->hasNoAssignedProjects()) {
return $unlisted;
}
return page('projects')->children()->unlisted()->filter(function($project) {
return $project->users()->toUsers()->has($this);
});
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();
},
]
]);