fix: appliquer le filtre d'assignation admin dans projects.json.php

Le template bypassait currentProjects() pour les admins. Maintenant :
- Admin sans projets assignés → tous les projets (comportement d'origine)
- Admin avec projets assignés → uniquement ses projets (listed + unlisted)
- Autres rôles → inchangé

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
isUnknown 2026-03-04 15:07:04 +01:00
parent 7425a1493d
commit aceb8c7fdb

View file

@ -44,9 +44,12 @@ function getProjectData($project, $user)
$currentUser = $kirby->user();
try {
$children = $currentUser->role() == 'admin'
? $page->childrenAndDrafts()->map(fn($project) => getProjectData($project, $currentUser))->values()
: $currentUser->currentProjects()->map(fn($project) => getProjectData($project, $currentUser))->values();
if ($currentUser->role() == 'admin' && $currentUser->hasNoAssignedProjects()) {
$projectCollection = $page->childrenAndDrafts();
} else {
$projectCollection = $currentUser->currentProjects()->merge($currentUser->archivedProjects());
}
$children = $projectCollection->map(fn($project) => getProjectData($project, $currentUser))->values();
} catch (\Throwable $th) {
throw new Exception($th->getMessage() . ' line ' . $th->getLine() . ' in file ' . $th->getFile(), 1);
$children = [];