mirror of
https://github.com/verdigado/organization_folders.git
synced 2024-11-21 20:28:11 +01:00
Added organization folder member occ commands
This commit is contained in:
parent
afb731e56b
commit
fb3f9836a2
5 changed files with 125 additions and 3 deletions
|
@ -25,6 +25,9 @@
|
|||
<command>OCA\OrganizationFolders\Command\OrganizationFolder\UpdateOrganizationFolder</command>
|
||||
<command>OCA\OrganizationFolders\Command\OrganizationFolder\DeleteOrganizationFolder</command>
|
||||
<command>OCA\OrganizationFolders\Command\OrganizationFolder\FixACLsOfOrganizationFolder</command>
|
||||
<command>OCA\OrganizationFolders\Command\OrganizationFolderMember\CreateOrganizationFolderMember</command>
|
||||
<command>OCA\OrganizationFolders\Command\OrganizationFolderMember\ListOrganizationFolderMembers</command>
|
||||
<command>OCA\OrganizationFolders\Command\OrganizationFolderMember\DeleteOrganizationFolderMember</command>
|
||||
<command>OCA\OrganizationFolders\Command\Resource\CreateResource</command>
|
||||
<command>OCA\OrganizationFolders\Command\Resource\ListResources</command>
|
||||
<command>OCA\OrganizationFolders\Command\Resource\UpdateResource</command>
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\OrganizationFolders\Command\OrganizationFolderMember;
|
||||
|
||||
use OCP\DB\Exception;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
use OCA\OrganizationFolders\Command\BaseCommand;
|
||||
use OCA\OrganizationFolders\Model\Principal;
|
||||
use OCA\OrganizationFolders\Enum\PrincipalType;
|
||||
use OCA\OrganizationFolders\Enum\OrganizationFolderMemberPermissionLevel;
|
||||
|
||||
class CreateOrganizationFolderMember extends BaseCommand {
|
||||
protected function configure(): void {
|
||||
$this
|
||||
->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("<error>Exception \"{$e->getMessage()}\" at {$e->getFile()} line {$e->getLine()}</error>");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\OrganizationFolders\Command\OrganizationFolderMember;
|
||||
|
||||
use OCP\DB\Exception;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
use OCA\OrganizationFolders\Command\BaseCommand;
|
||||
|
||||
class DeleteOrganizationFolderMember extends BaseCommand {
|
||||
protected function configure(): void {
|
||||
$this
|
||||
->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("<error>Exception \"{$e->getMessage()}\" at {$e->getFile()} line {$e->getLine()}</error>");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\OrganizationFolders\Command\OrganizationFolderMember;
|
||||
|
||||
use OCP\DB\Exception;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
use OCA\OrganizationFolders\Command\BaseCommand;
|
||||
|
||||
class ListOrganizationFolderMembers extends BaseCommand {
|
||||
protected function configure(): void {
|
||||
$this
|
||||
->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("<error>Exception \"{$e->getMessage()}\" at {$e->getFile()} line {$e->getLine()}</error>");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue