mirror of https://github.com/nextcloud/server
allow filtering occ files_external:list to storages applicable for a user
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
a1aa4491ac
commit
c0c5a19c26
|
@ -33,6 +33,7 @@ use OCA\Files_External\Lib\DefinitionParameter;
|
|||
use OCA\Files_External\Lib\StorageConfig;
|
||||
use OCA\Files_External\Service\BackendService;
|
||||
use OCA\Files_External\Service\GlobalStoragesService;
|
||||
use OCA\Files_External\Service\UserGlobalStoragesService;
|
||||
use OCA\Files_External\Service\UserStoragesService;
|
||||
use OCA\Files_External\Service\StoragesService;
|
||||
use OCP\IUserManager;
|
||||
|
@ -46,19 +47,23 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||
class Create extends Base {
|
||||
private GlobalStoragesService $globalService;
|
||||
private UserStoragesService $userService;
|
||||
private UserGlobalStoragesService $userGlobalService;
|
||||
private IUserManager $userManager;
|
||||
private BackendService $backendService;
|
||||
private IUserSession $userSession;
|
||||
|
||||
public function __construct(GlobalStoragesService $globalService,
|
||||
UserStoragesService $userService,
|
||||
IUserManager $userManager,
|
||||
IUserSession $userSession,
|
||||
BackendService $backendService
|
||||
public function __construct(
|
||||
GlobalStoragesService $globalService,
|
||||
UserStoragesService $userService,
|
||||
UserGlobalStoragesService $userGlobalService,
|
||||
IUserManager $userManager,
|
||||
IUserSession $userSession,
|
||||
BackendService $backendService
|
||||
) {
|
||||
parent::__construct();
|
||||
$this->globalService = $globalService;
|
||||
$this->userService = $userService;
|
||||
$this->userGlobalService = $userGlobalService;
|
||||
$this->userManager = $userManager;
|
||||
$this->userSession = $userSession;
|
||||
$this->backendService = $backendService;
|
||||
|
@ -188,7 +193,7 @@ class Create extends Base {
|
|||
}
|
||||
|
||||
private function showMount(string $user, StorageConfig $mount, InputInterface $input, OutputInterface $output): void {
|
||||
$listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager);
|
||||
$listCommand = new ListCommand($this->globalService, $this->userService, $this->userGlobalService, $this->userSession, $this->userManager);
|
||||
$listInput = new ArrayInput([], $listCommand->getDefinition());
|
||||
$listInput->setOption('output', $input->getOption('output'));
|
||||
$listInput->setOption('show-password', true);
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace OCA\Files_External\Command;
|
|||
use OC\Core\Command\Base;
|
||||
use OCA\Files_External\NotFoundException;
|
||||
use OCA\Files_External\Service\GlobalStoragesService;
|
||||
use OCA\Files_External\Service\UserGlobalStoragesService;
|
||||
use OCA\Files_External\Service\UserStoragesService;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
|
@ -39,13 +40,21 @@ use Symfony\Component\Console\Question\ConfirmationQuestion;
|
|||
class Delete extends Base {
|
||||
protected GlobalStoragesService $globalService;
|
||||
protected UserStoragesService $userService;
|
||||
protected UserGlobalStoragesService $userGlobalService;
|
||||
protected IUserSession $userSession;
|
||||
protected IUserManager $userManager;
|
||||
|
||||
public function __construct(GlobalStoragesService $globalService, UserStoragesService $userService, IUserSession $userSession, IUserManager $userManager) {
|
||||
public function __construct(
|
||||
GlobalStoragesService $globalService,
|
||||
UserStoragesService $userService,
|
||||
UserGlobalStoragesService $userGlobalService,
|
||||
IUserSession $userSession,
|
||||
IUserManager $userManager
|
||||
) {
|
||||
parent::__construct();
|
||||
$this->globalService = $globalService;
|
||||
$this->userService = $userService;
|
||||
$this->userGlobalService = $userGlobalService;
|
||||
$this->userSession = $userSession;
|
||||
$this->userManager = $userManager;
|
||||
}
|
||||
|
@ -79,10 +88,10 @@ class Delete extends Base {
|
|||
$noConfirm = $input->getOption('yes');
|
||||
|
||||
if (!$noConfirm) {
|
||||
$listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager);
|
||||
$listCommand = new ListCommand($this->globalService, $this->userService, $this->userGlobalService, $this->userSession, $this->userManager);
|
||||
$listInput = new ArrayInput([], $listCommand->getDefinition());
|
||||
$listInput->setOption('output', $input->getOption('output'));
|
||||
$listCommand->listMounts(null, [$mount], $listInput, $output);
|
||||
$listCommand->listMounts("", [$mount], $listInput, $output);
|
||||
|
||||
$questionHelper = $this->getHelper('question');
|
||||
$question = new ConfirmationQuestion('Delete this mount? [y/N] ', false);
|
||||
|
|
|
@ -46,7 +46,7 @@ class Export extends ListCommand {
|
|||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int {
|
||||
$listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager);
|
||||
$listCommand = new ListCommand($this->globalService, $this->userService, $this->userGlobalService, $this->userSession, $this->userManager);
|
||||
$listInput = new ArrayInput([], $listCommand->getDefinition());
|
||||
$listInput->setArgument('user_id', $input->getArgument('user_id'));
|
||||
$listInput->setOption('all', $input->getOption('all'));
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Files_External\Command;
|
||||
|
||||
use OC\Core\Command\Base;
|
||||
|
@ -30,6 +31,7 @@ use OCA\Files_External\Lib\StorageConfig;
|
|||
use OCA\Files_External\Service\BackendService;
|
||||
use OCA\Files_External\Service\GlobalStoragesService;
|
||||
use OCA\Files_External\Service\ImportLegacyStoragesService;
|
||||
use OCA\Files_External\Service\UserGlobalStoragesService;
|
||||
use OCA\Files_External\Service\UserStoragesService;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
|
@ -42,21 +44,25 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||
class Import extends Base {
|
||||
private GlobalStoragesService $globalService;
|
||||
private UserStoragesService $userService;
|
||||
private UserGlobalStoragesService $userGlobalService;
|
||||
private IUserSession $userSession;
|
||||
private IUserManager $userManager;
|
||||
private ImportLegacyStoragesService $importLegacyStorageService;
|
||||
private BackendService $backendService;
|
||||
|
||||
public function __construct(GlobalStoragesService $globalService,
|
||||
UserStoragesService $userService,
|
||||
IUserSession $userSession,
|
||||
IUserManager $userManager,
|
||||
ImportLegacyStoragesService $importLegacyStorageService,
|
||||
BackendService $backendService
|
||||
public function __construct(
|
||||
GlobalStoragesService $globalService,
|
||||
UserStoragesService $userService,
|
||||
UserGlobalStoragesService $userGlobalService,
|
||||
IUserSession $userSession,
|
||||
IUserManager $userManager,
|
||||
ImportLegacyStoragesService $importLegacyStorageService,
|
||||
BackendService $backendService
|
||||
) {
|
||||
parent::__construct();
|
||||
$this->globalService = $globalService;
|
||||
$this->userService = $userService;
|
||||
$this->userGlobalService = $userGlobalService;
|
||||
$this->userSession = $userSession;
|
||||
$this->userManager = $userManager;
|
||||
$this->importLegacyStorageService = $importLegacyStorageService;
|
||||
|
@ -88,7 +94,7 @@ class Import extends Base {
|
|||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int {
|
||||
$user = (string) $input->getOption('user');
|
||||
$user = (string)$input->getOption('user');
|
||||
$path = $input->getArgument('path');
|
||||
if ($path === '-') {
|
||||
$json = file_get_contents('php://stdin');
|
||||
|
@ -157,7 +163,7 @@ class Import extends Base {
|
|||
$output->writeln('<error>No mounts to be imported</error>');
|
||||
return 1;
|
||||
}
|
||||
$listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager);
|
||||
$listCommand = new ListCommand($this->globalService, $this->userService, $this->userGlobalService, $this->userSession, $this->userManager);
|
||||
$listInput = new ArrayInput([], $listCommand->getDefinition());
|
||||
$listInput->setOption('output', $input->getOption('output'));
|
||||
$listInput->setOption('show-password', true);
|
||||
|
|
|
@ -29,6 +29,7 @@ use OC\Core\Command\Base;
|
|||
use OC\User\NoUserException;
|
||||
use OCA\Files_External\Lib\StorageConfig;
|
||||
use OCA\Files_External\Service\GlobalStoragesService;
|
||||
use OCA\Files_External\Service\UserGlobalStoragesService;
|
||||
use OCA\Files_External\Service\UserStoragesService;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
|
@ -41,15 +42,23 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||
class ListCommand extends Base {
|
||||
protected GlobalStoragesService $globalService;
|
||||
protected UserStoragesService $userService;
|
||||
protected UserGlobalStoragesService $userGlobalService;
|
||||
protected IUserSession $userSession;
|
||||
protected IUserManager $userManager;
|
||||
|
||||
public const ALL = -1;
|
||||
public const ALL = "__ALL__USERS__";
|
||||
|
||||
public function __construct(GlobalStoragesService $globalService, UserStoragesService $userService, IUserSession $userSession, IUserManager $userManager) {
|
||||
public function __construct(
|
||||
GlobalStoragesService $globalService,
|
||||
UserStoragesService $userService,
|
||||
UserGlobalStoragesService $userGlobalService,
|
||||
IUserSession $userSession,
|
||||
IUserManager $userManager
|
||||
) {
|
||||
parent::__construct();
|
||||
$this->globalService = $globalService;
|
||||
$this->userService = $userService;
|
||||
$this->userGlobalService = $userGlobalService;
|
||||
$this->userSession = $userSession;
|
||||
$this->userManager = $userManager;
|
||||
}
|
||||
|
@ -77,13 +86,26 @@ class ListCommand extends Base {
|
|||
'a',
|
||||
InputOption::VALUE_NONE,
|
||||
'show both system wide mounts and all personal mounts'
|
||||
)->addOption(
|
||||
'for',
|
||||
null,
|
||||
InputOption::VALUE_REQUIRED,
|
||||
'show only mounts applicable for a specific user'
|
||||
);
|
||||
parent::configure();
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int {
|
||||
/** @var StorageConfig[] $mounts */
|
||||
if ($input->getOption('all')) {
|
||||
if ($for = $input->getOption('for')) {
|
||||
$forUser = $this->userManager->get($for);
|
||||
if (!$forUser) {
|
||||
$output->writeln("<error>User $for not found</error>");
|
||||
return 1;
|
||||
}
|
||||
$mounts = $this->userGlobalService->getAllStoragesForUser($forUser);
|
||||
$userId = self::ALL;
|
||||
} else if ($input->getOption('all')) {
|
||||
$mounts = $this->globalService->getStorageForAllUsers();
|
||||
$userId = self::ALL;
|
||||
} else {
|
||||
|
@ -97,10 +119,10 @@ class ListCommand extends Base {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param ?string|ListCommand::ALL $userId
|
||||
* @param string $userId
|
||||
* @param StorageConfig[] $mounts
|
||||
*/
|
||||
public function listMounts($userId, array $mounts, InputInterface $input, OutputInterface $output): void {
|
||||
public function listMounts(string $userId, array $mounts, InputInterface $input, OutputInterface $output): void {
|
||||
$outputType = $input->getOption('output');
|
||||
if (count($mounts) === 0) {
|
||||
if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) {
|
||||
|
@ -245,7 +267,7 @@ class ListCommand extends Base {
|
|||
}
|
||||
}
|
||||
|
||||
protected function getStorageService($userId) {
|
||||
protected function getStorageService(string $userId) {
|
||||
if (!empty($userId)) {
|
||||
$user = $this->userManager->get($userId);
|
||||
if (is_null($user)) {
|
||||
|
|
|
@ -33,6 +33,7 @@ use OCA\Files_External\Lib\Auth\Password\SessionCredentials;
|
|||
use OCA\Files_External\Lib\Backend\Local;
|
||||
use OCA\Files_External\Lib\StorageConfig;
|
||||
use OCA\Files_External\Service\GlobalStoragesService;
|
||||
use OCA\Files_External\Service\UserGlobalStoragesService;
|
||||
use OCA\Files_External\Service\UserStoragesService;
|
||||
use OCP\Authentication\LoginCredentials\IStore;
|
||||
use OCP\IL10N;
|
||||
|
@ -51,12 +52,14 @@ class ListCommandTest extends CommandTest {
|
|||
$globalService = $this->createMock(GlobalStoragesService::class);
|
||||
/** @var UserStoragesService|\PHPUnit\Framework\MockObject\MockObject $userService */
|
||||
$userService = $this->createMock(UserStoragesService::class);
|
||||
/** @var UserStoragesService|\PHPUnit\Framework\MockObject\MockObject $userService */
|
||||
$userGlobalService = $this->createMock(UserGlobalStoragesService::class);
|
||||
/** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject $userManager */
|
||||
$userManager = $this->createMock(IUserManager::class);
|
||||
/** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject $userSession */
|
||||
$userSession = $this->createMock(IUserSession::class);
|
||||
|
||||
return new ListCommand($globalService, $userService, $userSession, $userManager);
|
||||
return new ListCommand($globalService, $userService, $userGlobalService, $userSession, $userManager);
|
||||
}
|
||||
|
||||
public function testListAuthIdentifier() {
|
||||
|
|
Loading…
Reference in New Issue