From da83314d6986a2504fb26fc3e82c0e40e6d9ef49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Wed, 8 Apr 2020 15:54:07 +0200 Subject: [PATCH] Fixed a wrong AccessDenied exception related to data structures StructureVoter now can work with ProxyClasses (child classes of "our" classes) --- src/Security/Voter/StructureVoter.php | 44 +++++++++++++++------------ 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/Security/Voter/StructureVoter.php b/src/Security/Voter/StructureVoter.php index af01b75a..fe3ce84b 100644 --- a/src/Security/Voter/StructureVoter.php +++ b/src/Security/Voter/StructureVoter.php @@ -52,11 +52,24 @@ use App\Entity\Parts\Storelocation; use App\Entity\Parts\Supplier; use App\Entity\PriceInformations\Currency; use App\Entity\UserSystem\User; + use function get_class; use function is_object; class StructureVoter extends ExtendedVoter { + protected const OBJ_PERM_MAP = [ + AttachmentType::class => 'attachment_type', + Category::class => 'categories', + Device::class => 'devices', + Footprint::class => 'footprints', + Manufacturer::class => 'manufacturers', + Storelocation::class => 'storelocations', + Supplier::class => 'suppliers', + Currency::class => 'currencies', + MeasurementUnit::class => 'measurement_units', + ]; + /** * Determines if the attribute and subject are supported by this voter. * @@ -90,27 +103,18 @@ class StructureVoter extends ExtendedVoter } else { $class_name = $subject; } - switch ($class_name) { - case AttachmentType::class: - return 'attachment_types'; - case Category::class: - return 'categories'; - case Device::class: - return 'devices'; - case Footprint::class: - return 'footprints'; - case Manufacturer::class: - return 'manufacturers'; - case Storelocation::class: - return 'storelocations'; - case Supplier::class: - return 'suppliers'; - case Currency::class: - return 'currencies'; - case MeasurementUnit::class: - return 'measurement_units'; + + //If it is existing in index, we can skip the loop + if (isset(static::OBJ_PERM_MAP[$class_name])) { + return static::OBJ_PERM_MAP[$class_name]; } - //When the class is not supported by this class return null + + foreach (static::OBJ_PERM_MAP as $class => $ret) { + if (is_a($class_name, $class, true)) { + return $ret; + } + } + return null; }