From 7425a1493dc9f4cc03544515aa67f52a82bdcf5e Mon Sep 17 00:00:00 2001 From: isUnknown Date: Wed, 4 Mar 2026 14:44:00 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20admin=20voit=20tous=20les=20projets=20s?= =?UTF-8?q?eulement=20si=20aucun=20ne=20lui=20est=20assign=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- public/site/plugins/user-projects/index.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) 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(); }, ] ]);