From b7c957683322c4bef38e3e30b250d62b0c506fc5 Mon Sep 17 00:00:00 2001 From: Manuel Schmid <9307310+mashb1t@users.noreply.github.com> Date: Mon, 5 Dec 2022 10:47:06 +0100 Subject: [PATCH 01/10] refactor: adjust composer vendor to oddity-agency --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 24c2cd6..c850c24 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "dmstr/yii2-filefly-module", + "name": "oddity-agency/yii2-filefly-module", "description": "FlySystem API for Filemanager", "type": "yii2-extension", "keywords": ["yii2","extension"], From 082f80caf8f4648262a3ae5f530eae1c66fe95eb Mon Sep 17 00:00:00 2001 From: boehmi1988 Date: Mon, 5 Dec 2022 10:09:19 +0000 Subject: [PATCH 02/10] refactor: revert composer vendor to dmstr --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c850c24..24c2cd6 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "oddity-agency/yii2-filefly-module", + "name": "dmstr/yii2-filefly-module", "description": "FlySystem API for Filemanager", "type": "yii2-extension", "keywords": ["yii2","extension"], From 41334305a89ff778eee69a720c1e8195b00daf51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Bo=CC=88hm?= Date: Mon, 5 Dec 2022 11:05:58 +0000 Subject: [PATCH 03/10] fix: fix exception handling --- controllers/ApiController.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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); From e835bea91f4af69f3ab260450897e791ce42179d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Bo=CC=88hm?= Date: Mon, 5 Dec 2022 11:06:10 +0000 Subject: [PATCH 04/10] fix: fix typo --- messages/de.json | 2 +- messages/en.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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", From 7cf7a0ef093a51e42a42d3537ec0a9fb7ef4e3c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Bo=CC=88hm?= Date: Mon, 5 Dec 2022 11:07:03 +0000 Subject: [PATCH 05/10] fix: add empty check to avoid ltrim error on null param --- plugins/AccessPlugin.php | 4 ++++ 1 file changed, 4 insertions(+) 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, '/'); } } From 8b8e76e1586b717ecee7868ddd68dc80a28680c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Bo=CC=88hm?= Date: Mon, 5 Dec 2022 11:07:31 +0000 Subject: [PATCH 06/10] fix: add empty check to avoid str_replace error on null param --- plugins/SetAccess.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) 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() From 14c3e6f46fc221ffeef96feade2af66c5c462de9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Bo=CC=88hm?= Date: Fri, 9 Dec 2022 12:30:49 +0000 Subject: [PATCH 07/10] feat(): make static FileflyHashmap::accessDefaults work from every context --- models/FileflyHashmap.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/models/FileflyHashmap.php b/models/FileflyHashmap.php index 4a8fc26..c35aea8 100644 --- a/models/FileflyHashmap.php +++ b/models/FileflyHashmap.php @@ -63,8 +63,7 @@ public static function accessColumnAttributes() */ public static function accessDefaults() { - $currentModule = Yii::$app->controller->module->id; - return \Yii::$app->getModule($currentModule)->defaultPermissions; + return \Yii::$app->getModule(Module::NAME)->defaultPermissions; } /** From cad1f1d3b9d11ccb90463e8eedae0f45fe277209 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Bo=CC=88hm?= Date: Mon, 12 Dec 2022 10:11:31 +0000 Subject: [PATCH 08/10] feat: get $accessDefaults from hrzg\filefly\Module instance --- models/FileflyHashmap.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/models/FileflyHashmap.php b/models/FileflyHashmap.php index c35aea8..83840a7 100644 --- a/models/FileflyHashmap.php +++ b/models/FileflyHashmap.php @@ -63,7 +63,22 @@ public static function accessColumnAttributes() */ public static function accessDefaults() { - return \Yii::$app->getModule(Module::NAME)->defaultPermissions; + $currentModule = Yii::$app->loadedModules[Module::class]; + + 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; } /** From a3a36ef256ff7d2b42a5aabbb8b054b0287773ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Bo=CC=88hm?= Date: Thu, 2 Feb 2023 14:39:47 +0000 Subject: [PATCH 09/10] loadedModules nullcheck --- models/FileflyHashmap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/FileflyHashmap.php b/models/FileflyHashmap.php index 83840a7..3ad2adb 100644 --- a/models/FileflyHashmap.php +++ b/models/FileflyHashmap.php @@ -63,7 +63,7 @@ public static function accessColumnAttributes() */ public static function accessDefaults() { - $currentModule = Yii::$app->loadedModules[Module::class]; + $currentModule = Yii::$app->loadedModules[Module::class] ?? null; if (isset($currentModule->defaultPermissions)) return $currentModule->defaultPermissions; From 3e68232f6f808852809e640483171260d8ed9eca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Bo=CC=88hm?= Date: Tue, 14 Mar 2023 11:43:31 +0100 Subject: [PATCH 10/10] fix(): current module array index --- models/FileflyHashmap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/FileflyHashmap.php b/models/FileflyHashmap.php index 3ad2adb..8ce0691 100644 --- a/models/FileflyHashmap.php +++ b/models/FileflyHashmap.php @@ -63,7 +63,7 @@ public static function accessColumnAttributes() */ public static function accessDefaults() { - $currentModule = Yii::$app->loadedModules[Module::class] ?? null; + $currentModule = isset(Yii::$app->loadedModules[Module::class]) ? Yii::$app->loadedModules[Module::class] : null; if (isset($currentModule->defaultPermissions)) return $currentModule->defaultPermissions;