diff --git a/public/site/plugins/user-projects/index.php b/public/site/plugins/user-projects/index.php index 733a9b3..c1a4f3f 100644 --- a/public/site/plugins/user-projects/index.php +++ b/public/site/plugins/user-projects/index.php @@ -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(); }, ] ]);