mirror of
https://github.com/nextcloud/server.git
synced 2026-06-11 01:30:50 -04:00
Merge pull request #60544 from nextcloud/local-external-block-alias
fix: improve check if external storage backend is local
This commit is contained in:
commit
988d8225be
6 changed files with 17 additions and 22 deletions
|
|
@ -77,16 +77,6 @@ class GlobalStoragesController extends StoragesController {
|
|||
?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,
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ namespace OCA\Files_External\Controller;
|
|||
|
||||
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 @@ abstract class StoragesController extends Controller {
|
|||
?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')
|
||||
|
|
|
|||
|
|
@ -102,15 +102,6 @@ class UserStoragesController extends StoragesController {
|
|||
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,
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ class GlobalStoragesControllerTest extends StoragesControllerTestCase {
|
|||
$session,
|
||||
$this->createMock(IGroupManager::class),
|
||||
$config,
|
||||
$this->createMock(BackendService::class),
|
||||
$this->backendService,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,9 +13,11 @@ use OCA\Files_External\Controller\UserStoragesController;
|
|||
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 @@ use PHPUnit\Framework\MockObject\MockObject;
|
|||
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 {
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ class UserStoragesControllerTest extends StoragesControllerTestCase {
|
|||
$session,
|
||||
$this->createMock(IGroupManager::class),
|
||||
$config,
|
||||
$this->createMock(BackendService::class),
|
||||
$this->backendService,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue