Skip to content

Commit bea70ee

Browse files
[BUGFIX] Split target and existing dirs to avoid user permissions error
Currently the root dir was always specified as target dir to create the new dirs into. When using filemounts the user does not always have access to the root dir. Specifying the target dir more precise the target dir can be into a filemount and the user will have access to that dir. In this case no exception will be thrown.
1 parent dcc2aec commit bea70ee

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

Classes/EventListener/Backend/DefaultUploadFolder.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,29 @@ private function createUploadFolder($combinedFolderIdentifier): ?Folder
7979
return null;
8080
}
8181
$parts = explode(':', $combinedFolderIdentifier);
82+
// Split $combinedFolderIdentifier into target and data(folders to be created) due possible permissions mismatch.
83+
// When an user has access to a subdir by filemount but not access to the full storage, the root target (/) is checked for permission.
84+
// Therefore, an exception will be thrown. Checking and specifying the target more precise this will be avoid.
85+
$dirs = explode('/', trim($parts[1], '/'));
86+
$lastItem = array_pop($dirs);
87+
$nonExistingDirs = [];
88+
while ($lastItem !== null) {
89+
$nonExistingDirs = [$lastItem, ...$nonExistingDirs];
90+
try {
91+
GeneralUtility::makeInstance(ResourceFactory::class)
92+
->getFolderObjectFromCombinedIdentifier(
93+
$parts[0] . ':/' . implode('/', $dirs)
94+
);
95+
break;
96+
} catch (FolderDoesNotExistException $folderDoesNotExistException) {
97+
}
98+
$lastItem = array_pop($dirs);
99+
}
82100
$data = [
83101
'newfolder' => [
84102
0 => [
85-
'data' => $parts[1],
86-
'target' => $parts[0] . ':/',
103+
'data' => implode('/', $nonExistingDirs),
104+
'target' => $parts[0] . ':/' . implode('/', $dirs),
87105
],
88106
],
89107
];

0 commit comments

Comments
 (0)