Skip to content

Commit 988d822

Browse files
authored
Merge pull request #60544 from nextcloud/local-external-block-alias
fix: improve check if external storage backend is local
2 parents 4f1055b + 8e2ef53 commit 988d822

6 files changed

Lines changed: 17 additions & 22 deletions

File tree

apps/files_external/lib/Controller/GlobalStoragesController.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,6 @@ public function create(
7777
?array $applicableGroups,
7878
?int $priority,
7979
): DataResponse {
80-
$canCreateNewLocalStorage = $this->config->getSystemValue('files_external_allow_create_new_local', true);
81-
if (!$canCreateNewLocalStorage && $backend === 'local') {
82-
return new DataResponse(
83-
[
84-
'message' => $this->l10n->t('Forbidden to manage local mounts')
85-
],
86-
Http::STATUS_FORBIDDEN
87-
);
88-
}
89-
9080
$newStorage = $this->createStorage(
9181
$mountPoint,
9282
$backend,

apps/files_external/lib/Controller/StoragesController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use OCA\Files_External\Lib\Auth\AuthMechanism;
1111
use OCA\Files_External\Lib\Backend\Backend;
12+
use OCA\Files_External\Lib\Backend\Local;
1213
use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException;
1314
use OCA\Files_External\Lib\StorageConfig;
1415
use OCA\Files_External\NotFoundException;
@@ -78,7 +79,7 @@ protected function createStorage(
7879
?int $priority = null,
7980
) {
8081
$canCreateNewLocalStorage = $this->config->getSystemValue('files_external_allow_create_new_local', true);
81-
if (!$canCreateNewLocalStorage && $backend === 'local') {
82+
if (!$canCreateNewLocalStorage && $this->backendService->getBackend($backend) instanceof Local) {
8283
return new DataResponse(
8384
[
8485
'message' => $this->l10n->t('Forbidden to manage local mounts')

apps/files_external/lib/Controller/UserStoragesController.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,6 @@ public function create(
102102
array $backendOptions,
103103
?array $mountOptions,
104104
): DataResponse {
105-
$canCreateNewLocalStorage = $this->config->getSystemValue('files_external_allow_create_new_local', true);
106-
if (!$canCreateNewLocalStorage && $backend === 'local') {
107-
return new DataResponse(
108-
[
109-
'message' => $this->l10n->t('Forbidden to manage local mounts')
110-
],
111-
Http::STATUS_FORBIDDEN
112-
);
113-
}
114105
$newStorage = $this->createStorage(
115106
$mountPoint,
116107
$backend,

apps/files_external/tests/Controller/GlobalStoragesControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private function createController(bool $allowCreateLocal = true): GlobalStorages
5050
$session,
5151
$this->createMock(IGroupManager::class),
5252
$config,
53-
$this->createMock(BackendService::class),
53+
$this->backendService,
5454
);
5555
}
5656

apps/files_external/tests/Controller/StoragesControllerTestCase.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
use OCA\Files_External\Lib\Auth\AuthMechanism;
1414
use OCA\Files_External\Lib\Auth\NullMechanism;
1515
use OCA\Files_External\Lib\Backend\Backend;
16+
use OCA\Files_External\Lib\Backend\Local;
1617
use OCA\Files_External\Lib\Backend\SMB;
1718
use OCA\Files_External\Lib\StorageConfig;
1819
use OCA\Files_External\NotFoundException;
20+
use OCA\Files_External\Service\BackendService;
1921
use OCA\Files_External\Service\GlobalStoragesService;
2022
use OCA\Files_External\Service\UserStoragesService;
2123
use OCP\AppFramework\Http;
@@ -24,9 +26,20 @@
2426
abstract class StoragesControllerTestCase extends \Test\TestCase {
2527
protected GlobalStoragesController|UserStoragesController $controller;
2628
protected GlobalStoragesService|UserStoragesService|MockObject $service;
29+
protected BackendService|MockObject $backendService;
2730

2831
protected function setUp(): void {
2932
parent::setUp();
33+
34+
$this->backendService = $this->createMock(BackendService::class);
35+
$this->backendService->method('getBackend')
36+
->willReturnCallback(function ($identifier) {
37+
if ($identifier === 'local') {
38+
return $this->createMock(Local::class);
39+
} else {
40+
return $this->createMock(Backend::class);
41+
}
42+
});
3043
}
3144

3245
protected function tearDown(): void {

apps/files_external/tests/Controller/UserStoragesControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private function createController(bool $allowCreateLocal = true) {
5959
$session,
6060
$this->createMock(IGroupManager::class),
6161
$config,
62-
$this->createMock(BackendService::class),
62+
$this->backendService,
6363
);
6464
}
6565

0 commit comments

Comments
 (0)