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:
parent
cd1b374d10
commit
7425a1493d
1 changed files with 11 additions and 10 deletions
|
|
@ -3,20 +3,21 @@
|
||||||
Kirby::plugin('adrienpayet/pdc-authorized-projects', [
|
Kirby::plugin('adrienpayet/pdc-authorized-projects', [
|
||||||
'userMethods' => [
|
'userMethods' => [
|
||||||
'currentProjects' => function() {
|
'currentProjects' => function() {
|
||||||
if ($this->role() == 'admin') {
|
$listed = page('projects')->children()->listed();
|
||||||
return page('projects')->children()->listed();
|
if ($this->role() == 'admin' && $this->hasNoAssignedProjects()) {
|
||||||
|
return $listed;
|
||||||
}
|
}
|
||||||
return page('projects')->children()->listed()->filter(function($project) {
|
return $listed->filter(fn($project) => $project->users()->toUsers()->has($this));
|
||||||
return $project->users()->toUsers()->has($this);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
'archivedProjects' => function() {
|
'archivedProjects' => function() {
|
||||||
if ($this->role() == 'admin') {
|
$unlisted = page('projects')->children()->unlisted();
|
||||||
return page('projects')->children()->unlisted();
|
if ($this->role() == 'admin' && $this->hasNoAssignedProjects()) {
|
||||||
|
return $unlisted;
|
||||||
}
|
}
|
||||||
return page('projects')->children()->unlisted()->filter(function($project) {
|
return $unlisted->filter(fn($project) => $project->users()->toUsers()->has($this));
|
||||||
return $project->users()->toUsers()->has($this);
|
},
|
||||||
});
|
'hasNoAssignedProjects' => function() {
|
||||||
|
return page('projects')->children()->filter(fn($p) => $p->users()->toUsers()->has($this))->isEmpty();
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue