diff --git a/appinfo/info.xml b/appinfo/info.xml
index 6e4aa44..00e9464 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -18,4 +18,8 @@
mysql
+
+ OCA\OrganizationFolders\Command\Resource\CreateResource
+ OCA\OrganizationFolders\Command\Resource\ListResources
+
\ No newline at end of file
diff --git a/lib/Command/BaseCommand.php b/lib/Command/BaseCommand.php
new file mode 100644
index 0000000..424ec56
--- /dev/null
+++ b/lib/Command/BaseCommand.php
@@ -0,0 +1,34 @@
+tableSerialize();
+ }
+
+ protected function formatOrganizationFolders(array $organizationFolders) {
+ return array_map($this->formatTableSerializable(...), $organizationFolders);
+ }
+
+ protected function formatResources(array $resources): array {
+ return array_map($this->formatTableSerializable(...), $resources);
+ }
+}
diff --git a/lib/Command/Resource/CreateResource.php b/lib/Command/Resource/CreateResource.php
new file mode 100644
index 0000000..2df908b
--- /dev/null
+++ b/lib/Command/Resource/CreateResource.php
@@ -0,0 +1,60 @@
+setName('organization-folders:create-resource')
+ ->setDescription('Create a new resource in organization folder')
+ ->addOption('organization-folder', null, InputOption::VALUE_REQUIRED, 'Id of organization folder to create resource in')
+ ->addOption('type', null, InputOption::VALUE_REQUIRED, 'Type of resource (valid values: folder)')
+ ->addOption('name', null, InputOption::VALUE_REQUIRED, 'Name of resource')
+ ->addOption('parent-resource', null, InputOption::VALUE_OPTIONAL, 'Id of parent resource (leave out if creating at top level in organization folder)');
+
+ // folder type options
+ $this
+ ->addOption('members-acl-permission', null, InputOption::VALUE_OPTIONAL, 'acl permissions for members of resource')
+ ->addOption('managers-acl-permission', null, InputOption::VALUE_OPTIONAL, 'acl permissions for managers of resource')
+ ->addOption('inherited-acl-permission', null, InputOption::VALUE_OPTIONAL, 'acl permissions for users with access to the resource level above (or organization in case resource is top-level)');
+
+ parent::configure();
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output): int {
+ $organizationFolder = $input->getOption('organization-folder');
+ $type = $input->getOption('type');
+ $name = $input->getOption('name');
+ $parentResource = $input->getOption('parent-resource');
+
+ $membersAclPermission = $input->getOption('members-acl-permission');
+ $managersAclPermission = $input->getOption('managers-acl-permission');
+ $inheritedAclPermission = $input->getOption('inherited-acl-permission');
+
+ try {
+ $resource = $this->resourceService->create(
+ type: $type,
+ organizationFolderId: $organizationFolder,
+ name: $name,
+ parentResource: $parentResource,
+
+ membersAclPermission: $membersAclPermission,
+ managersAclPermission: $managersAclPermission,
+ inheritedAclPermission: $inheritedAclPermission,
+ );
+
+ $this->writeTableInOutputFormat($input, $output, [$this->formatTableSerializable($resource)]);
+ return 0;
+ } catch (Exception $e) {
+ $output->writeln("Exception \"{$e->getMessage()}\" at {$e->getFile()} line {$e->getLine()}");
+ return 1;
+ }
+ }
+}
diff --git a/lib/Command/Resource/ListResources.php b/lib/Command/Resource/ListResources.php
new file mode 100644
index 0000000..cf75ab1
--- /dev/null
+++ b/lib/Command/Resource/ListResources.php
@@ -0,0 +1,37 @@
+setName('organization-folders:list-resources')
+ ->addArgument('organization-folder-id', InputArgument::REQUIRED, 'Id of Organization Folder')
+ ->addArgument('parent-resource-id', InputArgument::OPTIONAL, 'Id of Organization Folder')
+ ->setDescription('List all resource in organization folder. Only shows one layer of tree at once, provide resource parent id to reveal child resources.');
+
+ parent::configure();
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output): int {
+ try {
+ $organizationFolderId = $input->getArgument('organization-folder-id');
+ $parentResourceId = $input->getArgument('parent-resource-id');
+
+ $resources = $this->resourceService->findAll($organizationFolderId, $parentResourceId);
+
+ $this->writeTableInOutputFormat($input, $output, $this->formatResources($resources));
+ return 0;
+ } catch (Exception $e) {
+ $output->writeln("Exception \"{$e->getMessage()}\" at {$e->getFile()} line {$e->getLine()}");
+ return 1;
+ }
+ }
+}
diff --git a/lib/Db/FolderResource.php b/lib/Db/FolderResource.php
index 0007bbf..0ccb8c3 100644
--- a/lib/Db/FolderResource.php
+++ b/lib/Db/FolderResource.php
@@ -47,4 +47,22 @@ class FolderResource extends Resource {
'inheritedAclPermission' => $this->inheritedAclPermission,
];
}
+
+ public function tableSerialize(): array {
+ return [
+ 'Id' => $this->id,
+ 'Name' => $this->name,
+ 'Type' => "Folder",
+ 'Active' => ((bool)$this->active) ? 'yes' : 'no',
+ 'Last Updated' => $this->lastUpdatedTimestamp,
+
+ 'Members ACL Permission' => $this->membersAclPermission,
+ 'Managers ACL Permission' => $this->managersAclPermission,
+ 'Inherited ACL Permission' => $this->inheritedAclPermission,
+ ];
+ }
+
+ public function getType(): string {
+ return "folder";
+ }
}
diff --git a/lib/Db/Resource.php b/lib/Db/Resource.php
index 8bd3bce..386679e 100644
--- a/lib/Db/Resource.php
+++ b/lib/Db/Resource.php
@@ -3,10 +3,11 @@
namespace OCA\OrganizationFolders\Db;
use JsonSerializable;
+use OCA\OrganizationFolders\Interface\TableSerializable;
use OCP\AppFramework\Db\Entity;
-abstract class Resource extends Entity implements JsonSerializable {
+abstract class Resource extends Entity implements JsonSerializable, TableSerializable {
protected $organizationFolderId;
protected $parentResource;
protected $name;
@@ -19,4 +20,6 @@ abstract class Resource extends Entity implements JsonSerializable {
$this->addType('active','bool');
$this->addType('lastUpdatedTimestamp','integer');
}
+
+ abstract public function getType(): string;
}
diff --git a/lib/Interface/TableSerializable.php b/lib/Interface/TableSerializable.php
new file mode 100644
index 0000000..ac4a26f
--- /dev/null
+++ b/lib/Interface/TableSerializable.php
@@ -0,0 +1,11 @@
+id;
}