From c9fc27a778856820bb8df6fd52cc5f5c68e59a4e Mon Sep 17 00:00:00 2001 From: Giuseppe Criscione <18699708+giuscris@users.noreply.github.com> Date: Sat, 12 Jul 2025 17:25:41 +0200 Subject: [PATCH 01/10] Prepend panel permissions names with `panel.` --- .../src/Panel/Controllers/BackupController.php | 6 +++--- .../src/Panel/Controllers/CacheController.php | 2 +- .../Panel/Controllers/DashboardController.php | 2 +- .../src/Panel/Controllers/FilesController.php | 12 ++++++------ .../src/Panel/Controllers/OptionsController.php | 6 +++--- .../src/Panel/Controllers/PagesController.php | 14 +++++++------- .../Panel/Controllers/StatisticsController.php | 2 +- .../src/Panel/Controllers/ToolsController.php | 8 ++++---- .../src/Panel/Controllers/UpdatesController.php | 4 ++-- .../src/Panel/Controllers/UsersController.php | 8 ++++---- formwork/src/Panel/Navigation/NavigationItem.php | 4 ++-- formwork/src/Users/Permissions.php | 6 +----- panel/config/navigation.php | 16 ++++++++-------- panel/views/dashboard/index.php | 10 +++++----- panel/views/files/edit.php | 8 ++++---- panel/views/files/index.php | 4 ++-- panel/views/options/tabs.php | 4 ++-- panel/views/pages/editor.php | 2 +- panel/views/pages/index.php | 4 ++-- panel/views/pages/tree.php | 4 ++-- panel/views/partials/files/file/item.php | 8 ++++---- panel/views/partials/files/file/list.php | 8 ++++---- panel/views/partials/sidebar.php | 4 ++-- panel/views/tools/tabs.php | 4 ++-- panel/views/users/index.php | 4 ++-- site/users/roles/admin.yaml | 11 +---------- site/users/roles/user.yaml | 6 +++--- 27 files changed, 79 insertions(+), 92 deletions(-) diff --git a/formwork/src/Panel/Controllers/BackupController.php b/formwork/src/Panel/Controllers/BackupController.php index dad9523f2..2f2b2bec5 100644 --- a/formwork/src/Panel/Controllers/BackupController.php +++ b/formwork/src/Panel/Controllers/BackupController.php @@ -20,7 +20,7 @@ final class BackupController extends AbstractController */ public function make(): JsonResponse|Response { - if (!$this->hasPermission('backup.make')) { + if (!$this->hasPermission('panel.backup.make')) { return $this->forward(ErrorsController::class, 'forbidden'); } @@ -47,7 +47,7 @@ public function make(): JsonResponse|Response */ public function download(RouteParams $routeParams): Response { - if (!$this->hasPermission('backup.download')) { + if (!$this->hasPermission('panel.backup.download')) { return $this->forward(ErrorsController::class, 'forbidden'); } @@ -68,7 +68,7 @@ public function download(RouteParams $routeParams): Response */ public function delete(RouteParams $routeParams): Response { - if (!$this->hasPermission('backup.download')) { + if (!$this->hasPermission('panel.backup.download')) { return $this->forward(ErrorsController::class, 'forbidden'); } diff --git a/formwork/src/Panel/Controllers/CacheController.php b/formwork/src/Panel/Controllers/CacheController.php index 00aa4d5e6..2d6d5fe69 100644 --- a/formwork/src/Panel/Controllers/CacheController.php +++ b/formwork/src/Panel/Controllers/CacheController.php @@ -15,7 +15,7 @@ final class CacheController extends AbstractController */ public function clear(RouteParams $routeParams, AbstractCache $cache): JsonResponse|Response { - if (!$this->hasPermission('cache.clear')) { + if (!$this->hasPermission('panel.cache.clear')) { return $this->forward(ErrorsController::class, 'forbidden'); } diff --git a/formwork/src/Panel/Controllers/DashboardController.php b/formwork/src/Panel/Controllers/DashboardController.php index e97a58509..10e1c36f6 100644 --- a/formwork/src/Panel/Controllers/DashboardController.php +++ b/formwork/src/Panel/Controllers/DashboardController.php @@ -13,7 +13,7 @@ final class DashboardController extends AbstractController */ public function index(Statistics $statistics): Response { - if (!$this->hasPermission('dashboard')) { + if (!$this->hasPermission('panel.dashboard')) { return $this->forward(ErrorsController::class, 'forbidden'); } diff --git a/formwork/src/Panel/Controllers/FilesController.php b/formwork/src/Panel/Controllers/FilesController.php index e41971518..6f4940a25 100644 --- a/formwork/src/Panel/Controllers/FilesController.php +++ b/formwork/src/Panel/Controllers/FilesController.php @@ -31,7 +31,7 @@ final class FilesController extends AbstractController */ public function index(): Response { - if (!$this->hasPermission('files.index')) { + if (!$this->hasPermission('panel.files.index')) { return $this->forward(ErrorsController::class, 'forbidden'); } @@ -46,7 +46,7 @@ public function index(): Response */ public function upload(): Response { - if (!$this->hasPermission('files.upload')) { + if (!$this->hasPermission('panel.files.upload')) { return $this->forward(ErrorsController::class, 'forbidden'); } @@ -87,7 +87,7 @@ public function upload(): Response */ public function edit(RouteParams $routeParams): Response { - if (!$this->hasPermission('files.edit')) { + if (!$this->hasPermission('panel.files.edit')) { return $this->forward(ErrorsController::class, 'forbidden'); } @@ -139,7 +139,7 @@ public function edit(RouteParams $routeParams): Response */ public function delete(RouteParams $routeParams): JsonResponse|Response { - if (!$this->hasPermission('files.delete')) { + if (!$this->hasPermission('panel.files.delete')) { return $this->forward(ErrorsController::class, 'forbidden'); } @@ -171,7 +171,7 @@ public function delete(RouteParams $routeParams): JsonResponse|Response */ public function rename(RouteParams $routeParams, FileFactory $fileFactory): JsonResponse|Response { - if (!$this->hasPermission('files.rename')) { + if (!$this->hasPermission('panel.files.rename')) { return $this->forward(ErrorsController::class, 'forbidden'); } @@ -240,7 +240,7 @@ public function rename(RouteParams $routeParams, FileFactory $fileFactory): Json */ public function replace(RouteParams $routeParams): JsonResponse|Response { - if (!$this->hasPermission('files.replace')) { + if (!$this->hasPermission('panel.files.replace')) { return $this->forward(ErrorsController::class, 'forbidden'); } diff --git a/formwork/src/Panel/Controllers/OptionsController.php b/formwork/src/Panel/Controllers/OptionsController.php index e9a922d91..306900e60 100644 --- a/formwork/src/Panel/Controllers/OptionsController.php +++ b/formwork/src/Panel/Controllers/OptionsController.php @@ -26,7 +26,7 @@ final class OptionsController extends AbstractController */ public function index(): Response { - if (!$this->hasPermission('options.site')) { + if (!$this->hasPermission('panel.options.site')) { return $this->forward(ErrorsController::class, 'forbidden'); } @@ -38,7 +38,7 @@ public function index(): Response */ public function systemOptions(Schemes $schemes): Response { - if (!$this->hasPermission('options.system')) { + if (!$this->hasPermission('panel.options.system')) { return $this->forward(ErrorsController::class, 'forbidden'); } @@ -81,7 +81,7 @@ public function systemOptions(Schemes $schemes): Response */ public function siteOptions(Schemes $schemes): Response { - if (!$this->hasPermission('options.site')) { + if (!$this->hasPermission('panel.options.site')) { return $this->forward(ErrorsController::class, 'forbidden'); } diff --git a/formwork/src/Panel/Controllers/PagesController.php b/formwork/src/Panel/Controllers/PagesController.php index 8701d884c..d58d0a85a 100644 --- a/formwork/src/Panel/Controllers/PagesController.php +++ b/formwork/src/Panel/Controllers/PagesController.php @@ -33,7 +33,7 @@ final class PagesController extends AbstractController */ public function index(): Response { - if (!$this->hasPermission('pages.index')) { + if (!$this->hasPermission('panel.pages.index')) { return $this->forward(ErrorsController::class, 'forbidden'); } @@ -52,7 +52,7 @@ public function index(): Response 'includeChildren' => true, 'class' => 'pages-tree-root', 'parent' => '.', - 'orderable' => $this->panel->user()->permissions()->has('pages.reorder'), + 'orderable' => $this->panel->user()->permissions()->has('panel.pages.reorder'), 'headers' => true, ]), ])); @@ -63,7 +63,7 @@ public function index(): Response */ public function create(PageFactory $pageFactory): Response { - if (!$this->hasPermission('pages.create')) { + if (!$this->hasPermission('panel.pages.create')) { return $this->forward(ErrorsController::class, 'forbidden'); } @@ -98,7 +98,7 @@ public function create(PageFactory $pageFactory): Response */ public function edit(RouteParams $routeParams): Response { - if (!$this->hasPermission('pages.edit')) { + if (!$this->hasPermission('panel.pages.edit')) { return $this->forward(ErrorsController::class, 'forbidden'); } @@ -241,7 +241,7 @@ public function preview(RouteParams $routeParams): Response */ public function reorder(): JsonResponse|Response { - if (!$this->hasPermission('pages.reorder')) { + if (!$this->hasPermission('panel.pages.reorder')) { return $this->forward(ErrorsController::class, 'forbidden'); } @@ -284,7 +284,7 @@ public function reorder(): JsonResponse|Response */ public function delete(RouteParams $routeParams): Response { - if (!$this->hasPermission('pages.delete')) { + if (!$this->hasPermission('panel.pages.delete')) { return $this->forward(ErrorsController::class, 'forbidden'); } @@ -333,7 +333,7 @@ public function delete(RouteParams $routeParams): Response */ public function upload(RouteParams $routeParams): Response|JsonResponse { - if (!$this->hasPermission('files.upload')) { + if (!$this->hasPermission('panel.files.upload')) { return $this->forward(ErrorsController::class, 'forbidden'); } diff --git a/formwork/src/Panel/Controllers/StatisticsController.php b/formwork/src/Panel/Controllers/StatisticsController.php index 2384ed294..6ed1f8157 100644 --- a/formwork/src/Panel/Controllers/StatisticsController.php +++ b/formwork/src/Panel/Controllers/StatisticsController.php @@ -13,7 +13,7 @@ final class StatisticsController extends AbstractController */ public function index(Statistics $statistics): Response { - if (!$this->hasPermission('statistics')) { + if (!$this->hasPermission('panel.statistics')) { return $this->forward(ErrorsController::class, 'forbidden'); } diff --git a/formwork/src/Panel/Controllers/ToolsController.php b/formwork/src/Panel/Controllers/ToolsController.php index 8075e4778..9423aeb2f 100644 --- a/formwork/src/Panel/Controllers/ToolsController.php +++ b/formwork/src/Panel/Controllers/ToolsController.php @@ -24,7 +24,7 @@ final class ToolsController extends AbstractController */ public function index(): Response { - if (!$this->hasPermission('tools.backups')) { + if (!$this->hasPermission('panel.tools.backups')) { return $this->forward(ErrorsController::class, 'forbidden'); } @@ -36,7 +36,7 @@ public function index(): Response */ public function backups(): Response { - if (!$this->hasPermission('tools.backups')) { + if (!$this->hasPermission('panel.tools.backups')) { return $this->forward(ErrorsController::class, 'forbidden'); } @@ -64,7 +64,7 @@ public function backups(): Response */ public function updates(): Response { - if (!$this->hasPermission('tools.updates')) { + if (!$this->hasPermission('panel.tools.updates')) { return $this->forward(ErrorsController::class, 'forbidden'); } @@ -83,7 +83,7 @@ public function updates(): Response */ public function info(): Response { - if (!$this->hasPermission('tools.info')) { + if (!$this->hasPermission('panel.tools.info')) { return $this->forward(ErrorsController::class, 'forbidden'); } diff --git a/formwork/src/Panel/Controllers/UpdatesController.php b/formwork/src/Panel/Controllers/UpdatesController.php index ae1ec6c1a..096b2e8ba 100644 --- a/formwork/src/Panel/Controllers/UpdatesController.php +++ b/formwork/src/Panel/Controllers/UpdatesController.php @@ -18,7 +18,7 @@ final class UpdatesController extends AbstractController */ public function check(Updater $updater): JsonResponse|Response { - if (!$this->hasPermission('updates.check')) { + if (!$this->hasPermission('panel.updates.check')) { return $this->forward(ErrorsController::class, 'forbidden'); } @@ -45,7 +45,7 @@ public function check(Updater $updater): JsonResponse|Response */ public function update(Updater $updater, AbstractCache $cache): JsonResponse|Response { - if (!$this->hasPermission('updates.update')) { + if (!$this->hasPermission('panel.updates.update')) { return $this->forward(ErrorsController::class, 'forbidden'); } diff --git a/formwork/src/Panel/Controllers/UsersController.php b/formwork/src/Panel/Controllers/UsersController.php index c054b96dd..5d5a51882 100644 --- a/formwork/src/Panel/Controllers/UsersController.php +++ b/formwork/src/Panel/Controllers/UsersController.php @@ -25,7 +25,7 @@ final class UsersController extends AbstractController */ public function index(): Response { - if (!$this->hasPermission('users.index')) { + if (!$this->hasPermission('panel.users.index')) { return $this->forward(ErrorsController::class, 'forbidden'); } @@ -40,7 +40,7 @@ public function index(): Response */ public function create(): Response { - if (!$this->hasPermission('users.create')) { + if (!$this->hasPermission('panel.users.create')) { return $this->forward(ErrorsController::class, 'forbidden'); } @@ -89,7 +89,7 @@ public function create(): Response */ public function delete(RouteParams $routeParams): Response { - if (!$this->hasPermission('users.delete')) { + if (!$this->hasPermission('panel.users.delete')) { return $this->forward(ErrorsController::class, 'forbidden'); } @@ -129,7 +129,7 @@ public function delete(RouteParams $routeParams): Response */ public function deleteImage(RouteParams $routeParams): Response { - if (!$this->hasPermission('users.deleteImage')) { + if (!$this->hasPermission('panel.users.deleteImage')) { return $this->forward(ErrorsController::class, 'forbidden'); } diff --git a/formwork/src/Panel/Navigation/NavigationItem.php b/formwork/src/Panel/Navigation/NavigationItem.php index 4a4a44540..d7d1cfae6 100644 --- a/formwork/src/Panel/Navigation/NavigationItem.php +++ b/formwork/src/Panel/Navigation/NavigationItem.php @@ -44,9 +44,9 @@ public function uri(): string /** * Get navigation item permissions */ - public function permissions(): string + public function permissions(): ?string { - return $this->data['permissions'] ?? '*'; + return $this->data['permissions']; } /** diff --git a/formwork/src/Users/Permissions.php b/formwork/src/Users/Permissions.php index 767174eb9..2033aa92e 100644 --- a/formwork/src/Users/Permissions.php +++ b/formwork/src/Users/Permissions.php @@ -34,10 +34,6 @@ public function __construct(array $permissions) */ public function has(string $permission): bool { - if ($permission === '*') { - return true; - } - if (array_key_exists($permission, $this->permissions)) { return $this->permissions[$permission]; } @@ -45,7 +41,7 @@ public function has(string $permission): bool // If $permission is not found try with the upper level one (super permission), // e.g. try with 'options' if 'options.updates' is not found - $superPermission = Str::before($permission, '.'); + $superPermission = Str::beforeLast($permission, '.'); if ($superPermission !== $permission) { return $this->has($superPermission); diff --git a/panel/config/navigation.php b/panel/config/navigation.php index 0da5fd608..b8541ab1f 100644 --- a/panel/config/navigation.php +++ b/panel/config/navigation.php @@ -7,49 +7,49 @@ 'dashboard' => [ 'label' => $translation->translate('panel.dashboard.dashboard'), 'uri' => '/dashboard/', - 'permissions' => 'dashboard', + 'permissions' => 'panel.dashboard', 'badge' => null, ], 'pages' => [ 'label' => $translation->translate('panel.pages.pages'), 'uri' => '/pages/', - 'permissions' => 'pages', + 'permissions' => 'panel.pages', 'badge' => $site->descendants()->count(), ], 'files' => [ 'label' => $translation->translate('panel.files.files'), 'uri' => '/files/', - 'permissions' => 'files', + 'permissions' => 'panel.files', 'badge' => null, ], 'statistics' => [ 'label' => $translation->translate('panel.statistics.statistics'), 'uri' => '/statistics/', - 'permissions' => 'statistics', + 'permissions' => 'panel.statistics', 'badge' => null, ], 'users' => [ 'label' => $translation->translate('panel.users.users'), 'uri' => '/users/', - 'permissions' => 'users', + 'permissions' => 'panel.users', 'badge' => $site->users()->count(), ], 'options' => [ 'label' => $translation->translate('panel.options.options'), 'uri' => '/options/', - 'permissions' => 'options', + 'permissions' => 'panel.options', 'badge' => null, ], 'tools' => [ 'label' => $translation->translate('panel.tools.tools'), 'uri' => '/tools/', - 'permissions' => 'tools', + 'permissions' => 'panel.tools', 'badge' => null, ], 'logout' => [ 'label' => $translation->translate('panel.login.logout'), 'uri' => '/logout/', - 'permissions' => '*', + 'permissions' => null, 'badge' => null, ], ]; diff --git a/panel/views/dashboard/index.php b/panel/views/dashboard/index.php index 79feb87f9..310efe343 100644 --- a/panel/views/dashboard/index.php +++ b/panel/views/dashboard/index.php @@ -16,10 +16,10 @@