diff --git a/apps/files_external/lib/Controller/GlobalStoragesController.php b/apps/files_external/lib/Controller/GlobalStoragesController.php index f350576362405..9712ed0874355 100644 --- a/apps/files_external/lib/Controller/GlobalStoragesController.php +++ b/apps/files_external/lib/Controller/GlobalStoragesController.php @@ -77,16 +77,6 @@ public function create( ?array $applicableGroups, ?int $priority, ): DataResponse { - $canCreateNewLocalStorage = $this->config->getSystemValue('files_external_allow_create_new_local', true); - if (!$canCreateNewLocalStorage && $backend === 'local') { - return new DataResponse( - [ - 'message' => $this->l10n->t('Forbidden to manage local mounts') - ], - Http::STATUS_FORBIDDEN - ); - } - $newStorage = $this->createStorage( $mountPoint, $backend, diff --git a/apps/files_external/lib/Controller/StoragesController.php b/apps/files_external/lib/Controller/StoragesController.php index 07afd0ceb44e2..e216539ceb0e3 100644 --- a/apps/files_external/lib/Controller/StoragesController.php +++ b/apps/files_external/lib/Controller/StoragesController.php @@ -9,6 +9,7 @@ use OCA\Files_External\Lib\Auth\AuthMechanism; use OCA\Files_External\Lib\Backend\Backend; +use OCA\Files_External\Lib\Backend\Local; use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException; use OCA\Files_External\Lib\StorageConfig; use OCA\Files_External\NotFoundException; @@ -78,7 +79,7 @@ protected function createStorage( ?int $priority = null, ) { $canCreateNewLocalStorage = $this->config->getSystemValue('files_external_allow_create_new_local', true); - if (!$canCreateNewLocalStorage && $backend === 'local') { + if (!$canCreateNewLocalStorage && $this->backendService->getBackend($backend) instanceof Local) { return new DataResponse( [ 'message' => $this->l10n->t('Forbidden to manage local mounts') diff --git a/apps/files_external/lib/Controller/UserStoragesController.php b/apps/files_external/lib/Controller/UserStoragesController.php index 2ed6d4d92d138..1cd2fa291869c 100644 --- a/apps/files_external/lib/Controller/UserStoragesController.php +++ b/apps/files_external/lib/Controller/UserStoragesController.php @@ -102,15 +102,6 @@ public function create( array $backendOptions, ?array $mountOptions, ): DataResponse { - $canCreateNewLocalStorage = $this->config->getSystemValue('files_external_allow_create_new_local', true); - if (!$canCreateNewLocalStorage && $backend === 'local') { - return new DataResponse( - [ - 'message' => $this->l10n->t('Forbidden to manage local mounts') - ], - Http::STATUS_FORBIDDEN - ); - } $newStorage = $this->createStorage( $mountPoint, $backend, diff --git a/apps/files_external/tests/Controller/GlobalStoragesControllerTest.php b/apps/files_external/tests/Controller/GlobalStoragesControllerTest.php index 7445c3e16d88d..21182010c9563 100644 --- a/apps/files_external/tests/Controller/GlobalStoragesControllerTest.php +++ b/apps/files_external/tests/Controller/GlobalStoragesControllerTest.php @@ -50,7 +50,7 @@ private function createController(bool $allowCreateLocal = true): GlobalStorages $session, $this->createMock(IGroupManager::class), $config, - $this->createMock(BackendService::class), + $this->backendService, ); } diff --git a/apps/files_external/tests/Controller/StoragesControllerTestCase.php b/apps/files_external/tests/Controller/StoragesControllerTestCase.php index 33c8eb26f5f82..2370588193f50 100644 --- a/apps/files_external/tests/Controller/StoragesControllerTestCase.php +++ b/apps/files_external/tests/Controller/StoragesControllerTestCase.php @@ -13,9 +13,11 @@ use OCA\Files_External\Lib\Auth\AuthMechanism; use OCA\Files_External\Lib\Auth\NullMechanism; use OCA\Files_External\Lib\Backend\Backend; +use OCA\Files_External\Lib\Backend\Local; use OCA\Files_External\Lib\Backend\SMB; use OCA\Files_External\Lib\StorageConfig; use OCA\Files_External\NotFoundException; +use OCA\Files_External\Service\BackendService; use OCA\Files_External\Service\GlobalStoragesService; use OCA\Files_External\Service\UserStoragesService; use OCP\AppFramework\Http; @@ -24,9 +26,20 @@ abstract class StoragesControllerTestCase extends \Test\TestCase { protected GlobalStoragesController|UserStoragesController $controller; protected GlobalStoragesService|UserStoragesService|MockObject $service; + protected BackendService|MockObject $backendService; protected function setUp(): void { parent::setUp(); + + $this->backendService = $this->createMock(BackendService::class); + $this->backendService->method('getBackend') + ->willReturnCallback(function ($identifier) { + if ($identifier === 'local') { + return $this->createMock(Local::class); + } else { + return $this->createMock(Backend::class); + } + }); } protected function tearDown(): void { diff --git a/apps/files_external/tests/Controller/UserStoragesControllerTest.php b/apps/files_external/tests/Controller/UserStoragesControllerTest.php index e2d5f301b122f..138b5e1225dd8 100644 --- a/apps/files_external/tests/Controller/UserStoragesControllerTest.php +++ b/apps/files_external/tests/Controller/UserStoragesControllerTest.php @@ -59,7 +59,7 @@ private function createController(bool $allowCreateLocal = true) { $session, $this->createMock(IGroupManager::class), $config, - $this->createMock(BackendService::class), + $this->backendService, ); }