From fb3f9836a279e0b9516b74efc6ea5d3f19f659d4 Mon Sep 17 00:00:00 2001 From: Jonathan Treffler Date: Sat, 16 Nov 2024 03:17:50 +0100 Subject: [PATCH] Added organization folder member occ commands --- appinfo/info.xml | 3 ++ lib/Command/BaseCommand.php | 8 ++-- .../CreateOrganizationFolderMember.php | 48 +++++++++++++++++++ .../DeleteOrganizationFolderMember.php | 34 +++++++++++++ .../ListOrganizationFolderMembers.php | 35 ++++++++++++++ 5 files changed, 125 insertions(+), 3 deletions(-) create mode 100644 lib/Command/OrganizationFolderMember/CreateOrganizationFolderMember.php create mode 100644 lib/Command/OrganizationFolderMember/DeleteOrganizationFolderMember.php create mode 100644 lib/Command/OrganizationFolderMember/ListOrganizationFolderMembers.php diff --git a/appinfo/info.xml b/appinfo/info.xml index af8666f..10bc195 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -25,6 +25,9 @@ OCA\OrganizationFolders\Command\OrganizationFolder\UpdateOrganizationFolder OCA\OrganizationFolders\Command\OrganizationFolder\DeleteOrganizationFolder OCA\OrganizationFolders\Command\OrganizationFolder\FixACLsOfOrganizationFolder + OCA\OrganizationFolders\Command\OrganizationFolderMember\CreateOrganizationFolderMember + OCA\OrganizationFolders\Command\OrganizationFolderMember\ListOrganizationFolderMembers + OCA\OrganizationFolders\Command\OrganizationFolderMember\DeleteOrganizationFolderMember OCA\OrganizationFolders\Command\Resource\CreateResource OCA\OrganizationFolders\Command\Resource\ListResources OCA\OrganizationFolders\Command\Resource\UpdateResource diff --git a/lib/Command/BaseCommand.php b/lib/Command/BaseCommand.php index 82939d3..93cc1be 100644 --- a/lib/Command/BaseCommand.php +++ b/lib/Command/BaseCommand.php @@ -6,6 +6,7 @@ use OC\Core\Command\Base; use OCP\IDateTimeFormatter; use OCA\OrganizationFolders\Service\OrganizationFolderService; +use OCA\OrganizationFolders\Service\OrganizationFolderMemberService; use OCA\OrganizationFolders\Service\ResourceService; use OCA\OrganizationFolders\Service\ResourceMemberService; use OCA\OrganizationFolders\OrganizationProvider\OrganizationProviderManager; @@ -16,9 +17,10 @@ abstract class BaseCommand extends Base { public function __construct( private readonly IDateTimeFormatter $dateTimeFormatter, protected readonly OrganizationFolderService $organizationFolderService, - protected ResourceService $resourceService, - protected ResourceMemberService $resourceMemberService, - protected OrganizationProviderManager $organizationProviderManager, + protected readonly OrganizationFolderMemberService $organizationFolderMemberService, + protected readonly ResourceService $resourceService, + protected readonly ResourceMemberService $resourceMemberService, + protected readonly OrganizationProviderManager $organizationProviderManager, ) { parent::__construct(); } diff --git a/lib/Command/OrganizationFolderMember/CreateOrganizationFolderMember.php b/lib/Command/OrganizationFolderMember/CreateOrganizationFolderMember.php new file mode 100644 index 0000000..872538e --- /dev/null +++ b/lib/Command/OrganizationFolderMember/CreateOrganizationFolderMember.php @@ -0,0 +1,48 @@ +setName('organization-folders:members:create') + ->setDescription('Create a new member of an organization folder') + ->addOption('organization-folder-id', null, InputOption::VALUE_REQUIRED, 'Id of organization folder to create member of') + ->addOption('permission-level', null, InputOption::VALUE_REQUIRED, 'Permissions level of member (valid values: MEMBER, MANAGER, ADMIN)') + ->addOption('principal-type', null, InputOption::VALUE_REQUIRED, 'Type of principal (valid values: GROUP, ROLE)') + ->addOption('principal-id', null, InputOption::VALUE_OPTIONAL, 'For type group: "[group_name]", for type role: "[organization_provider_id]:[role_id]"'); + + parent::configure(); + } + + protected function execute(InputInterface $input, OutputInterface $output): int { + $organizationFolderId = $input->getOption('organization-folder-id'); + $permissionLevel = OrganizationFolderMemberPermissionLevel::fromNameOrValue($input->getOption('permission-level')); + $principalType = PrincipalType::fromNameOrValue($input->getOption('principal-type')); + $principalId = $input->getOption('principal-id'); + + try { + $member = $this->organizationFolderMemberService->create( + organizationFolderId: $organizationFolderId, + permissionLevel: $permissionLevel, + principal: new Principal($principalType, $principalId), + ); + + $this->writeTableInOutputFormat($input, $output, [$this->formatTableSerializable($member)]); + return 0; + } catch (Exception $e) { + $output->writeln("Exception \"{$e->getMessage()}\" at {$e->getFile()} line {$e->getLine()}"); + return 1; + } + } +} diff --git a/lib/Command/OrganizationFolderMember/DeleteOrganizationFolderMember.php b/lib/Command/OrganizationFolderMember/DeleteOrganizationFolderMember.php new file mode 100644 index 0000000..bdf070c --- /dev/null +++ b/lib/Command/OrganizationFolderMember/DeleteOrganizationFolderMember.php @@ -0,0 +1,34 @@ +setName('organization-folders:members:delete') + ->setDescription('Delete a member of an organization folder') + ->addArgument('id', InputArgument::REQUIRED, 'Id of the organization folder'); + } + + protected function execute(InputInterface $input, OutputInterface $output): int { + $id = (int)$input->getArgument('id'); + + try { + $this->organizationFolderMemberService->delete($id); + + $output->writeln("done"); + + return 0; + } catch (Exception $e) { + $output->writeln("Exception \"{$e->getMessage()}\" at {$e->getFile()} line {$e->getLine()}"); + return 1; + } + } +} diff --git a/lib/Command/OrganizationFolderMember/ListOrganizationFolderMembers.php b/lib/Command/OrganizationFolderMember/ListOrganizationFolderMembers.php new file mode 100644 index 0000000..28e29fa --- /dev/null +++ b/lib/Command/OrganizationFolderMember/ListOrganizationFolderMembers.php @@ -0,0 +1,35 @@ +setName('organization-folders:members:list') + ->addArgument('organization-folder-id', InputArgument::REQUIRED, 'Id of organization folder') + ->setDescription('List all members of organization folder.'); + + parent::configure(); + } + + protected function execute(InputInterface $input, OutputInterface $output): int { + try { + $organizationFolderId = $input->getArgument('organization-folder-id'); + + $members = $this->organizationFolderMemberService->findAll($organizationFolderId); + + $this->writeTableInOutputFormat($input, $output, $this->formatTableSerializables($members)); + return 0; + } catch (Exception $e) { + $output->writeln("Exception \"{$e->getMessage()}\" at {$e->getFile()} line {$e->getLine()}"); + return 1; + } + } +}