Fix permission & navigation bugs (#2786)

* Prevent duplicate nav registration

* Fix the security module not being accessible

Corrects the security permissions accidentally being hidden and fixes flawed logic which caused hiding the permissions for a module to then report no permission being given (which is why the security module was being hidden)

* Greatly simplified some of the permissions logic

---------

Co-authored-by: Adam Daley <admdly@users.noreply.github.com>
This commit is contained in:
Belle AerniandAdam Daley authored and GitHub committed 2025-06-12 09:04:36 +01:00
1 parent fba15adb0b
commit fa57b285e8
4 files changed
+33 -34

No files matched your search

+16 -23
View File
@@ -272,7 +272,7 @@ class Service implements InjectionAwareInterface
$modules = $this->di['mod']('extension')->getCoreModules();
$installed = $this->getInstalledMods();
$list = array_merge($modules, $installed);
$list = array_unique(array_merge($modules, $installed));
foreach ($list as $mod) {
if (!$staff_service->hasPermission($admin, $mod)) {
continue;
@@ -698,19 +698,14 @@ class Service implements InjectionAwareInterface
continue;
}
// If getSpecificModulePermissions returns false, we need to skip that module and not include it in the permissions list
$permissions = $this->getSpecificModulePermissions($module, true);
if ($permissions === false) {
continue;
} else {
$modules[$module]['permissions'] = $permissions;
}
$permissions = $this->getSpecificModulePermissions($module);
$modules[$module]['permissions'] = $permissions;
}
return $modules;
}
public function getSpecificModulePermissions(string $module, bool $buildingCompleteList = false): array|false
public function getSpecificModulePermissions(string $module): array|false
{
$class = 'Box\Mod\\' . ucfirst($module) . '\Service';
if (class_exists($class) && method_exists($class, 'getModulePermissions')) {
@@ -720,22 +715,20 @@ class Service implements InjectionAwareInterface
}
$permissions = $moduleService->getModulePermissions();
if (isset($permissions['hide_permissions']) && $permissions['hide_permissions']) {
return $buildingCompleteList ? false : [];
} else {
if (isset($permissions['hide_permissions']) && !$permissions['hide_permissions']) {
unset($permissions['hide_permissions']);
// Fill in the manage_settings permission as it will always be the same
if (isset($permissions['manage_settings'])) {
$permissions['manage_settings'] = [
'type' => 'bool',
'display_name' => __trans('Manage settings'),
'description' => __trans('Allows the staff member to edit settings for this module.'),
];
}
return $permissions;
}
// Fill in the manage_settings permission as it will always be the same
if (isset($permissions['manage_settings'])) {
$permissions['manage_settings'] = [
'type' => 'bool',
'display_name' => __trans('Manage settings'),
'description' => __trans('Allows the staff member to edit settings for this module.'),
];
}
return $permissions;
}
return [];
-1
View File
@@ -34,7 +34,6 @@ class Service
{
return [
'can_always_access' => true,
'hide_permissions' => true,
'run_checks' => [
'type' => 'bool',
'display_name' => __trans('Run security checks'),
+16 -9
View File
@@ -162,7 +162,12 @@ class Service implements InjectionAwareInterface
$modulePermissions = $extensionService->getSpecificModulePermissions($module);
$permissions = $this->getPermissions($member->id);
$canAlwaysAccess = $modulePermissions['can_always_access'] ?? false;
if ($modulePermissions['hide_permissions'] ?? false) {
$canAlwaysAccess = true;
} else {
$canAlwaysAccess = $modulePermissions['can_always_access'] ?? false;
}
if (!$canAlwaysAccess) {
// They have no permissions or don't have any access to that module
if (empty($permissions) || !array_key_exists($module, $permissions) || !is_array($permissions[$module]) || !($permissions[$module]['access'] ?? false)) {
@@ -170,15 +175,17 @@ class Service implements InjectionAwareInterface
}
}
// If this passes, the permission key isn't assigned to them and they therefore don't have permission
if ((!is_null($key) && !is_array($permissions[$module])) || (!is_null($key) && !array_key_exists($key, $permissions[$module]))) {
return false;
}
if (!is_null($key)) {
// If this passes, the permission key isn't assigned to them and they therefore don't have permission
if (!is_array($permissions[$module]) || !array_key_exists($key, $permissions[$module])) {
return false;
}
if (!is_null($key) && !is_null($constraint)) {
return $permissions[$module][$key] === $constraint;
} elseif (!is_null($key)) {
return (bool) $permissions[$module][$key];
if (!is_null($constraint)) {
return $permissions[$module][$key] === $constraint;
} else {
return (bool) $permissions[$module][$key];
}
}
return true;
@@ -148,7 +148,7 @@
<input type="hidden" name="CSRFToken" value="{{ CSRFToken }}">
<input type="hidden" name="permissions[default]" value="">
{% for modName, mod in mods %}
{% for modName, mod in mods|filter(mod => mod.permissions.hide_permissions is not true) %}
<div class="row">
<div class="col-1"></div>
<div class="col-2">