Skip to content

Commit 1ada60e

Browse files
authored
Merge pull request #62076 from nextcloud/backport/62072/stable26
[stable26] fix: improve check if external storage backend is local
2 parents 89b8844 + f992595 commit 1ada60e

7 files changed

Lines changed: 46 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\DataResponse;
@@ -62,7 +63,8 @@ public function __construct(
6263
ILogger $logger,
6364
IUserSession $userSession,
6465
IGroupManager $groupManager,
65-
IConfig $config
66+
IConfig $config,
67+
BackendService $backendService
6668
) {
6769
parent::__construct(
6870
$AppName,
@@ -72,7 +74,8 @@ public function __construct(
7274
$logger,
7375
$userSession,
7476
$groupManager,
75-
$config
77+
$config,
78+
$backendService
7679
);
7780
}
7881

@@ -100,16 +103,6 @@ public function create(
100103
$applicableGroups,
101104
$priority
102105
) {
103-
$canCreateNewLocalStorage = $this->config->getSystemValue('files_external_allow_create_new_local', true);
104-
if (!$canCreateNewLocalStorage && $backend === 'local') {
105-
return new DataResponse(
106-
[
107-
'message' => $this->l10n->t('Forbidden to manage local mounts')
108-
],
109-
Http::STATUS_FORBIDDEN
110-
);
111-
}
112-
113106
$newStorage = $this->createStorage(
114107
$mountPoint,
115108
$backend,

apps/files_external/lib/Controller/StoragesController.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@
3131
use OCA\Files_External\Lib\Auth\AuthMechanism;
3232
use OCA\Files_External\Lib\Backend\Backend;
3333
use OCA\Files_External\Lib\DefinitionParameter;
34+
use OCA\Files_External\Lib\Backend\Local;
3435
use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException;
3536
use OCA\Files_External\Lib\StorageConfig;
3637
use OCA\Files_External\NotFoundException;
38+
use OCA\Files_External\Service\BackendService;
3739
use OCA\Files_External\Service\StoragesService;
3840
use OCP\AppFramework\Controller;
3941
use OCP\AppFramework\Http;
@@ -85,6 +87,11 @@ abstract class StoragesController extends Controller {
8587
*/
8688
protected $config;
8789

90+
/**
91+
* @var BackendService
92+
*/
93+
protected $backendService;
94+
8895
/**
8996
* Creates a new storages controller.
9097
*
@@ -102,7 +109,8 @@ public function __construct(
102109
ILogger $logger,
103110
IUserSession $userSession,
104111
IGroupManager $groupManager,
105-
IConfig $config
112+
IConfig $config,
113+
BackendService $backendService
106114
) {
107115
parent::__construct($AppName, $request);
108116
$this->l10n = $l10n;
@@ -111,6 +119,7 @@ public function __construct(
111119
$this->userSession = $userSession;
112120
$this->groupManager = $groupManager;
113121
$this->config = $config;
122+
$this->backendService = $backendService;
114123
}
115124

116125
/**
@@ -138,7 +147,7 @@ protected function createStorage(
138147
$priority = null
139148
) {
140149
$canCreateNewLocalStorage = $this->config->getSystemValue('files_external_allow_create_new_local', true);
141-
if (!$canCreateNewLocalStorage && $backend === 'local') {
150+
if (!$canCreateNewLocalStorage && $this->backendService->getBackend($backend) instanceof Local) {
142151
return new DataResponse(
143152
[
144153
'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\DataResponse;
@@ -66,7 +67,8 @@ public function __construct(
6667
ILogger $logger,
6768
IUserSession $userSession,
6869
IGroupManager $groupManager,
69-
IConfig $config
70+
IConfig $config,
71+
BackendService $backendService
7072
) {
7173
parent::__construct(
7274
$AppName,
@@ -76,7 +78,8 @@ public function __construct(
7678
$logger,
7779
$userSession,
7880
$groupManager,
79-
$config
81+
$config,
82+
$backendService,
8083
);
8184
}
8285

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\DataResponse;
@@ -65,7 +66,8 @@ public function __construct(
6566
ILogger $logger,
6667
IUserSession $userSession,
6768
IGroupManager $groupManager,
68-
IConfig $config
69+
IConfig $config,
70+
BackendService $backendService
6971
) {
7072
parent::__construct(
7173
$AppName,
@@ -75,7 +77,8 @@ public function __construct(
7577
$logger,
7678
$userSession,
7779
$groupManager,
78-
$config
80+
$config,
81+
$backendService,
7982
);
8083
}
8184

@@ -130,15 +133,6 @@ public function create(
130133
$backendOptions,
131134
$mountOptions
132135
) {
133-
$canCreateNewLocalStorage = $this->config->getSystemValue('files_external_allow_create_new_local', true);
134-
if (!$canCreateNewLocalStorage && $backend === 'local') {
135-
return new DataResponse(
136-
[
137-
'message' => $this->l10n->t('Forbidden to manage local mounts')
138-
],
139-
Http::STATUS_FORBIDDEN
140-
);
141-
}
142136
$newStorage = $this->createStorage(
143137
$mountPoint,
144138
$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(ILogger::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 OCP\AppFramework\Http;
3840

@@ -47,9 +49,23 @@ abstract class StoragesControllerTest extends \Test\TestCase {
4749
* @var GlobalStoragesService
4850
*/
4951
protected $service;
52+
/**
53+
* @var BackendService|MockObject
54+
*/
55+
protected $backendService;
5056

5157
protected function setUp(): void {
5258
\OCA\Files_External\MountConfig::$skipTest = true;
59+
60+
$this->backendService = $this->createMock(BackendService::class);
61+
$this->backendService->method('getBackend')
62+
->willReturnCallback(function ($identifier) {
63+
if ($identifier === 'local') {
64+
return $this->createMock(Local::class);
65+
} else {
66+
return $this->createMock(Backend::class);
67+
}
68+
});
5369
}
5470

5571
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(ILogger::class),
7777
$session,
7878
$this->createMock(IGroupManager::class),
79-
$config
79+
$config,
80+
$this->backendService,
8081
);
8182
}
8283

0 commit comments

Comments
 (0)