Skip to content

Commit 0e0951b

Browse files
authored
Merge pull request #60563 from nextcloud/backport/60558/stable29
[stable29] [stable34] fix: improve check if external storage backend is local
2 parents c8d9581 + 41a95d7 commit 0e0951b

7 files changed

Lines changed: 40 additions & 29 deletions

apps/files_external/lib/Controller/GlobalStoragesController.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
namespace OCA\Files_External\Controller;
2929

3030
use OCA\Files_External\NotFoundException;
31+
use OCA\Files_External\Service\BackendService;
3132
use OCA\Files_External\Service\GlobalStoragesService;
3233
use OCP\AppFramework\Http;
3334
use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired;
@@ -63,7 +64,8 @@ public function __construct(
6364
LoggerInterface $logger,
6465
IUserSession $userSession,
6566
IGroupManager $groupManager,
66-
IConfig $config
67+
IConfig $config,
68+
BackendService $backendService
6769
) {
6870
parent::__construct(
6971
$AppName,
@@ -73,7 +75,8 @@ public function __construct(
7375
$logger,
7476
$userSession,
7577
$groupManager,
76-
$config
78+
$config,
79+
$backendService
7780
);
7881
}
7982

@@ -102,16 +105,6 @@ public function create(
102105
$applicableGroups,
103106
$priority
104107
) {
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-
}
114-
115108
$newStorage = $this->createStorage(
116109
$mountPoint,
117110
$backend,

apps/files_external/lib/Controller/StoragesController.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@
3030

3131
use OCA\Files_External\Lib\Auth\AuthMechanism;
3232
use OCA\Files_External\Lib\Backend\Backend;
33+
use OCA\Files_External\Lib\Backend\Local;
3334
use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException;
3435
use OCA\Files_External\Lib\StorageConfig;
3536
use OCA\Files_External\NotFoundException;
37+
use OCA\Files_External\Service\BackendService;
3638
use OCA\Files_External\Service\StoragesService;
3739
use OCP\AppFramework\Controller;
3840
use OCP\AppFramework\Http;
@@ -67,7 +69,8 @@ public function __construct(
6769
protected LoggerInterface $logger,
6870
protected IUserSession $userSession,
6971
protected IGroupManager $groupManager,
70-
protected IConfig $config
72+
protected IConfig $config,
73+
private BackendService $backendService
7174
) {
7275
parent::__construct($AppName, $request);
7376
}
@@ -97,7 +100,7 @@ protected function createStorage(
97100
$priority = null
98101
) {
99102
$canCreateNewLocalStorage = $this->config->getSystemValue('files_external_allow_create_new_local', true);
100-
if (!$canCreateNewLocalStorage && $backend === 'local') {
103+
if (!$canCreateNewLocalStorage && $this->backendService->getBackend($backend) instanceof Local) {
101104
return new DataResponse(
102105
[
103106
'message' => $this->l10n->t('Forbidden to manage local mounts')

apps/files_external/lib/Controller/UserGlobalStoragesController.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException;
3434
use OCA\Files_External\Lib\StorageConfig;
3535
use OCA\Files_External\NotFoundException;
36+
use OCA\Files_External\Service\BackendService;
3637
use OCA\Files_External\Service\UserGlobalStoragesService;
3738
use OCP\AppFramework\Http;
3839
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
@@ -68,7 +69,8 @@ public function __construct(
6869
LoggerInterface $logger,
6970
IUserSession $userSession,
7071
IGroupManager $groupManager,
71-
IConfig $config
72+
IConfig $config,
73+
BackendService $backendService
7274
) {
7375
parent::__construct(
7476
$AppName,
@@ -78,7 +80,8 @@ public function __construct(
7880
$logger,
7981
$userSession,
8082
$groupManager,
81-
$config
83+
$config,
84+
$backendService,
8285
);
8386
}
8487

apps/files_external/lib/Controller/UserStoragesController.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use OCA\Files_External\Lib\Backend\Backend;
3333
use OCA\Files_External\Lib\StorageConfig;
3434
use OCA\Files_External\NotFoundException;
35+
use OCA\Files_External\Service\BackendService;
3536
use OCA\Files_External\Service\UserStoragesService;
3637
use OCP\AppFramework\Http;
3738
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
@@ -67,7 +68,8 @@ public function __construct(
6768
LoggerInterface $logger,
6869
IUserSession $userSession,
6970
IGroupManager $groupManager,
70-
IConfig $config
71+
IConfig $config,
72+
BackendService $backendService
7173
) {
7274
parent::__construct(
7375
$AppName,
@@ -77,7 +79,8 @@ public function __construct(
7779
$logger,
7880
$userSession,
7981
$groupManager,
80-
$config
82+
$config,
83+
$backendService,
8184
);
8285
}
8386

@@ -132,15 +135,6 @@ public function create(
132135
$backendOptions,
133136
$mountOptions
134137
) {
135-
$canCreateNewLocalStorage = $this->config->getSystemValue('files_external_allow_create_new_local', true);
136-
if (!$canCreateNewLocalStorage && $backend === 'local') {
137-
return new DataResponse(
138-
[
139-
'message' => $this->l10n->t('Forbidden to manage local mounts')
140-
],
141-
Http::STATUS_FORBIDDEN
142-
);
143-
}
144138
$newStorage = $this->createStorage(
145139
$mountPoint,
146140
$backend,

apps/files_external/tests/Controller/GlobalStoragesControllerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ private function createController($allowCreateLocal = true) {
6868
$this->createMock(LoggerInterface::class),
6969
$session,
7070
$this->createMock(IGroupManager::class),
71-
$config
71+
$config,
72+
$this->backendService,
7273
);
7374
}
7475

apps/files_external/tests/Controller/StoragesControllerTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131
use OCA\Files_External\Lib\Auth\AuthMechanism;
3232
use OCA\Files_External\Lib\Backend\Backend;
3333

34+
use OCA\Files_External\Lib\Backend\Local;
3435
use OCA\Files_External\Lib\StorageConfig;
3536
use OCA\Files_External\NotFoundException;
37+
use OCA\Files_External\Service\BackendService;
3638
use OCA\Files_External\Service\GlobalStoragesService;
3739
use OCA\Files_External\Service\UserStoragesService;
3840
use OCP\AppFramework\Http;
@@ -49,9 +51,23 @@ abstract class StoragesControllerTest extends \Test\TestCase {
4951
* @var GlobalStoragesService|UserStoragesService|MockObject
5052
*/
5153
protected $service;
54+
/**
55+
* @var BackendService|MockObject
56+
*/
57+
protected $backendService;
5258

5359
protected function setUp(): void {
5460
\OCA\Files_External\MountConfig::$skipTest = true;
61+
62+
$this->backendService = $this->createMock(BackendService::class);
63+
$this->backendService->method('getBackend')
64+
->willReturnCallback(function ($identifier) {
65+
if ($identifier === 'local') {
66+
return $this->createMock(Local::class);
67+
} else {
68+
return $this->createMock(Backend::class);
69+
}
70+
});
5571
}
5672

5773
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
@@ -76,7 +76,8 @@ private function createController($allowCreateLocal = true) {
7676
$this->createMock(LoggerInterface::class),
7777
$session,
7878
$this->createMock(IGroupManager::class),
79-
$config
79+
$config,
80+
$this->backendService,
8081
);
8182
}
8283

0 commit comments

Comments
 (0)