initial implementation of demo organization provider
This commit is contained in:
parent
9d2d0a7988
commit
429ca86ce9
5 changed files with 180 additions and 0 deletions
21
appinfo/info.xml
Normal file
21
appinfo/info.xml
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0"?>
|
||||
<info xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd">
|
||||
<id>demo_organization_provider</id>
|
||||
<name>Demo Organization Provider</name>
|
||||
<summary></summary>
|
||||
<description><![CDATA[]]></description>
|
||||
<version>1.0.0</version>
|
||||
<licence>agpl</licence>
|
||||
<author mail="mail@jonathan-treffler.de">Jonathan Treffler</author>
|
||||
<namespace>DemoOrganizationProvider</namespace>
|
||||
<category>files</category>
|
||||
<bugs>https://git.verdigado.com/verdigado-public/demo_organization_provider/issues</bugs>
|
||||
<dependencies>
|
||||
<php min-version="8.2" />
|
||||
<database>pgsql</database>
|
||||
<database>sqlite</database>
|
||||
<database>mysql</database>
|
||||
<nextcloud min-version="30" max-version="30"/>
|
||||
</dependencies>
|
||||
</info>
|
8
appinfo/routes.php
Normal file
8
appinfo/routes.php
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'resources' => [
|
||||
],
|
||||
'routes' => [
|
||||
]
|
||||
];
|
28
lib/AppInfo/Application.php
Normal file
28
lib/AppInfo/Application.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\DemoOrganizationProvider\AppInfo;
|
||||
|
||||
use OCP\AppFramework\App;
|
||||
use OCP\AppFramework\Bootstrap\IBootstrap;
|
||||
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
||||
use OCP\AppFramework\Bootstrap\IBootContext;
|
||||
|
||||
use OCA\OrganizationFolders\Events\RegisterOrganizationProviderEvent;
|
||||
|
||||
use OCA\DemoOrganizationProvider\Listener\RegisterOrganizationProviderListener;
|
||||
|
||||
class Application extends App implements IBootstrap {
|
||||
public const APP_ID = 'demo_organization_provider';
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct(self::APP_ID);
|
||||
}
|
||||
|
||||
public function register(IRegistrationContext $context): void {
|
||||
$context->registerEventListener(RegisterOrganizationProviderEvent::class, RegisterOrganizationProviderListener::class);
|
||||
}
|
||||
|
||||
public function boot(IBootContext $context): void {
|
||||
}
|
||||
|
||||
}
|
25
lib/Listener/RegisterOrganizationProviderListener.php
Normal file
25
lib/Listener/RegisterOrganizationProviderListener.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\DemoOrganizationProvider\Listener;
|
||||
|
||||
use OCA\DemoOrganizationProvider\OrganizationProviders\DemoOrganizationProvider;
|
||||
|
||||
use OCA\OrganizationFolders\Events\RegisterOrganizationProviderEvent;
|
||||
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\EventDispatcher\IEventListener;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class RegisterOrganizationProviderListener implements IEventListener {
|
||||
public function __construct(private ContainerInterface $container) {}
|
||||
|
||||
public function handle(Event $event): void {
|
||||
if ($event instanceof RegisterOrganizationProviderEvent) {
|
||||
$organizationProviderManager = $event->getOrganizationProviderManager();
|
||||
$organizationProviderManager->registerOrganizationProvider(new DemoOrganizationProvider());
|
||||
}
|
||||
}
|
||||
}
|
98
lib/OrganizationProviders/DemoOrganizationProvider.php
Normal file
98
lib/OrganizationProviders/DemoOrganizationProvider.php
Normal file
|
@ -0,0 +1,98 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\DemoOrganizationProvider\OrganizationProviders;
|
||||
|
||||
use OCA\OrganizationFolders\Model\Organization;
|
||||
use OCA\OrganizationFolders\Model\OrganizationRole;
|
||||
|
||||
use OCA\OrganizationFolders\Errors\OrganizationNotFound;
|
||||
use OCA\OrganizationFolders\Errors\OrganizationRoleNotFound;
|
||||
|
||||
class DemoOrganizationProvider extends \OCA\OrganizationFolders\OrganizationProvider\OrganizationProvider {
|
||||
protected $id = "demo";
|
||||
|
||||
private const DEMO_ORGANIZATIONS = [1, 2, 11, 12, 13, 21, 22];
|
||||
|
||||
/**
|
||||
* @return Organization
|
||||
* @throws OrganizationNotFound
|
||||
*/
|
||||
public function getOrganization(int $id): Organization {
|
||||
if(in_array($id, self::DEMO_ORGANIZATIONS)) {
|
||||
return new Organization($id, (string)$id);
|
||||
} else {
|
||||
throw new OrganizationNotFound("demo", $id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Organization[]
|
||||
*/
|
||||
public function getSubOrganizations(?int $parentOrganizationId = null): array {
|
||||
if(is_null($parentOrganizationId)) {
|
||||
return [
|
||||
new Organization(1, "1"),
|
||||
new Organization(2, "2"),
|
||||
];
|
||||
} else if ($parentOrganizationId === 1) {
|
||||
return [
|
||||
new Organization(11, "11"),
|
||||
new Organization(12, "12"),
|
||||
new Organization(13, "13"),
|
||||
];
|
||||
} else if ($parentOrganizationId === 2) {
|
||||
return [
|
||||
new Organization(21, "21"),
|
||||
new Organization(22, "22"),
|
||||
];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return OrganizationRole
|
||||
* @throws OrganizationRoleNotFound
|
||||
*/
|
||||
public function getRole(string $id): OrganizationRole {
|
||||
[$organizationIdString, $roleNumberString] = explode("_", $id, 2);
|
||||
$organizationId = (int)$organizationIdString;
|
||||
$roleNumber = (int)$roleNumberString;
|
||||
|
||||
if(in_array($organizationId, self::DEMO_ORGANIZATIONS)) {
|
||||
if($roleNumber >= 1 && $roleNumber <= 3) {
|
||||
return new OrganizationRole(
|
||||
id: $id,
|
||||
organizationId: $organizationId,
|
||||
friendlyName: "Role " . $roleNumber . " of org " . $organizationId,
|
||||
membersGroup: $id
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
throw new OrganizationRoleNotFound("demo", $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return OrganizationRole[]
|
||||
*/
|
||||
public function getRolesOfOrganization(int $organizationId): array {
|
||||
if(in_array($organizationId, self::DEMO_ORGANIZATIONS)) {
|
||||
$result = [];
|
||||
for($i = 1; $i <= 3; $i++) {
|
||||
$result[] = new OrganizationRole(
|
||||
id: $organizationId . "_" . $i,
|
||||
organizationId: $organizationId,
|
||||
friendlyName: "Role " . $i . " of org " . $organizationId,
|
||||
membersGroup: $organizationId . "_" . $i
|
||||
);
|
||||
}
|
||||
return $result;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue