Skip to content

Commit 3747ded

Browse files
authored
Merge pull request #60559 from nextcloud/backport/60558/stable33
[stable33] fix: improve check if external storage backend is local
2 parents 0c38333 + 25df337 commit 3747ded

7 files changed

Lines changed: 33 additions & 25 deletions

apps/files_external/lib/Controller/GlobalStoragesController.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace OCA\Files_External\Controller;
99

1010
use OCA\Files_External\NotFoundException;
11+
use OCA\Files_External\Service\BackendService;
1112
use OCA\Files_External\Service\GlobalStoragesService;
1213
use OCA\Files_External\Settings\Admin;
1314
use OCP\AppFramework\Http;
@@ -37,6 +38,7 @@ public function __construct(
3738
IUserSession $userSession,
3839
IGroupManager $groupManager,
3940
IConfig $config,
41+
BackendService $backendService,
4042
) {
4143
parent::__construct(
4244
$appName,
@@ -46,7 +48,8 @@ public function __construct(
4648
$logger,
4749
$userSession,
4850
$groupManager,
49-
$config
51+
$config,
52+
$backendService
5053
);
5154
}
5255

@@ -74,16 +77,6 @@ public function create(
7477
?array $applicableGroups,
7578
?int $priority,
7679
): DataResponse {
77-
$canCreateNewLocalStorage = $this->config->getSystemValue('files_external_allow_create_new_local', true);
78-
if (!$canCreateNewLocalStorage && $backend === 'local') {
79-
return new DataResponse(
80-
[
81-
'message' => $this->l10n->t('Forbidden to manage local mounts')
82-
],
83-
Http::STATUS_FORBIDDEN
84-
);
85-
}
86-
8780
$newStorage = $this->createStorage(
8881
$mountPoint,
8982
$backend,

apps/files_external/lib/Controller/StoragesController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
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\MountConfig;
1516
use OCA\Files_External\NotFoundException;
17+
use OCA\Files_External\Service\BackendService;
1618
use OCA\Files_External\Service\StoragesService;
1719
use OCP\AppFramework\Controller;
1820
use OCP\AppFramework\Http;
@@ -48,6 +50,7 @@ public function __construct(
4850
protected IUserSession $userSession,
4951
protected IGroupManager $groupManager,
5052
protected IConfig $config,
53+
private BackendService $backendService,
5154
) {
5255
parent::__construct($appName, $request);
5356
}
@@ -77,7 +80,7 @@ protected function createStorage(
7780
?int $priority = null,
7881
) {
7982
$canCreateNewLocalStorage = $this->config->getSystemValue('files_external_allow_create_new_local', true);
80-
if (!$canCreateNewLocalStorage && $backend === 'local') {
83+
if (!$canCreateNewLocalStorage && $this->backendService->getBackend($backend) instanceof Local) {
8184
return new DataResponse(
8285
[
8386
'message' => $this->l10n->t('Forbidden to manage local mounts')

apps/files_external/lib/Controller/UserGlobalStoragesController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException;
1515
use OCA\Files_External\Lib\StorageConfig;
1616
use OCA\Files_External\NotFoundException;
17+
use OCA\Files_External\Service\BackendService;
1718
use OCA\Files_External\Service\UserGlobalStoragesService;
1819
use OCP\AppFramework\Http;
1920
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
@@ -50,6 +51,7 @@ public function __construct(
5051
IUserSession $userSession,
5152
IGroupManager $groupManager,
5253
IConfig $config,
54+
BackendService $backendService,
5355
) {
5456
parent::__construct(
5557
$appName,
@@ -59,7 +61,8 @@ public function __construct(
5961
$logger,
6062
$userSession,
6163
$groupManager,
62-
$config
64+
$config,
65+
$backendService,
6366
);
6467
}
6568

apps/files_external/lib/Controller/UserStoragesController.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use OCA\Files_External\Lib\Backend\Backend;
1212
use OCA\Files_External\Lib\StorageConfig;
1313
use OCA\Files_External\NotFoundException;
14+
use OCA\Files_External\Service\BackendService;
1415
use OCA\Files_External\Service\UserStoragesService;
1516
use OCP\AppFramework\Http;
1617
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
@@ -40,6 +41,7 @@ public function __construct(
4041
IUserSession $userSession,
4142
IGroupManager $groupManager,
4243
IConfig $config,
44+
BackendService $backendService,
4345
) {
4446
parent::__construct(
4547
$appName,
@@ -49,7 +51,8 @@ public function __construct(
4951
$logger,
5052
$userSession,
5153
$groupManager,
52-
$config
54+
$config,
55+
$backendService,
5356
);
5457
}
5558

@@ -98,15 +101,6 @@ public function create(
98101
array $backendOptions,
99102
?array $mountOptions,
100103
): DataResponse {
101-
$canCreateNewLocalStorage = $this->config->getSystemValue('files_external_allow_create_new_local', true);
102-
if (!$canCreateNewLocalStorage && $backend === 'local') {
103-
return new DataResponse(
104-
[
105-
'message' => $this->l10n->t('Forbidden to manage local mounts')
106-
],
107-
Http::STATUS_FORBIDDEN
108-
);
109-
}
110104
$newStorage = $this->createStorage(
111105
$mountPoint,
112106
$backend,

apps/files_external/tests/Controller/GlobalStoragesControllerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ private function createController(bool $allowCreateLocal = true): GlobalStorages
4949
$this->createMock(LoggerInterface::class),
5050
$session,
5151
$this->createMock(IGroupManager::class),
52-
$config
52+
$config,
53+
$this->backendService,
5354
);
5455
}
5556

apps/files_external/tests/Controller/StoragesControllerTestCase.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
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\MountConfig;
1920
use OCA\Files_External\NotFoundException;
21+
use OCA\Files_External\Service\BackendService;
2022
use OCA\Files_External\Service\GlobalStoragesService;
2123
use OCA\Files_External\Service\UserStoragesService;
2224
use OCP\AppFramework\Http;
@@ -25,10 +27,21 @@
2527
abstract class StoragesControllerTestCase extends \Test\TestCase {
2628
protected GlobalStoragesController|UserStoragesController $controller;
2729
protected GlobalStoragesService|UserStoragesService|MockObject $service;
30+
protected BackendService|MockObject $backendService;
2831

2932
protected function setUp(): void {
3033
parent::setUp();
3134
MountConfig::$skipTest = true;
35+
36+
$this->backendService = $this->createMock(BackendService::class);
37+
$this->backendService->method('getBackend')
38+
->willReturnCallback(function ($identifier) {
39+
if ($identifier === 'local') {
40+
return $this->createMock(Local::class);
41+
} else {
42+
return $this->createMock(Backend::class);
43+
}
44+
});
3245
}
3346

3447
protected function tearDown(): void {

apps/files_external/tests/Controller/UserStoragesControllerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ private function createController(bool $allowCreateLocal = true) {
5858
$this->createMock(LoggerInterface::class),
5959
$session,
6060
$this->createMock(IGroupManager::class),
61-
$config
61+
$config,
62+
$this->backendService,
6263
);
6364
}
6465

0 commit comments

Comments
 (0)