From 851fa0a1ccdff6003c12605cae8a5dcb74e7c0e2 Mon Sep 17 00:00:00 2001 From: Jonathan Treffler Date: Wed, 30 Oct 2024 04:47:47 +0100 Subject: [PATCH] added work-in-progress organization folder occ commands --- appinfo/info.xml | 2 + .../CreateOrganizationFolder.php | 36 +++++++++++ .../ListOrganizationFolders.php | 31 +++++++++ lib/Model/OrganizationFolder.php | 43 +++++++++++++ lib/Service/OrganizationFolderService.php | 63 +++++++++++++++++++ 5 files changed, 175 insertions(+) create mode 100644 lib/Command/OrganizationFolder/CreateOrganizationFolder.php create mode 100644 lib/Command/OrganizationFolder/ListOrganizationFolders.php create mode 100644 lib/Model/OrganizationFolder.php create mode 100644 lib/Service/OrganizationFolderService.php diff --git a/appinfo/info.xml b/appinfo/info.xml index 00e9464..f58e3af 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -19,6 +19,8 @@ + OCA\OrganizationFolders\Command\OrganizationFolder\ListOrganizationFolders + OCA\OrganizationFolders\Command\OrganizationFolder\CreateOrganizationFolder OCA\OrganizationFolders\Command\Resource\CreateResource OCA\OrganizationFolders\Command\Resource\ListResources diff --git a/lib/Command/OrganizationFolder/CreateOrganizationFolder.php b/lib/Command/OrganizationFolder/CreateOrganizationFolder.php new file mode 100644 index 0000000..c6c1a77 --- /dev/null +++ b/lib/Command/OrganizationFolder/CreateOrganizationFolder.php @@ -0,0 +1,36 @@ +setName('organization-folders:create') + ->setDescription('Create a new organization folder') + ->addOption('name', null, InputOption::VALUE_REQUIRED, 'Name of the new organization folder') + ->addOption('quota', null, InputOption::VALUE_REQUIRED, 'Storage Quota of the new organization folder'); + parent::configure(); + } + + protected function execute(InputInterface $input, OutputInterface $output): int { + $name = $input->getOption('name'); + $quota = $input->getOption('quota'); + + try { + $organizationFolder = $this->organizationFolderService->create($name, $quota); + + $output->writeln(json_encode($organizationFolder)); + return 0; + } catch (Exception $e) { + $output->writeln("Exception \"{$e->getMessage()}\" at {$e->getFile()} line {$e->getLine()}"); + return 1; + } + } +} diff --git a/lib/Command/OrganizationFolder/ListOrganizationFolders.php b/lib/Command/OrganizationFolder/ListOrganizationFolders.php new file mode 100644 index 0000000..65b82d3 --- /dev/null +++ b/lib/Command/OrganizationFolder/ListOrganizationFolders.php @@ -0,0 +1,31 @@ +setName('organization-folders:list') + ->setDescription('List all organization folders'); + parent::configure(); + } + + protected function execute(InputInterface $input, OutputInterface $output): int { + try { + $organizationFolderGroupfolders = $this->organizationFolderService->getAll(); + + $this->writeTableInOutputFormat($input, $output, $this->formatOrganizationFolders($organizationFolderGroupfolders)); + return 0; + } catch (Exception $e) { + $output->writeln("Exception \"{$e->getMessage()}\" at {$e->getFile()} line {$e->getLine()}"); + return 1; + } + } +} diff --git a/lib/Model/OrganizationFolder.php b/lib/Model/OrganizationFolder.php new file mode 100644 index 0000000..8e0e495 --- /dev/null +++ b/lib/Model/OrganizationFolder.php @@ -0,0 +1,43 @@ +id; + } + + public function getName(): string { + return $this->name; + } + + public function getQuota(): int { + return $this->quota; + } + + public function jsonSerialize(): array { + return [ + 'id' => $this->id, + 'name' => $this->name, + 'quota' => $this->quota, + ]; + } + + public function tableSerialize(): array { + return [ + 'Id' => $this->id, + 'Name' => $this->name, + 'Quota' => $this->quota, + ]; + } +} \ No newline at end of file diff --git a/lib/Service/OrganizationFolderService.php b/lib/Service/OrganizationFolderService.php new file mode 100644 index 0000000..4db0bfe --- /dev/null +++ b/lib/Service/OrganizationFolderService.php @@ -0,0 +1,63 @@ +tagService->findAllIncludingGroupfolder("organization_folder"); + + foreach ($tags as $tag) { + $result[] = new OrganizationFolder($tag["group_folder_id"], $tag["mount_point"], $tag["quota"]); + } + + return $result; + } + + public function create(string $name, int $quota, ?string $organizationProvider = null,?int $organizationId = null) { + $this->atomic(function () use ($name, $quota) { + $groupfolderId = $this->folderManager->createFolder($name); + $this->folderManager->setFolderQuota($groupfolderId, $quota); + $this->folderManager->setFolderACL($groupfolderId, true); + + $this->tagService->update($groupfolderId, "organization_folder"); + + if(isset($organizationProvider) && $this->organizationProviderManager->hasOrganizationProvider($organizationProvider) && isset($organizationId)) { + $organization = $this->organizationProviderManager->getOrganizationProvider($organizationProvider)->getOrganization($organizationId); + + $this->tagService->update($groupfolderId, "organization_provider", $organizationProvider); + $this->tagService->update($groupfolderId, "organization_id", $organization->getId()); + } + + // TODO: return Model object + + }, $this->db); + } + + public function applyPermissions(int $id) { + + } + +}