Skip to content

Commit 38c8267

Browse files
committed
Check for permissions to access settings menu and added settings menu to sidebar menu
1 parent b9c3358 commit 38c8267

File tree

5 files changed

+31
-14
lines changed

5 files changed

+31
-14
lines changed

config/permissions.yaml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -265,17 +265,13 @@ perms: # Here comes a list with all Permission names (they have a perm_[name] co
265265
# label: "perm.database.write_db_settings"
266266
# alsoSet: ['read_db_settings', 'see_status']
267267

268-
#config:
269-
# label: "perm.config"
270-
# group: "system"
271-
# operations:
272-
# read_config:
273-
# label: "perm.config.read_config"
274-
# edit_config:
275-
# label: "perm.config.edit_config"
276-
# alsoSet: 'read_config'
277-
# server_info:
278-
# label: "perm.config.server_info"
268+
config:
269+
label: "perm.config"
270+
group: "system"
271+
operations:
272+
change_system_settings:
273+
label: "perm.config.change_system_settings"
274+
apiTokenRole: ROLE_API_ADMIN
279275

280276
system:
281277
label: "perm.system"

src/Controller/SettingsController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public function __construct(private readonly SettingsManagerInterface $settingsM
4040
#[Route("/settings", name: "system_settings")]
4141
public function systemSettings(Request $request, TagAwareCacheInterface $cache): Response
4242
{
43+
$this->denyAccessUnlessGranted('@config.change_system_settings');
44+
4345
//Create a clone of the settings object
4446
$settings = $this->settingsManager->createTemporaryCopy(AppSettings::class);
4547

@@ -62,9 +64,6 @@ public function systemSettings(Request $request, TagAwareCacheInterface $cache):
6264
$cache->invalidateTags(['tree_treeview', 'sidebar_tree_update']);
6365
}
6466

65-
66-
67-
6867
//Render the form
6968
return $this->render('settings/settings.html.twig', [
7069
'form' => $form

src/Services/Trees/ToolsTreeBuilder.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,13 @@ protected function getSystemNodes(): array
289289
))->setIcon('fa-fw fa-treeview fa-solid fa-database');
290290
}
291291

292+
if ($this->security->isGranted('@config.change_system_settings')) {
293+
$nodes[] = (new TreeViewNode(
294+
$this->translator->trans('tree.tools.system.settings'),
295+
$this->urlGenerator->generate('system_settings')
296+
))->setIcon('fa fa-fw fa-gears fa-solid');
297+
}
298+
292299
return $nodes;
293300
}
294301
}

src/Services/UserSystem/PermissionPresetsHelper.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ private function admin(HasPermissionsInterface $perm_holder): void
105105
$this->permissionResolver->setAllOperationsOfPermission($perm_holder, 'suppliers', PermissionData::ALLOW);
106106
$this->permissionResolver->setAllOperationsOfPermission($perm_holder, 'projects', PermissionData::ALLOW);
107107

108+
//Allow to change system settings
109+
$this->permissionResolver->setPermission($perm_holder, 'config', 'change_system_settings', PermissionData::ALLOW);
110+
108111
//Allow to manage Oauth tokens
109112
$this->permissionResolver->setPermission($perm_holder, 'system', 'manage_oauth_tokens', PermissionData::ALLOW);
110113
//Allow to show updates

translations/messages.en.xlf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13012,5 +13012,17 @@ Please note, that you can not impersonate a disabled user. If you try you will g
1301213012
<target>Show the image overlay with attachment details on hovering over the part image gallery.</target>
1301313013
</segment>
1301413014
</unit>
13015+
<unit id="ALfPkeR" name="perm.config.change_system_settings">
13016+
<segment>
13017+
<source>perm.config.change_system_settings</source>
13018+
<target>Change system settings</target>
13019+
</segment>
13020+
</unit>
13021+
<unit id="TlHeIjk" name="tree.tools.system.settings">
13022+
<segment>
13023+
<source>tree.tools.system.settings</source>
13024+
<target>System settings</target>
13025+
</segment>
13026+
</unit>
1301513027
</file>
1301613028
</xliff>

0 commit comments

Comments
 (0)