src/Security/Voter/OrderdetailVoter.php line 29

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
  5.  *
  6.  * Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics)
  7.  *
  8.  * This program is free software: you can redistribute it and/or modify
  9.  * it under the terms of the GNU Affero General Public License as published
  10.  * by the Free Software Foundation, either version 3 of the License, or
  11.  * (at your option) any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU Affero General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Affero General Public License
  19.  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  20.  */
  21. namespace App\Security\Voter;
  22. use App\Entity\PriceInformations\Orderdetail;
  23. use App\Entity\UserSystem\User;
  24. class OrderdetailVoter extends ExtendedVoter
  25. {
  26.     /**
  27.      * @var string[] When this permsission are encountered, they are checked on part
  28.      */
  29.     protected const PART_PERMS = ['show_history''revert_element'];
  30.     protected function voteOnUser($attribute$subjectUser $user): bool
  31.     {
  32.         if (in_array($attributeself::PART_PERMStrue)) {
  33.             return $this->resolver->inherit($user'parts'$attribute) ?? false;
  34.         }
  35.         return $this->resolver->inherit($user'parts_orderdetails'$attribute) ?? false;
  36.     }
  37.     protected function supports($attribute$subject)
  38.     {
  39.         if (is_a($subjectOrderdetail::class, true)) {
  40.             return in_array($attributearray_merge(
  41.                 self::PART_PERMS,
  42.                 $this->resolver->listOperationsForPermission('parts_orderdetails')
  43.             ), true);
  44.         }
  45.         return false;
  46.     }
  47. }