src/Security/Voter/LabelProfileVoter.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\LabelSystem\LabelProfile;
  23. use App\Entity\UserSystem\User;
  24. class LabelProfileVoter extends ExtendedVoter
  25. {
  26.     protected const MAPPING = [
  27.         'read' => 'read_profiles',
  28.         'create' => 'create_profiles',
  29.         'edit' => 'edit_profiles',
  30.         'delete' => 'delete_profiles',
  31.         'show_history' => 'show_history',
  32.         'revert_element' => 'revert_element',
  33.     ];
  34.     protected function voteOnUser($attribute$subjectUser $user): bool
  35.     {
  36.         return $this->resolver->inherit($user'labels'self::MAPPING[$attribute]) ?? false;
  37.     }
  38.     protected function supports($attribute$subject)
  39.     {
  40.         if ($subject instanceof LabelProfile) {
  41.             if (!isset(self::MAPPING[$attribute])) {
  42.                 return false;
  43.             }
  44.             return $this->resolver->isValidOperation('labels'self::MAPPING[$attribute]);
  45.         }
  46.         return false;
  47.     }
  48. }