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:
parent
f7b3b2f255
commit
fdb4b8fc76
8 changed files with 65 additions and 4 deletions
|
@ -17,7 +17,8 @@ class CreateResource extends BaseCommand {
|
|||
->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)');
|
||||
->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
|
||||
$this
|
||||
|
@ -33,6 +34,7 @@ class CreateResource extends BaseCommand {
|
|||
$type = $input->getOption('type');
|
||||
$name = $input->getOption('name');
|
||||
$parentResource = $input->getOption('parent-resource');
|
||||
$inheritManagers = $input->getOption('inherit-managers') === true || $input->getOption('inherit-managers') === "true";
|
||||
|
||||
$membersAclPermission = $input->getOption('members-acl-permission');
|
||||
$managersAclPermission = $input->getOption('managers-acl-permission');
|
||||
|
@ -44,6 +46,8 @@ class CreateResource extends BaseCommand {
|
|||
organizationFolderId: $organizationFolder,
|
||||
name: $name,
|
||||
parentResourceId: $parentResource,
|
||||
active: true,
|
||||
inheritManagers : $inheritManagers,
|
||||
|
||||
membersAclPermission: $membersAclPermission,
|
||||
managersAclPermission: $managersAclPermission,
|
||||
|
|
|
@ -16,7 +16,9 @@ class UpdateResource extends BaseCommand {
|
|||
->setName('organization-folders:resources:update')
|
||||
->setDescription('Update a resource')
|
||||
->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
|
||||
$this
|
||||
|
@ -31,6 +33,16 @@ class UpdateResource extends BaseCommand {
|
|||
$id = $input->getArgument('id');
|
||||
$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');
|
||||
$managersAclPermission = $input->getOption('managers-acl-permission');
|
||||
$inheritedAclPermission = $input->getOption('inherited-acl-permission');
|
||||
|
@ -39,6 +51,8 @@ class UpdateResource extends BaseCommand {
|
|||
$resource = $this->resourceService->update(
|
||||
id: $id,
|
||||
name: $name,
|
||||
active: $active,
|
||||
inheritManagers: $inheritManagers,
|
||||
|
||||
membersAclPermission: $membersAclPermission,
|
||||
managersAclPermission: $managersAclPermission,
|
||||
|
|
|
@ -24,6 +24,7 @@ class FolderResource extends Resource {
|
|||
$instance->setOrganizationFolderId($row["organization_folder_id"]);
|
||||
$instance->setName($row["name"]);
|
||||
$instance->setActive($row["active"]);
|
||||
$instance->setInheritManagers($row["inherit_managers"]);
|
||||
$instance->setLastUpdatedTimestamp($row["last_updated_timestamp"]);
|
||||
$instance->setMembersAclPermission($row["members_acl_permission"]);
|
||||
$instance->setManagersAclPermission($row["managers_acl_permission"]);
|
||||
|
@ -43,6 +44,7 @@ class FolderResource extends Resource {
|
|||
'type' => "folder",
|
||||
'name' => $this->name,
|
||||
'active' => $this->active,
|
||||
'inheritManagers' => $this->inheritManagers,
|
||||
'lastUpdatedTimestamp' => $this->lastUpdatedTimestamp,
|
||||
|
||||
'membersAclPermission' => $this->membersAclPermission,
|
||||
|
@ -58,6 +60,7 @@ class FolderResource extends Resource {
|
|||
'Name' => $this->name,
|
||||
'Type' => "Folder",
|
||||
'Active' => ((bool)$this->active) ? 'yes' : 'no',
|
||||
'Inherit Managers' => ((bool)$this->inheritManagers) ? 'yes' : 'no',
|
||||
'Last Updated' => $this->lastUpdatedTimestamp,
|
||||
|
||||
'Members ACL Permission' => $this->membersAclPermission,
|
||||
|
|
|
@ -12,12 +12,14 @@ abstract class Resource extends Entity implements JsonSerializable, TableSeriali
|
|||
protected $parentResource;
|
||||
protected $name;
|
||||
protected $active;
|
||||
protected $inheritManagers;
|
||||
protected $lastUpdatedTimestamp;
|
||||
|
||||
public function __construct() {
|
||||
$this->addType('organizationFolderId','integer');
|
||||
$this->addType('parentResource','integer');
|
||||
$this->addType('active','bool');
|
||||
$this->addType('inheritManagers','bool');
|
||||
$this->addType('lastUpdatedTimestamp','integer');
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ class ResourceMapper extends QBMapper {
|
|||
public const RESOURCES_TABLE = "organizationfolders_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"];
|
||||
|
||||
public function __construct(IDBConnection $db) {
|
||||
|
|
|
@ -49,4 +49,23 @@ class ResourceMember extends Entity implements JsonSerializable, TableSerializab
|
|||
'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,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,6 +49,9 @@ class Version000000Date20241014120000 extends SimpleMigrationStep {
|
|||
$table->addColumn('active', Types::BOOLEAN, [
|
||||
'notnull' => true,
|
||||
]);
|
||||
$table->addColumn('inherit_managers', Types::BOOLEAN, [
|
||||
'notnull' => true,
|
||||
]);
|
||||
$table->addColumn('last_updated_timestamp', Types::BIGINT, [
|
||||
'notnull' => true,
|
||||
]);
|
||||
|
|
|
@ -67,6 +67,7 @@ class ResourceService {
|
|||
string $name,
|
||||
?int $parentResourceId = null,
|
||||
bool $active = true,
|
||||
bool $inheritManagers = true,
|
||||
|
||||
?int $membersAclPermission = null,
|
||||
?int $managersAclPermission = null,
|
||||
|
@ -82,6 +83,7 @@ class ResourceService {
|
|||
$resource->setOrganizationFolderId($organizationFolderId);
|
||||
$resource->setName($name);
|
||||
$resource->setActive($active);
|
||||
$resource->setInheritManagers($inheritManagers);
|
||||
$resource->setLastUpdatedTimestamp(time());
|
||||
|
||||
if(isset($parentResourceId)) {
|
||||
|
@ -131,6 +133,7 @@ class ResourceService {
|
|||
?string $name = null,
|
||||
?int $parentResource = null,
|
||||
?bool $active = null,
|
||||
?bool $inheritManagers = null,
|
||||
|
||||
?int $membersAclPermission = null,
|
||||
?int $managersAclPermission = null,
|
||||
|
@ -160,6 +163,10 @@ class ResourceService {
|
|||
$resource->setActive($active);
|
||||
}
|
||||
|
||||
if(isset($inheritManagers)) {
|
||||
$resource->setInheritManagers($inheritManagers);
|
||||
}
|
||||
|
||||
if($resource->getType() === "folder") {
|
||||
if(isset($membersAclPermission)) {
|
||||
$resource->setMembersAclPermission($membersAclPermission);
|
||||
|
@ -231,7 +238,8 @@ class ResourceService {
|
|||
} else if($resourceMember->getType() === MemberType::GROUP->value) {
|
||||
$mapping = $this->userMappingManager->mappingFromId("group", $resourceMember->getPrincipal());
|
||||
} else if($resourceMember->getType() === MemberType::ROLE->value) {
|
||||
[$organizationProviderId, $roleId] = explode(":", $resourceMember->getPrincipal(), 2);
|
||||
['organizationProviderId' => $organizationProviderId, 'roleId' => $roleId] = $resourceMember->getParsedPrincipal();
|
||||
|
||||
$organizationProvider = $this->organizationProviderManager->getOrganizationProvider($organizationProviderId);
|
||||
$role = $organizationProvider->getRole($roleId);
|
||||
$mapping = $this->userMappingManager->mappingFromId("group", $role->getMembersGroup());
|
||||
|
@ -296,6 +304,14 @@ class ResourceService {
|
|||
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 {
|
||||
try {
|
||||
$resource = $this->mapper->find($id);
|
||||
|
|
Loading…
Reference in a new issue