0
0
Fork 0
mirror of https://github.com/verdigado/organization_folders.git synced 2024-12-06 11:22:41 +01:00

split principal types into different subclasses, added principal factory, implemented principal friendlyNames and FullHierarchyNames, added parentOrganizationId attribute to organizations

This commit is contained in:
Jonathan Treffler 2024-11-26 18:19:05 +01:00
parent 225072bff7
commit 89ff5415dd
15 changed files with 321 additions and 47 deletions

View file

@ -0,0 +1,34 @@
<?php
namespace OCA\OrganizationFolders\Model;
use OCP\IUserManager;
use OCP\IGroupManager;
use OCA\OrganizationFolders\Enum\PrincipalType;
use OCA\OrganizationFolders\OrganizationProvider\OrganizationProviderManager;
class PrincipalFactory {
public function __construct(
protected IUserManager $userManager,
protected IGroupManager $groupManager,
protected OrganizationProviderManager $organizationProviderManager,
) {
}
public function buildPrincipal(PrincipalType $type, string $id): Principal {
if($type === PrincipalType::USER) {
return new UserPrincipal($this->userManager, $id);
} else if ($type === PrincipalType::GROUP) {
return new GroupPrincipal($this->groupManager, $id);
} else if ($type === PrincipalType::ROLE) {
[$organizationProviderId, $roleId] = explode(":", $id, 2);
if(!(isset($organizationProviderId) && isset($roleId))) {
throw new \Exception("Invalid id format for principal of type role");
}
return new RolePrincipal($this->organizationProviderManager, $organizationProviderId, $roleId);
} else {
throw new \Exception("invalid PrincipalType");
}
}
}