mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-12-29 06:19:32 +00:00
Check permissions for time travel and element undo.
This commit is contained in:
parent
254d4e6c69
commit
8a61b465d0
23 changed files with 370 additions and 90 deletions
57
src/Security/Voter/OrderdetailVoter.php
Normal file
57
src/Security/Voter/OrderdetailVoter.php
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Security\Voter;
|
||||
|
||||
|
||||
use App\Entity\Parts\PartLot;
|
||||
use App\Entity\PriceInformations\Orderdetail;
|
||||
use App\Entity\UserSystem\User;
|
||||
|
||||
class OrderdetailVoter extends ExtendedVoter
|
||||
{
|
||||
/** @var string[] When this permsission are encountered, they are checked on part */
|
||||
protected const PART_PERMS = ['show_history', 'revert_element'];
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function voteOnUser($attribute, $subject, User $user): bool
|
||||
{
|
||||
if (in_array($attribute, self::PART_PERMS, true)) {
|
||||
return $this->resolver->inherit($user, 'parts', $attribute) ?? false;
|
||||
}
|
||||
|
||||
return $this->resolver->inherit($user, 'parts_orderdetails', $attribute) ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function supports($attribute, $subject)
|
||||
{
|
||||
if (is_a($subject, Orderdetail::class, true)) {
|
||||
return in_array($attribute, array_merge(
|
||||
self::PART_PERMS,
|
||||
$this->resolver->listOperationsForPermission('parts_orderdetails')
|
||||
), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue