mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-30 13:34:28 +02:00
Fixed a wrong AccessDenied exception related to data structures
StructureVoter now can work with ProxyClasses (child classes of "our" classes)
This commit is contained in:
parent
e12ecf774f
commit
da83314d69
1 changed files with 24 additions and 20 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue