@@ -27,152 +27,152 @@ |
||
27 | 27 | */ |
28 | 28 | class FilePermissionsAspect |
29 | 29 | { |
30 | - /** |
|
31 | - * Post-process the matcher object to respect the file storages. |
|
32 | - */ |
|
33 | - public function addFilePermissionsForFileStorages(Matcher $matcher, string $dataType): void |
|
34 | - { |
|
35 | - if ($dataType === 'sys_file' && $this->isPermissionNecessary()) { |
|
36 | - if ($this->isFolderConsidered()) { |
|
37 | - $folder = $this->getMediaModule()->getCurrentFolder(); |
|
38 | - |
|
39 | - if ($this->getMediaModule()->hasRecursiveSelection()) { |
|
40 | - // Only add like condition if needed. |
|
41 | - if ($folder->getStorage()->getRootLevelFolder() !== $folder) { |
|
42 | - $matcher->like('identifier', $folder->getIdentifier() . '%', $automaticallyAddWildCard = false); |
|
43 | - } |
|
44 | - } else { |
|
45 | - // Browse only currently |
|
46 | - $files = $this->getFileUids($folder); |
|
47 | - $matcher->in('uid', $files); |
|
48 | - } |
|
49 | - |
|
50 | - $matcher->equals('storage', $folder->getStorage()->getUid()); |
|
51 | - } else { |
|
52 | - $storage = $this->getMediaModule()->getCurrentStorage(); |
|
53 | - |
|
54 | - // Set the storage identifier only if the storage is on-line. |
|
55 | - $identifier = -1; |
|
56 | - if ($storage->isOnline()) { |
|
57 | - $identifier = $storage->getUid(); |
|
58 | - } |
|
59 | - |
|
60 | - if ($this->getModuleLoader()->hasPlugin() && !$this->getCurrentBackendUser()->isAdmin()) { |
|
61 | - $fileMounts = $this->getCurrentBackendUser()->getFileMountRecords(); |
|
62 | - $collectedFiles = []; |
|
63 | - foreach ($fileMounts as $fileMount) { |
|
64 | - $combinedIdentifier = $fileMount['base'] . ':' . $fileMount['path']; |
|
65 | - $folder = $this->getResourceFactory()->getFolderObjectFromCombinedIdentifier($combinedIdentifier); |
|
66 | - |
|
67 | - $files = $this->getFileUids($folder); |
|
68 | - $collectedFiles = array_merge($collectedFiles, $files); |
|
69 | - } |
|
70 | - |
|
71 | - $matcher->in('uid', $collectedFiles); |
|
72 | - } |
|
73 | - |
|
74 | - $matcher->equals('storage', $identifier); |
|
75 | - } |
|
76 | - } |
|
77 | - } |
|
78 | - |
|
79 | - protected function isPermissionNecessary(): bool |
|
80 | - { |
|
81 | - $isNecessary = true; |
|
82 | - |
|
83 | - $parameters = GeneralUtility::_GET(VidiModule::getParameterPrefix()); |
|
84 | - |
|
85 | - if ($parameters['controller'] === 'Clipboard' && ($parameters['action'] === 'show' || $parameters['action'] === 'flush')) { |
|
86 | - $isNecessary = false; |
|
87 | - } |
|
88 | - |
|
89 | - if ($parameters['controller'] === 'Content' && ($parameters['action'] === 'copyClipboard' || $parameters['action'] === 'moveClipboard')) { |
|
90 | - $isNecessary = false; |
|
91 | - } |
|
92 | - |
|
93 | - return $isNecessary; |
|
94 | - } |
|
95 | - |
|
96 | - protected function isFolderConsidered(): bool |
|
97 | - { |
|
98 | - return $this->getMediaModule()->hasFolderTree() && !$this->getModuleLoader()->hasPlugin(); |
|
99 | - } |
|
100 | - |
|
101 | - protected function getFileUids(Folder $folder): array |
|
102 | - { |
|
103 | - $files = []; |
|
104 | - foreach ($folder->getFiles() as $file) { |
|
105 | - $files[] = $file->getUid(); |
|
106 | - } |
|
107 | - return $files; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Post-process the constraints object to respect the file mounts. |
|
112 | - * |
|
113 | - * @param ConstraintInterface|null $constraints |
|
114 | - */ |
|
115 | - public function addFilePermissionsForFileMounts(Query $query, $constraints, ConstraintContainer $constraintContainer): void |
|
116 | - { |
|
117 | - if ($query->getType() === 'sys_file') { |
|
118 | - if (!$this->getCurrentBackendUser()->isAdmin()) { |
|
119 | - $this->respectFileMounts($query, $constraints, $constraintContainer); |
|
120 | - } |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * @param ConstraintInterface|null $constraints |
|
126 | - */ |
|
127 | - protected function respectFileMounts(Query $query, $constraints, ConstraintContainer $constraintContainer): array |
|
128 | - { |
|
129 | - // Get the file mount identifiers for the current Backend User. |
|
130 | - $fileMountRecords = $this->getCurrentBackendUser()->getFileMountRecords(); |
|
131 | - $constraintsRespectingFileMounts = []; |
|
132 | - foreach ((array)$fileMountRecords as $fileMountRecord) { |
|
133 | - if ($fileMountRecord['path']) { |
|
134 | - $constraintsRespectingFileMounts[] = $query->like( |
|
135 | - 'identifier', |
|
136 | - $fileMountRecord['path'] . '%' |
|
137 | - ); |
|
138 | - } |
|
139 | - } |
|
140 | - |
|
141 | - $logicalOrForRespectingFileMounts = $query->logicalOr($constraintsRespectingFileMounts); |
|
142 | - |
|
143 | - if ($constraints) { |
|
144 | - $constraints = $query->logicalAnd([$constraints, $logicalOrForRespectingFileMounts]); |
|
145 | - } else { |
|
146 | - $constraints = $logicalOrForRespectingFileMounts; |
|
147 | - } |
|
148 | - |
|
149 | - $constraintContainer->setConstraint($constraints); |
|
150 | - |
|
151 | - return [$query, $constraints, $constraintContainer]; |
|
152 | - } |
|
153 | - |
|
154 | - protected function getCurrentBackendUser(): BackendUserAuthentication |
|
155 | - { |
|
156 | - return $GLOBALS['BE_USER']; |
|
157 | - } |
|
158 | - |
|
159 | - protected function getDataService(): DataService |
|
160 | - { |
|
161 | - return GeneralUtility::makeInstance(DataService::class); |
|
162 | - } |
|
163 | - |
|
164 | - protected function getMediaModule(): MediaModule |
|
165 | - { |
|
166 | - return GeneralUtility::makeInstance(MediaModule::class); |
|
167 | - } |
|
168 | - |
|
169 | - protected function getModuleLoader(): ModuleLoader |
|
170 | - { |
|
171 | - return GeneralUtility::makeInstance(ModuleLoader::class); |
|
172 | - } |
|
173 | - |
|
174 | - protected function getResourceFactory(): ResourceFactory |
|
175 | - { |
|
176 | - return GeneralUtility::makeInstance(ResourceFactory::class); |
|
177 | - } |
|
30 | + /** |
|
31 | + * Post-process the matcher object to respect the file storages. |
|
32 | + */ |
|
33 | + public function addFilePermissionsForFileStorages(Matcher $matcher, string $dataType): void |
|
34 | + { |
|
35 | + if ($dataType === 'sys_file' && $this->isPermissionNecessary()) { |
|
36 | + if ($this->isFolderConsidered()) { |
|
37 | + $folder = $this->getMediaModule()->getCurrentFolder(); |
|
38 | + |
|
39 | + if ($this->getMediaModule()->hasRecursiveSelection()) { |
|
40 | + // Only add like condition if needed. |
|
41 | + if ($folder->getStorage()->getRootLevelFolder() !== $folder) { |
|
42 | + $matcher->like('identifier', $folder->getIdentifier() . '%', $automaticallyAddWildCard = false); |
|
43 | + } |
|
44 | + } else { |
|
45 | + // Browse only currently |
|
46 | + $files = $this->getFileUids($folder); |
|
47 | + $matcher->in('uid', $files); |
|
48 | + } |
|
49 | + |
|
50 | + $matcher->equals('storage', $folder->getStorage()->getUid()); |
|
51 | + } else { |
|
52 | + $storage = $this->getMediaModule()->getCurrentStorage(); |
|
53 | + |
|
54 | + // Set the storage identifier only if the storage is on-line. |
|
55 | + $identifier = -1; |
|
56 | + if ($storage->isOnline()) { |
|
57 | + $identifier = $storage->getUid(); |
|
58 | + } |
|
59 | + |
|
60 | + if ($this->getModuleLoader()->hasPlugin() && !$this->getCurrentBackendUser()->isAdmin()) { |
|
61 | + $fileMounts = $this->getCurrentBackendUser()->getFileMountRecords(); |
|
62 | + $collectedFiles = []; |
|
63 | + foreach ($fileMounts as $fileMount) { |
|
64 | + $combinedIdentifier = $fileMount['base'] . ':' . $fileMount['path']; |
|
65 | + $folder = $this->getResourceFactory()->getFolderObjectFromCombinedIdentifier($combinedIdentifier); |
|
66 | + |
|
67 | + $files = $this->getFileUids($folder); |
|
68 | + $collectedFiles = array_merge($collectedFiles, $files); |
|
69 | + } |
|
70 | + |
|
71 | + $matcher->in('uid', $collectedFiles); |
|
72 | + } |
|
73 | + |
|
74 | + $matcher->equals('storage', $identifier); |
|
75 | + } |
|
76 | + } |
|
77 | + } |
|
78 | + |
|
79 | + protected function isPermissionNecessary(): bool |
|
80 | + { |
|
81 | + $isNecessary = true; |
|
82 | + |
|
83 | + $parameters = GeneralUtility::_GET(VidiModule::getParameterPrefix()); |
|
84 | + |
|
85 | + if ($parameters['controller'] === 'Clipboard' && ($parameters['action'] === 'show' || $parameters['action'] === 'flush')) { |
|
86 | + $isNecessary = false; |
|
87 | + } |
|
88 | + |
|
89 | + if ($parameters['controller'] === 'Content' && ($parameters['action'] === 'copyClipboard' || $parameters['action'] === 'moveClipboard')) { |
|
90 | + $isNecessary = false; |
|
91 | + } |
|
92 | + |
|
93 | + return $isNecessary; |
|
94 | + } |
|
95 | + |
|
96 | + protected function isFolderConsidered(): bool |
|
97 | + { |
|
98 | + return $this->getMediaModule()->hasFolderTree() && !$this->getModuleLoader()->hasPlugin(); |
|
99 | + } |
|
100 | + |
|
101 | + protected function getFileUids(Folder $folder): array |
|
102 | + { |
|
103 | + $files = []; |
|
104 | + foreach ($folder->getFiles() as $file) { |
|
105 | + $files[] = $file->getUid(); |
|
106 | + } |
|
107 | + return $files; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Post-process the constraints object to respect the file mounts. |
|
112 | + * |
|
113 | + * @param ConstraintInterface|null $constraints |
|
114 | + */ |
|
115 | + public function addFilePermissionsForFileMounts(Query $query, $constraints, ConstraintContainer $constraintContainer): void |
|
116 | + { |
|
117 | + if ($query->getType() === 'sys_file') { |
|
118 | + if (!$this->getCurrentBackendUser()->isAdmin()) { |
|
119 | + $this->respectFileMounts($query, $constraints, $constraintContainer); |
|
120 | + } |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * @param ConstraintInterface|null $constraints |
|
126 | + */ |
|
127 | + protected function respectFileMounts(Query $query, $constraints, ConstraintContainer $constraintContainer): array |
|
128 | + { |
|
129 | + // Get the file mount identifiers for the current Backend User. |
|
130 | + $fileMountRecords = $this->getCurrentBackendUser()->getFileMountRecords(); |
|
131 | + $constraintsRespectingFileMounts = []; |
|
132 | + foreach ((array)$fileMountRecords as $fileMountRecord) { |
|
133 | + if ($fileMountRecord['path']) { |
|
134 | + $constraintsRespectingFileMounts[] = $query->like( |
|
135 | + 'identifier', |
|
136 | + $fileMountRecord['path'] . '%' |
|
137 | + ); |
|
138 | + } |
|
139 | + } |
|
140 | + |
|
141 | + $logicalOrForRespectingFileMounts = $query->logicalOr($constraintsRespectingFileMounts); |
|
142 | + |
|
143 | + if ($constraints) { |
|
144 | + $constraints = $query->logicalAnd([$constraints, $logicalOrForRespectingFileMounts]); |
|
145 | + } else { |
|
146 | + $constraints = $logicalOrForRespectingFileMounts; |
|
147 | + } |
|
148 | + |
|
149 | + $constraintContainer->setConstraint($constraints); |
|
150 | + |
|
151 | + return [$query, $constraints, $constraintContainer]; |
|
152 | + } |
|
153 | + |
|
154 | + protected function getCurrentBackendUser(): BackendUserAuthentication |
|
155 | + { |
|
156 | + return $GLOBALS['BE_USER']; |
|
157 | + } |
|
158 | + |
|
159 | + protected function getDataService(): DataService |
|
160 | + { |
|
161 | + return GeneralUtility::makeInstance(DataService::class); |
|
162 | + } |
|
163 | + |
|
164 | + protected function getMediaModule(): MediaModule |
|
165 | + { |
|
166 | + return GeneralUtility::makeInstance(MediaModule::class); |
|
167 | + } |
|
168 | + |
|
169 | + protected function getModuleLoader(): ModuleLoader |
|
170 | + { |
|
171 | + return GeneralUtility::makeInstance(ModuleLoader::class); |
|
172 | + } |
|
173 | + |
|
174 | + protected function getResourceFactory(): ResourceFactory |
|
175 | + { |
|
176 | + return GeneralUtility::makeInstance(ResourceFactory::class); |
|
177 | + } |
|
178 | 178 | } |