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

Added inherit managers attribute to resources

This commit is contained in:
Jonathan Treffler 2024-11-06 17:32:33 +01:00
parent f7b3b2f255
commit fdb4b8fc76
8 changed files with 65 additions and 4 deletions

View file

@ -17,7 +17,8 @@ class CreateResource extends BaseCommand {
->addOption('organization-folder', null, InputOption::VALUE_REQUIRED, 'Id of organization folder to create resource in') ->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('type', null, InputOption::VALUE_REQUIRED, 'Type of resource (valid values: folder)')
->addOption('name', null, InputOption::VALUE_REQUIRED, 'Name of resource') ->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)'); ->addOption('parent-resource', null, InputOption::VALUE_OPTIONAL, 'Id of parent resource (leave out if creating at top level in organization folder)')
->addOption('inherit-managers', null, InputOption::VALUE_REQUIRED, 'Wether managers of the parent level (parent resource or organization folder for top level resources) should have management permissions');
// folder type options // folder type options
$this $this
@ -33,6 +34,7 @@ class CreateResource extends BaseCommand {
$type = $input->getOption('type'); $type = $input->getOption('type');
$name = $input->getOption('name'); $name = $input->getOption('name');
$parentResource = $input->getOption('parent-resource'); $parentResource = $input->getOption('parent-resource');
$inheritManagers = $input->getOption('inherit-managers') === true || $input->getOption('inherit-managers') === "true";
$membersAclPermission = $input->getOption('members-acl-permission'); $membersAclPermission = $input->getOption('members-acl-permission');
$managersAclPermission = $input->getOption('managers-acl-permission'); $managersAclPermission = $input->getOption('managers-acl-permission');
@ -44,6 +46,8 @@ class CreateResource extends BaseCommand {
organizationFolderId: $organizationFolder, organizationFolderId: $organizationFolder,
name: $name, name: $name,
parentResourceId: $parentResource, parentResourceId: $parentResource,
active: true,
inheritManagers : $inheritManagers,
membersAclPermission: $membersAclPermission, membersAclPermission: $membersAclPermission,
managersAclPermission: $managersAclPermission, managersAclPermission: $managersAclPermission,

View file

@ -16,7 +16,9 @@ class UpdateResource extends BaseCommand {
->setName('organization-folders:resources:update') ->setName('organization-folders:resources:update')
->setDescription('Update a resource') ->setDescription('Update a resource')
->addArgument('id', InputArgument::REQUIRED, 'Id of the resource to update') ->addArgument('id', InputArgument::REQUIRED, 'Id of the resource to update')
->addOption('name', null, InputOption::VALUE_OPTIONAL, 'New name of resource'); ->addOption('name', null, InputOption::VALUE_OPTIONAL, 'New name of resource')
->addOption('active', null, InputOption::VALUE_OPTIONAL, 'Activate/deactivate resource')
->addOption('inherit-managers', null, InputOption::VALUE_OPTIONAL, 'Set wether managers of the parent level (parent resource or organization folder for top level resources) should have management permissions');
// folder type options // folder type options
$this $this
@ -31,6 +33,16 @@ class UpdateResource extends BaseCommand {
$id = $input->getArgument('id'); $id = $input->getArgument('id');
$name = $input->getOption('name'); $name = $input->getOption('name');
$activeOption = $input->getOption('active');
if(!is_null($activeOption)) {
$active = $activeOption === true || $activeOption === "true";
}
$inheritManagersOption = $input->getOption('inherit-managers');
if(!is_null($inheritManagersOption)) {
$inheritManagers = $inheritManagersOption === true || $inheritManagersOption === "true";
}
$membersAclPermission = $input->getOption('members-acl-permission'); $membersAclPermission = $input->getOption('members-acl-permission');
$managersAclPermission = $input->getOption('managers-acl-permission'); $managersAclPermission = $input->getOption('managers-acl-permission');
$inheritedAclPermission = $input->getOption('inherited-acl-permission'); $inheritedAclPermission = $input->getOption('inherited-acl-permission');
@ -39,6 +51,8 @@ class UpdateResource extends BaseCommand {
$resource = $this->resourceService->update( $resource = $this->resourceService->update(
id: $id, id: $id,
name: $name, name: $name,
active: $active,
inheritManagers: $inheritManagers,
membersAclPermission: $membersAclPermission, membersAclPermission: $membersAclPermission,
managersAclPermission: $managersAclPermission, managersAclPermission: $managersAclPermission,

View file

@ -24,6 +24,7 @@ class FolderResource extends Resource {
$instance->setOrganizationFolderId($row["organization_folder_id"]); $instance->setOrganizationFolderId($row["organization_folder_id"]);
$instance->setName($row["name"]); $instance->setName($row["name"]);
$instance->setActive($row["active"]); $instance->setActive($row["active"]);
$instance->setInheritManagers($row["inherit_managers"]);
$instance->setLastUpdatedTimestamp($row["last_updated_timestamp"]); $instance->setLastUpdatedTimestamp($row["last_updated_timestamp"]);
$instance->setMembersAclPermission($row["members_acl_permission"]); $instance->setMembersAclPermission($row["members_acl_permission"]);
$instance->setManagersAclPermission($row["managers_acl_permission"]); $instance->setManagersAclPermission($row["managers_acl_permission"]);
@ -43,6 +44,7 @@ class FolderResource extends Resource {
'type' => "folder", 'type' => "folder",
'name' => $this->name, 'name' => $this->name,
'active' => $this->active, 'active' => $this->active,
'inheritManagers' => $this->inheritManagers,
'lastUpdatedTimestamp' => $this->lastUpdatedTimestamp, 'lastUpdatedTimestamp' => $this->lastUpdatedTimestamp,
'membersAclPermission' => $this->membersAclPermission, 'membersAclPermission' => $this->membersAclPermission,
@ -58,6 +60,7 @@ class FolderResource extends Resource {
'Name' => $this->name, 'Name' => $this->name,
'Type' => "Folder", 'Type' => "Folder",
'Active' => ((bool)$this->active) ? 'yes' : 'no', 'Active' => ((bool)$this->active) ? 'yes' : 'no',
'Inherit Managers' => ((bool)$this->inheritManagers) ? 'yes' : 'no',
'Last Updated' => $this->lastUpdatedTimestamp, 'Last Updated' => $this->lastUpdatedTimestamp,
'Members ACL Permission' => $this->membersAclPermission, 'Members ACL Permission' => $this->membersAclPermission,

View file

@ -12,12 +12,14 @@ abstract class Resource extends Entity implements JsonSerializable, TableSeriali
protected $parentResource; protected $parentResource;
protected $name; protected $name;
protected $active; protected $active;
protected $inheritManagers;
protected $lastUpdatedTimestamp; protected $lastUpdatedTimestamp;
public function __construct() { public function __construct() {
$this->addType('organizationFolderId','integer'); $this->addType('organizationFolderId','integer');
$this->addType('parentResource','integer'); $this->addType('parentResource','integer');
$this->addType('active','bool'); $this->addType('active','bool');
$this->addType('inheritManagers','bool');
$this->addType('lastUpdatedTimestamp','integer'); $this->addType('lastUpdatedTimestamp','integer');
} }

View file

@ -17,7 +17,7 @@ class ResourceMapper extends QBMapper {
public const RESOURCES_TABLE = "organizationfolders_resources"; public const RESOURCES_TABLE = "organizationfolders_resources";
public const FOLDER_RESOURCES_TABLE = "organizationfolders_folder_resources"; public const FOLDER_RESOURCES_TABLE = "organizationfolders_folder_resources";
private const updateableResourceProperties = ["parentResource", "active", "name", "lastUpdatedTimestamp"]; private const updateableResourceProperties = ["parentResource", "active", "name", "inheritManagers", "lastUpdatedTimestamp"];
private const updateableFolderResourceProperties = ["membersAclPermission", "managersAclPermission", "inheritedAclPermission", "fileId"]; private const updateableFolderResourceProperties = ["membersAclPermission", "managersAclPermission", "inheritedAclPermission", "fileId"];
public function __construct(IDBConnection $db) { public function __construct(IDBConnection $db) {

View file

@ -49,4 +49,23 @@ class ResourceMember extends Entity implements JsonSerializable, TableSerializab
'LastUpdated' => $this->lastUpdatedTimestamp, '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,
];
}
}
} }

View file

@ -49,6 +49,9 @@ class Version000000Date20241014120000 extends SimpleMigrationStep {
$table->addColumn('active', Types::BOOLEAN, [ $table->addColumn('active', Types::BOOLEAN, [
'notnull' => true, 'notnull' => true,
]); ]);
$table->addColumn('inherit_managers', Types::BOOLEAN, [
'notnull' => true,
]);
$table->addColumn('last_updated_timestamp', Types::BIGINT, [ $table->addColumn('last_updated_timestamp', Types::BIGINT, [
'notnull' => true, 'notnull' => true,
]); ]);

View file

@ -67,6 +67,7 @@ class ResourceService {
string $name, string $name,
?int $parentResourceId = null, ?int $parentResourceId = null,
bool $active = true, bool $active = true,
bool $inheritManagers = true,
?int $membersAclPermission = null, ?int $membersAclPermission = null,
?int $managersAclPermission = null, ?int $managersAclPermission = null,
@ -82,6 +83,7 @@ class ResourceService {
$resource->setOrganizationFolderId($organizationFolderId); $resource->setOrganizationFolderId($organizationFolderId);
$resource->setName($name); $resource->setName($name);
$resource->setActive($active); $resource->setActive($active);
$resource->setInheritManagers($inheritManagers);
$resource->setLastUpdatedTimestamp(time()); $resource->setLastUpdatedTimestamp(time());
if(isset($parentResourceId)) { if(isset($parentResourceId)) {
@ -131,6 +133,7 @@ class ResourceService {
?string $name = null, ?string $name = null,
?int $parentResource = null, ?int $parentResource = null,
?bool $active = null, ?bool $active = null,
?bool $inheritManagers = null,
?int $membersAclPermission = null, ?int $membersAclPermission = null,
?int $managersAclPermission = null, ?int $managersAclPermission = null,
@ -160,6 +163,10 @@ class ResourceService {
$resource->setActive($active); $resource->setActive($active);
} }
if(isset($inheritManagers)) {
$resource->setInheritManagers($inheritManagers);
}
if($resource->getType() === "folder") { if($resource->getType() === "folder") {
if(isset($membersAclPermission)) { if(isset($membersAclPermission)) {
$resource->setMembersAclPermission($membersAclPermission); $resource->setMembersAclPermission($membersAclPermission);
@ -231,7 +238,8 @@ class ResourceService {
} else if($resourceMember->getType() === MemberType::GROUP->value) { } else if($resourceMember->getType() === MemberType::GROUP->value) {
$mapping = $this->userMappingManager->mappingFromId("group", $resourceMember->getPrincipal()); $mapping = $this->userMappingManager->mappingFromId("group", $resourceMember->getPrincipal());
} else if($resourceMember->getType() === MemberType::ROLE->value) { } else if($resourceMember->getType() === MemberType::ROLE->value) {
[$organizationProviderId, $roleId] = explode(":", $resourceMember->getPrincipal(), 2); ['organizationProviderId' => $organizationProviderId, 'roleId' => $roleId] = $resourceMember->getParsedPrincipal();
$organizationProvider = $this->organizationProviderManager->getOrganizationProvider($organizationProviderId); $organizationProvider = $this->organizationProviderManager->getOrganizationProvider($organizationProviderId);
$role = $organizationProvider->getRole($roleId); $role = $organizationProvider->getRole($roleId);
$mapping = $this->userMappingManager->mappingFromId("group", $role->getMembersGroup()); $mapping = $this->userMappingManager->mappingFromId("group", $role->getMembersGroup());
@ -296,6 +304,14 @@ class ResourceService {
return $subResources; return $subResources;
} }
public function getParentResource(Resource $resource): ?Resource {
if(!is_null($resource->getParentResource())) {
return $this->find($resource->getParentResource());
} else {
return null;
}
}
public function deleteById(int $id): Resource { public function deleteById(int $id): Resource {
try { try {
$resource = $this->mapper->find($id); $resource = $this->mapper->find($id);