Restrict part lot withdraw/add/move operations to the owner of a part lot

This commit is contained in:
Jan Böhmer 2023-04-02 23:35:18 +02:00
parent 447b54fa4b
commit a7ff690891
3 changed files with 59 additions and 18 deletions

View file

@ -67,7 +67,15 @@ class PartLotVoter extends ExtendedVoter
if (in_array($attribute, ['withdraw', 'add', 'move']))
{
return $this->resolver->inherit($user, 'parts_stock', $attribute) ?? false;
$base_permission = $this->resolver->inherit($user, 'parts_stock', $attribute) ?? false;
$lot_permission = true;
//If the lot has an owner, we need to check if the user is the owner of the lot to be allowed to withdraw it.
if ($subject instanceof PartLot && $subject->getOwner()) {
$lot_permission = $subject->getOwner() === $user || $subject->getOwner()->getID() === $user->getID();
}
return $base_permission && $lot_permission;
}
switch ($attribute) {