|
28 | 28 | use Pimcore\Bundle\GenericDataIndexBundle\Permission\Workspace\DocumentWorkspace; |
29 | 29 | use Pimcore\Bundle\GenericDataIndexBundle\Permission\Workspace\WorkspaceInterface; |
30 | 30 | use Pimcore\Bundle\GenericDataIndexBundle\Service\EventServiceInterface; |
| 31 | +use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\LanguageServiceInterface; |
31 | 32 | use Pimcore\Bundle\GenericDataIndexBundle\Service\Workspace\WorkspaceServiceInterface; |
32 | 33 | use Pimcore\Model\User; |
33 | 34 |
|
|
36 | 37 | */ |
37 | 38 | final readonly class PermissionService implements PermissionServiceInterface |
38 | 39 | { |
| 40 | + private const SPECIAL_PERMISSIONS = [ |
| 41 | + 'localizedView', |
| 42 | + 'localizedEdit', |
| 43 | + ]; |
| 44 | + |
39 | 45 | public function __construct( |
40 | 46 | private EventServiceInterface $eventService, |
| 47 | + private LanguageServiceInterface $languageService, |
41 | 48 | private WorkspaceServiceInterface $workspaceService, |
42 | 49 | ) { |
43 | 50 | } |
@@ -102,14 +109,41 @@ public function checkWorkspacePermission( |
102 | 109 | return $this->getPermissionValue($permissions, $permission); |
103 | 110 | } |
104 | 111 |
|
105 | | - public function getPermissionValue(BasePermissions $permissions, string $permission): bool |
| 112 | + public function getPermissionValue( |
| 113 | + AssetPermissions|DocumentPermissions|DataObjectPermissions $permissions, |
| 114 | + string $permission, |
| 115 | + ?string $permissionValueKey = null |
| 116 | + ): bool { |
| 117 | + $getter = 'is' . ucfirst($permission); |
| 118 | + if (!method_exists($permissions, $getter)) { |
| 119 | + return false; |
| 120 | + } |
| 121 | + |
| 122 | + $value = $permissions->$getter(); |
| 123 | + if ($permissions instanceof DataObjectPermissions && !is_bool($value)) { |
| 124 | + return in_array( |
| 125 | + $permissionValueKey, |
| 126 | + $this->getSpecialPermissionValues($permissions, $permission), |
| 127 | + true |
| 128 | + ); |
| 129 | + } |
| 130 | + |
| 131 | + return $value; |
| 132 | + } |
| 133 | + |
| 134 | + public function getSpecialPermissionValues(DataObjectPermissions $permissions, string $permission): array |
106 | 135 | { |
| 136 | + if (!in_array($permission, self::SPECIAL_PERMISSIONS)) { |
| 137 | + return []; |
| 138 | + } |
| 139 | + |
107 | 140 | $getter = 'is' . ucfirst($permission); |
108 | | - if (method_exists($permissions, $getter)) { |
109 | | - return $permissions->$getter(); |
| 141 | + $permissionValues = $permissions->$getter(); |
| 142 | + if ($permissionValues === null) { |
| 143 | + return []; |
110 | 144 | } |
111 | 145 |
|
112 | | - return false; |
| 146 | + return explode(',', $permissionValues); |
113 | 147 | } |
114 | 148 |
|
115 | 149 | private function getPermissions( |
@@ -155,9 +189,15 @@ private function getAdminUserPermissions( |
155 | 189 |
|
156 | 190 | $properties = $permissions->getClassProperties(); |
157 | 191 | foreach ($properties as $property => $value) { |
| 192 | + $setter = 'set' . ucfirst($property); |
158 | 193 | if (is_bool($value)) { |
159 | | - $setter = 'set' . ucfirst($property); |
160 | 194 | $permissions->$setter(true); |
| 195 | + |
| 196 | + continue; |
| 197 | + } |
| 198 | + |
| 199 | + if (in_array($property, self::SPECIAL_PERMISSIONS, true)) { |
| 200 | + $permissions->$setter(implode(',', $this->languageService->getValidLanguages())); |
161 | 201 | } |
162 | 202 | } |
163 | 203 |
|
|
0 commit comments