mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #60560 from nextcloud/backport/60558/stable32
[stable32] fix: improve check if external storage backend is local
This commit is contained in:
commit
44ae9e16a3
7 changed files with 33 additions and 25 deletions
|
|
@ -8,6 +8,7 @@
|
|||
namespace OCA\Files_External\Controller;
|
||||
|
||||
use OCA\Files_External\NotFoundException;
|
||||
use OCA\Files_External\Service\BackendService;
|
||||
use OCA\Files_External\Service\GlobalStoragesService;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired;
|
||||
|
|
@ -44,6 +45,7 @@ class GlobalStoragesController extends StoragesController {
|
|||
IUserSession $userSession,
|
||||
IGroupManager $groupManager,
|
||||
IConfig $config,
|
||||
BackendService $backendService,
|
||||
) {
|
||||
parent::__construct(
|
||||
$AppName,
|
||||
|
|
@ -53,7 +55,8 @@ class GlobalStoragesController extends StoragesController {
|
|||
$logger,
|
||||
$userSession,
|
||||
$groupManager,
|
||||
$config
|
||||
$config,
|
||||
$backendService
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -82,16 +85,6 @@ class GlobalStoragesController extends StoragesController {
|
|||
$applicableGroups,
|
||||
$priority,
|
||||
) {
|
||||
$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,10 +9,12 @@ 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\MountConfig;
|
||||
use OCA\Files_External\NotFoundException;
|
||||
use OCA\Files_External\Service\BackendService;
|
||||
use OCA\Files_External\Service\StoragesService;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http;
|
||||
|
|
@ -48,6 +50,7 @@ abstract class StoragesController extends Controller {
|
|||
protected IUserSession $userSession,
|
||||
protected IGroupManager $groupManager,
|
||||
protected IConfig $config,
|
||||
private BackendService $backendService,
|
||||
) {
|
||||
parent::__construct($AppName, $request);
|
||||
}
|
||||
|
|
@ -77,7 +80,7 @@ abstract class StoragesController extends Controller {
|
|||
$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')
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ use OCA\Files_External\Lib\Backend\Backend;
|
|||
use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException;
|
||||
use OCA\Files_External\Lib\StorageConfig;
|
||||
use OCA\Files_External\NotFoundException;
|
||||
use OCA\Files_External\Service\BackendService;
|
||||
use OCA\Files_External\Service\UserGlobalStoragesService;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
|
||||
|
|
@ -50,6 +51,7 @@ class UserGlobalStoragesController extends StoragesController {
|
|||
IUserSession $userSession,
|
||||
IGroupManager $groupManager,
|
||||
IConfig $config,
|
||||
BackendService $backendService,
|
||||
) {
|
||||
parent::__construct(
|
||||
$AppName,
|
||||
|
|
@ -59,7 +61,8 @@ class UserGlobalStoragesController extends StoragesController {
|
|||
$logger,
|
||||
$userSession,
|
||||
$groupManager,
|
||||
$config
|
||||
$config,
|
||||
$backendService,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ use OCA\Files_External\Lib\Auth\AuthMechanism;
|
|||
use OCA\Files_External\Lib\Backend\Backend;
|
||||
use OCA\Files_External\Lib\StorageConfig;
|
||||
use OCA\Files_External\NotFoundException;
|
||||
use OCA\Files_External\Service\BackendService;
|
||||
use OCA\Files_External\Service\UserStoragesService;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
|
||||
|
|
@ -47,6 +48,7 @@ class UserStoragesController extends StoragesController {
|
|||
IUserSession $userSession,
|
||||
IGroupManager $groupManager,
|
||||
IConfig $config,
|
||||
BackendService $backendService,
|
||||
) {
|
||||
parent::__construct(
|
||||
$AppName,
|
||||
|
|
@ -56,7 +58,8 @@ class UserStoragesController extends StoragesController {
|
|||
$logger,
|
||||
$userSession,
|
||||
$groupManager,
|
||||
$config
|
||||
$config,
|
||||
$backendService,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -109,15 +112,6 @@ class UserStoragesController extends StoragesController {
|
|||
$backendOptions,
|
||||
$mountOptions,
|
||||
) {
|
||||
$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,
|
||||
|
|
|
|||
|
|
@ -49,7 +49,8 @@ class GlobalStoragesControllerTest extends StoragesControllerTestCase {
|
|||
$this->createMock(LoggerInterface::class),
|
||||
$session,
|
||||
$this->createMock(IGroupManager::class),
|
||||
$config
|
||||
$config,
|
||||
$this->backendService,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,10 +13,12 @@ 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\MountConfig;
|
||||
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;
|
||||
|
|
@ -25,10 +27,21 @@ 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();
|
||||
MountConfig::$skipTest = true;
|
||||
|
||||
$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 {
|
||||
|
|
|
|||
|
|
@ -58,7 +58,8 @@ class UserStoragesControllerTest extends StoragesControllerTestCase {
|
|||
$this->createMock(LoggerInterface::class),
|
||||
$session,
|
||||
$this->createMock(IGroupManager::class),
|
||||
$config
|
||||
$config,
|
||||
$this->backendService,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue