diff --git a/controllers/ApiController.php b/controllers/ApiController.php index d4c55d3..44491c1 100644 --- a/controllers/ApiController.php +++ b/controllers/ApiController.php @@ -723,19 +723,19 @@ public function actionSearch($q, $limit = '') foreach ($query->all() as $item) { // check read permissions or is folder - if (!$fileSystem->grantAccess($item['path'], - Filefly::ACCESS_READ) || $fileSystem->get($item['path'])->isDir()) { - continue; - } - try { - $item['id'] = $item['path']; - $item['mime'] = ''; - $result[] = $item; + if (!$fileSystem->grantAccess($item['path'], + Filefly::ACCESS_READ) || $fileSystem->get($item['path'])->isDir()) { + continue; + } } catch (FileNotFoundException $e) { \Yii::warning($e->getMessage(), __METHOD__); continue; } + + $item['id'] = $item['path']; + $item['mime'] = ''; + $result[] = $item; } return $this->asJson($result); diff --git a/messages/de.json b/messages/de.json index f1100d9..fe230ce 100644 --- a/messages/de.json +++ b/messages/de.json @@ -19,7 +19,7 @@ "compression_failed": "Compression failed", "archive_opening_failed": "Could not open archive, it is either corrupted or unsupported", "extraction_failed": "Extraction failed", - "upload_failed": "Upload filed", + "upload_failed": "Upload failed", "recycling_failed": "An error occured during the filesystem recycling", "permission_edit_denied" : "You are not allowed to edit this file", "permission_upload_denied" : "You are not allowed to upload files to this directory", diff --git a/messages/en.json b/messages/en.json index 500c043..f4798c9 100644 --- a/messages/en.json +++ b/messages/en.json @@ -19,7 +19,7 @@ "compression_failed": "Compression failed", "archive_opening_failed": "Could not open archive, it is either corrupted or unsupported", "extraction_failed": "Extraction failed", - "upload_failed": "Upload filed", + "upload_failed": "Upload failed", "recycling_failed": "An error occured during the filesystem recycling", "permission_edit_denied" : "You are not allowed to edit this file", "permission_upload_denied" : "You are not allowed to upload files to this directory", diff --git a/models/FileflyHashmap.php b/models/FileflyHashmap.php index 4a8fc26..8ce0691 100644 --- a/models/FileflyHashmap.php +++ b/models/FileflyHashmap.php @@ -63,8 +63,22 @@ public static function accessColumnAttributes() */ public static function accessDefaults() { - $currentModule = Yii::$app->controller->module->id; - return \Yii::$app->getModule($currentModule)->defaultPermissions; + $currentModule = isset(Yii::$app->loadedModules[Module::class]) ? Yii::$app->loadedModules[Module::class] : null; + + if (isset($currentModule->defaultPermissions)) + return $currentModule->defaultPermissions; + + $currentModule = Yii::$app->getModule(Yii::$app->controller->module->id); + + if (isset($currentModule->defaultPermissions)) + return $currentModule->defaultPermissions; + + $currentModule = Yii::$app->getModule(Module::NAME); + + if (isset($currentModule->defaultPermissions)) + return $currentModule->defaultPermissions; + + return Module::getInstance()->defaultPermissions; } /** diff --git a/plugins/AccessPlugin.php b/plugins/AccessPlugin.php index c3e920a..ffd8ca3 100644 --- a/plugins/AccessPlugin.php +++ b/plugins/AccessPlugin.php @@ -66,6 +66,10 @@ public function setFilesystem(FilesystemInterface $filesystem) */ protected function normalize($path) { + if(empty($path)) { + return $path; + } + return '/' . ltrim($path, '/'); } } diff --git a/plugins/SetAccess.php b/plugins/SetAccess.php index 9571e70..64252b8 100644 --- a/plugins/SetAccess.php +++ b/plugins/SetAccess.php @@ -46,7 +46,7 @@ public function handle($oldItemPath = null, $newItemPath = null) ->where( [ 'component' => $this->component, - 'path' => $oldItemPath, + 'path' => $oldItemPath, ] ) ->one(); @@ -68,12 +68,12 @@ public function handle($oldItemPath = null, $newItemPath = null) $defaultPermissions = FileflyHashmap::accessDefaults(); $newHash = new FileflyHashmap( [ - 'component' => $this->component, - 'type' => $type, - 'path' => $oldItemPath, - 'size' => $size, + 'component' => $this->component, + 'type' => $type, + 'path' => $oldItemPath, + 'size' => $size, 'access_owner' => \Yii::$app->user->id, - Module::ACCESS_READ => $defaultPermissions[Module::ACCESS_READ], + Module::ACCESS_READ => $defaultPermissions[Module::ACCESS_READ], Module::ACCESS_UPDATE => $defaultPermissions[Module::ACCESS_UPDATE], Module::ACCESS_DELETE => $defaultPermissions[Module::ACCESS_DELETE], ] @@ -97,6 +97,10 @@ public function handle($oldItemPath = null, $newItemPath = null) */ private function updateRecursive($oldItemPath, $newItemPath) { + if (empty($newItemPath)) { + return true; + } + $find = $oldItemPath . '%'; $items = FileflyHashmap::find()