diff --git a/config/permissions.yaml b/config/permissions.yaml index 27cb5a06..c7eefd4b 100644 --- a/config/permissions.yaml +++ b/config/permissions.yaml @@ -27,7 +27,7 @@ perms: # Here comes a list with all Permission names (they have a perm_[name] co 'currencies.read', 'attachment_types.read', 'measurement_units.read'] edit: label: "perm.edit" - alsoSet: 'read' + alsoSet: ['read', 'parts_stock.withdraw', 'parts_stock.add', 'parts_stock.move'] create: label: "perm.create" alsoSet: ['read', 'edit'] @@ -44,6 +44,18 @@ perms: # Here comes a list with all Permission names (they have a perm_[name] co label: "perm.revert_elements" alsoSet: ["read", "edit", "create", "delete", "show_history"] + parts_stock: + group: "data" + label: "perm.parts_stock" + operations: + withdraw: + label: "perm.parts_stock.withdraw" + add: + label: "perm.parts_stock.add" + move: + label: "perm.parts_stock.move" + + storelocations: &PART_CONTAINING label: "perm.storelocations" group: "data" diff --git a/src/Controller/PartController.php b/src/Controller/PartController.php index 125956d5..c2840314 100644 --- a/src/Controller/PartController.php +++ b/src/Controller/PartController.php @@ -354,12 +354,15 @@ class PartController extends AbstractController switch ($action) { case "withdraw": case "remove": + $this->denyAccessUnlessGranted('withdraw', $partLot); $withdrawAddHelper->withdraw($partLot, $amount, $comment); break; case "add": + $this->denyAccessUnlessGranted('add', $partLot); $withdrawAddHelper->add($partLot, $amount, $comment); break; case "move": + $this->denyAccessUnlessGranted('move', $partLot); $withdrawAddHelper->move($partLot, $targetLot, $amount, $comment); break; default: diff --git a/src/Security/Voter/PartLotVoter.php b/src/Security/Voter/PartLotVoter.php index 7886638f..da05070b 100644 --- a/src/Security/Voter/PartLotVoter.php +++ b/src/Security/Voter/PartLotVoter.php @@ -57,7 +57,7 @@ class PartLotVoter extends ExtendedVoter $this->security = $security; } - protected const ALLOWED_PERMS = ['read', 'edit', 'create', 'delete', 'show_history', 'revert_element']; + protected const ALLOWED_PERMS = ['read', 'edit', 'create', 'delete', 'show_history', 'revert_element', 'withdraw', 'add', 'move']; protected function voteOnUser(string $attribute, $subject, User $user): bool { @@ -65,6 +65,11 @@ class PartLotVoter extends ExtendedVoter throw new \RuntimeException('This voter can only handle PartLot objects!'); } + if (in_array($attribute, ['withdraw', 'add', 'move'])) + { + return $this->resolver->inherit($user, 'parts_stock', $attribute) ?? false; + } + switch ($attribute) { case 'read': $operation = 'read'; diff --git a/src/Services/UserSystem/PermissionManager.php b/src/Services/UserSystem/PermissionManager.php index e0529269..717c0bac 100644 --- a/src/Services/UserSystem/PermissionManager.php +++ b/src/Services/UserSystem/PermissionManager.php @@ -77,6 +77,11 @@ class PermissionManager */ public function dontInherit(HasPermissionsInterface $user, string $permission, string $operation): ?bool { + //Check that the permission/operation combination is valid + if (! $this->isValidOperation($permission, $operation)) { + throw new InvalidArgumentException('The permission/operation combination "'.$permission.'/'.$operation.'" is not valid!'); + } + //Get the permissions from the user return $user->getPermissions()->getPermissionValue($permission, $operation); } diff --git a/src/Services/UserSystem/PermissionPresetsHelper.php b/src/Services/UserSystem/PermissionPresetsHelper.php index d2ea616f..83ab0026 100644 --- a/src/Services/UserSystem/PermissionPresetsHelper.php +++ b/src/Services/UserSystem/PermissionPresetsHelper.php @@ -102,6 +102,7 @@ class PermissionPresetsHelper //Set datastructures $this->permissionResolver->setAllOperationsOfPermission($permHolder, 'parts', PermissionData::ALLOW); + $this->permissionResolver->setAllOperationsOfPermission($permHolder, 'parts_stock', PermissionData::ALLOW); $this->permissionResolver->setAllOperationsOfPermission($permHolder, 'categories', PermissionData::ALLOW); $this->permissionResolver->setAllOperationsOfPermission($permHolder, 'storelocations', PermissionData::ALLOW); $this->permissionResolver->setAllOperationsOfPermission($permHolder, 'footprints', PermissionData::ALLOW); diff --git a/templates/Parts/info/_part_lots.html.twig b/templates/Parts/info/_part_lots.html.twig index 5663ccd8..5a7bc217 100644 --- a/templates/Parts/info/_part_lots.html.twig +++ b/templates/Parts/info/_part_lots.html.twig @@ -65,21 +65,21 @@ diff --git a/translations/messages.en.xlf b/translations/messages.en.xlf index 038867c3..585cf567 100644 --- a/translations/messages.en.xlf +++ b/translations/messages.en.xlf @@ -10193,5 +10193,29 @@ Element 3 Added/Moved/Withdrawn parts successfully. + + + perm.parts_stock + Parts Stock + + + + + perm.parts_stock.withdraw + Withdraw parts from stock + + + + + perm.parts_stock.add + Add parts to stock + + + + + perm.parts_stock.move + Move parts between lots + +