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
17 changes: 5 additions & 12 deletions apps/files_external/lib/Controller/GlobalStoragesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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;
Expand Down Expand Up @@ -63,7 +64,8 @@ public function __construct(
LoggerInterface $logger,
IUserSession $userSession,
IGroupManager $groupManager,
IConfig $config
IConfig $config,
BackendService $backendService
) {
parent::__construct(
$AppName,
Expand All @@ -73,7 +75,8 @@ public function __construct(
$logger,
$userSession,
$groupManager,
$config
$config,
$backendService
);
}

Expand Down Expand Up @@ -102,16 +105,6 @@ public function create(
$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,
Expand Down
7 changes: 5 additions & 2 deletions apps/files_external/lib/Controller/StoragesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@

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;
use OCA\Files_External\Service\BackendService;
use OCA\Files_External\Service\StoragesService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
Expand Down Expand Up @@ -67,7 +69,8 @@ public function __construct(
protected LoggerInterface $logger,
protected IUserSession $userSession,
protected IGroupManager $groupManager,
protected IConfig $config
protected IConfig $config,
private BackendService $backendService
) {
parent::__construct($AppName, $request);
}
Expand Down Expand Up @@ -97,7 +100,7 @@ protected function createStorage(
$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 @@ -33,6 +33,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 @@ -68,7 +69,8 @@ public function __construct(
LoggerInterface $logger,
IUserSession $userSession,
IGroupManager $groupManager,
IConfig $config
IConfig $config,
BackendService $backendService
) {
parent::__construct(
$AppName,
Expand All @@ -78,7 +80,8 @@ public function __construct(
$logger,
$userSession,
$groupManager,
$config
$config,
$backendService,
);
}

Expand Down
16 changes: 5 additions & 11 deletions apps/files_external/lib/Controller/UserStoragesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,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 @@ -67,7 +68,8 @@ public function __construct(
LoggerInterface $logger,
IUserSession $userSession,
IGroupManager $groupManager,
IConfig $config
IConfig $config,
BackendService $backendService
) {
parent::__construct(
$AppName,
Expand All @@ -77,7 +79,8 @@ public function __construct(
$logger,
$userSession,
$groupManager,
$config
$config,
$backendService,
);
}

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

Expand Down
16 changes: 16 additions & 0 deletions apps/files_external/tests/Controller/StoragesControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
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\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 @@ -49,9 +51,23 @@ abstract class StoragesControllerTest extends \Test\TestCase {
* @var GlobalStoragesService|UserStoragesService|MockObject
*/
protected $service;
/**
* @var BackendService|MockObject
*/
protected $backendService;

protected function setUp(): void {
\OCA\Files_External\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 @@ -76,7 +76,8 @@ private function createController($allowCreateLocal = true) {
$this->createMock(LoggerInterface::class),
$session,
$this->createMock(IGroupManager::class),
$config
$config,
$this->backendService,
);
}

Expand Down
Loading