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

added user-has-manager-permissions dav prop; added principal model and simplified the ACL code with it

This commit is contained in:
Jonathan Treffler 2024-11-12 15:36:07 +01:00
parent 72fbc9e20e
commit 8bfa9dfa29
11 changed files with 172 additions and 114 deletions

View file

@ -8,31 +8,39 @@ use OCA\OrganizationFolders\Interface\TableSerializable;
use OCP\AppFramework\Db\Entity;
use OCA\OrganizationFolders\Enum\MemberPermissionLevel;
use OCA\OrganizationFolders\Enum\MemberType;
use OCA\OrganizationFolders\Enum\PrincipalType;
use OCA\OrganizationFolders\Model\Principal;
class ResourceMember extends Entity implements JsonSerializable, TableSerializable {
protected $resourceId;
protected $permissionLevel;
protected $type;
protected $principal;
protected $principalType;
protected $principalId;
protected $createdTimestamp;
protected $lastUpdatedTimestamp;
public function __construct() {
$this->addType('resourceId','integer');
$this->addType('permissionLevel','integer');
$this->addType('type','integer');
$this->addType('principalType','integer');
$this->addType('createdTimestamp','integer');
$this->addType('lastUpdatedTimestamp','integer');
}
public function getPrincipal(): Principal {
return new Principal(PrincipalType::from($this->principalType), $this->principalId);
}
public function setPrincipal(Principal $principal) {
$this->setPrincipalType($principal->getType()->value);
$this->setPrincipalId($principal->getId());
}
public function jsonSerialize(): array {
return [
'id' => $this->id,
'resourceId' => $this->resourceId,
'permissionLevel' => $this->permissionLevel,
'type' => $this->type,
'principal' => $this->principal,
'principal' => $this->getPrincipal(),
'createdTimestamp' => $this->createdTimestamp,
'lastUpdatedTimestamp' => $this->lastUpdatedTimestamp,
];
@ -43,29 +51,10 @@ class ResourceMember extends Entity implements JsonSerializable, TableSerializab
'Id' => $this->id,
'Resource Id' => $this->resourceId,
'Permission Level' => MemberPermissionLevel::from($this->permissionLevel)->name,
'Type' => MemberType::from($this->type)->name,
'Principal' => $this->principal,
'Principal Type' => PrincipalType::from($this->principalType)->name,
'Principal Id' => $this->principalId,
'Created' => $this->createdTimestamp,
'LastUpdated' => $this->lastUpdatedTimestamp,
];
}
public function getParsedPrincipal() {
if($this->type === MemberType::USER->value) {
return [
"userId" => $this->principal,
];
} else if($this->type === MemberType::GROUP->value) {
return [
"groupId" => $this->principal,
];
} else if($this->type === MemberType::ROLE->value) {
[$organizationProviderId, $roleId] = explode(":", $this->principal, 2);
return [
"organizationProviderId" => $organizationProviderId,
"roleId" => $roleId,
];
}
}
}