mirror of
https://github.com/nextcloud/server.git
synced 2026-06-10 01:00:50 -04:00
Merge pull request #60561 from nextcloud/backport/60558/stable31
[stable31] fix: improve check if external storage backend is local
This commit is contained in:
commit
b70b80a5ce
7 changed files with 36 additions and 25 deletions
|
|
@ -7,6 +7,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;
|
||||
|
|
@ -43,6 +44,7 @@ class GlobalStoragesController extends StoragesController {
|
|||
IUserSession $userSession,
|
||||
IGroupManager $groupManager,
|
||||
IConfig $config,
|
||||
BackendService $backendService,
|
||||
) {
|
||||
parent::__construct(
|
||||
$AppName,
|
||||
|
|
@ -52,7 +54,8 @@ class GlobalStoragesController extends StoragesController {
|
|||
$logger,
|
||||
$userSession,
|
||||
$groupManager,
|
||||
$config
|
||||
$config,
|
||||
$backendService
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -81,16 +84,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,
|
||||
|
|
|
|||
|
|
@ -8,10 +8,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;
|
||||
|
|
@ -47,6 +49,7 @@ abstract class StoragesController extends Controller {
|
|||
protected IUserSession $userSession,
|
||||
protected IGroupManager $groupManager,
|
||||
protected IConfig $config,
|
||||
private BackendService $backendService,
|
||||
) {
|
||||
parent::__construct($AppName, $request);
|
||||
}
|
||||
|
|
@ -76,7 +79,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')
|
||||
|
|
|
|||
|
|
@ -13,6 +13,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;
|
||||
|
|
@ -49,6 +50,7 @@ class UserGlobalStoragesController extends StoragesController {
|
|||
IUserSession $userSession,
|
||||
IGroupManager $groupManager,
|
||||
IConfig $config,
|
||||
BackendService $backendService,
|
||||
) {
|
||||
parent::__construct(
|
||||
$AppName,
|
||||
|
|
@ -58,7 +60,8 @@ class UserGlobalStoragesController extends StoragesController {
|
|||
$logger,
|
||||
$userSession,
|
||||
$groupManager,
|
||||
$config
|
||||
$config,
|
||||
$backendService,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,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;
|
||||
|
|
@ -46,6 +47,7 @@ class UserStoragesController extends StoragesController {
|
|||
IUserSession $userSession,
|
||||
IGroupManager $groupManager,
|
||||
IConfig $config,
|
||||
BackendService $backendService,
|
||||
) {
|
||||
parent::__construct(
|
||||
$AppName,
|
||||
|
|
@ -55,7 +57,8 @@ class UserStoragesController extends StoragesController {
|
|||
$logger,
|
||||
$userSession,
|
||||
$groupManager,
|
||||
$config
|
||||
$config,
|
||||
$backendService,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -108,15 +111,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 StoragesControllerTest {
|
|||
$this->createMock(LoggerInterface::class),
|
||||
$session,
|
||||
$this->createMock(IGroupManager::class),
|
||||
$config
|
||||
$config,
|
||||
$this->backendService,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,10 +9,12 @@ namespace OCA\Files_External\Tests\Controller;
|
|||
use OCA\Files_External\Controller\GlobalStoragesController;
|
||||
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\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;
|
||||
|
|
@ -29,9 +31,23 @@ abstract class StoragesControllerTest extends \Test\TestCase {
|
|||
* @var GlobalStoragesService|UserStoragesService|MockObject
|
||||
*/
|
||||
protected $service;
|
||||
/**
|
||||
* @var BackendService|MockObject
|
||||
*/
|
||||
protected $backendService;
|
||||
|
||||
protected function setUp(): void {
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -56,7 +56,8 @@ class UserStoragesControllerTest extends StoragesControllerTest {
|
|||
$this->createMock(LoggerInterface::class),
|
||||
$session,
|
||||
$this->createMock(IGroupManager::class),
|
||||
$config
|
||||
$config,
|
||||
$this->backendService,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue