Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions apps/files_external/lib/Controller/GlobalStoragesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 OCA\Files_External\Settings\Admin;
use OCP\AppFramework\Http;
Expand Down Expand Up @@ -37,6 +38,7 @@ public function __construct(
IUserSession $userSession,
IGroupManager $groupManager,
IConfig $config,
BackendService $backendService,
) {
parent::__construct(
$appName,
Expand All @@ -46,7 +48,8 @@ public function __construct(
$logger,
$userSession,
$groupManager,
$config
$config,
$backendService
);
}

Expand Down Expand Up @@ -74,16 +77,6 @@ public function create(
?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,
Expand Down
5 changes: 4 additions & 1 deletion apps/files_external/lib/Controller/StoragesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@

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;
Expand Down Expand Up @@ -48,6 +50,7 @@ public function __construct(
protected IUserSession $userSession,
protected IGroupManager $groupManager,
protected IConfig $config,
private BackendService $backendService,
) {
parent::__construct($appName, $request);
}
Expand Down Expand Up @@ -77,7 +80,7 @@ protected function createStorage(
?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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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;
Expand Down Expand Up @@ -50,6 +51,7 @@ public function __construct(
IUserSession $userSession,
IGroupManager $groupManager,
IConfig $config,
BackendService $backendService,
) {
parent::__construct(
$appName,
Expand All @@ -59,7 +61,8 @@ public function __construct(
$logger,
$userSession,
$groupManager,
$config
$config,
$backendService,
);
}

Expand Down
14 changes: 4 additions & 10 deletions apps/files_external/lib/Controller/UserStoragesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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;
Expand Down Expand Up @@ -40,6 +41,7 @@ public function __construct(
IUserSession $userSession,
IGroupManager $groupManager,
IConfig $config,
BackendService $backendService,
) {
parent::__construct(
$appName,
Expand All @@ -49,7 +51,8 @@ public function __construct(
$logger,
$userSession,
$groupManager,
$config
$config,
$backendService,
);
}

Expand Down Expand Up @@ -98,15 +101,6 @@ public function create(
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ private function createController(bool $allowCreateLocal = true): GlobalStorages
$this->createMock(LoggerInterface::class),
$session,
$this->createMock(IGroupManager::class),
$config
$config,
$this->backendService,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
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;
Expand All @@ -25,10 +27,21 @@
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ private function createController(bool $allowCreateLocal = true) {
$this->createMock(LoggerInterface::class),
$session,
$this->createMock(IGroupManager::class),
$config
$config,
$this->backendService,
);
}

Expand Down
Loading