mirror of
https://github.com/verdigado/organization_folders.git
synced 2024-11-23 21:20:28 +01:00
Added groupfolderManager to handle overwriting groupfolder members
This commit is contained in:
parent
f85a93aa3a
commit
b653a751dc
5 changed files with 94 additions and 10 deletions
|
@ -43,7 +43,7 @@ class CreateResource extends BaseCommand {
|
||||||
type: $type,
|
type: $type,
|
||||||
organizationFolderId: $organizationFolder,
|
organizationFolderId: $organizationFolder,
|
||||||
name: $name,
|
name: $name,
|
||||||
parentResource: $parentResource,
|
parentResourceId: $parentResource,
|
||||||
|
|
||||||
membersAclPermission: $membersAclPermission,
|
membersAclPermission: $membersAclPermission,
|
||||||
managersAclPermission: $managersAclPermission,
|
managersAclPermission: $managersAclPermission,
|
||||||
|
|
|
@ -14,10 +14,10 @@ use OCA\GroupFolders\Folder\FolderManager;
|
||||||
|
|
||||||
class ACLManager {
|
class ACLManager {
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private IDBConnection $db,
|
protected IDBConnection $db,
|
||||||
private FolderManager $folderManager,
|
protected FolderManager $folderManager,
|
||||||
private IUserMappingManager $userMappingManager,
|
protected IUserMappingManager $userMappingManager,
|
||||||
private RuleManager $ruleManager,
|
protected RuleManager $ruleManager,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ class ACLManager {
|
||||||
return array_map($this->createRuleEntityFromRow(...), $rows);
|
return array_map($this->createRuleEntityFromRow(...), $rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function ruleMappingComparison(Rule $rule1, Rule $rule2) {
|
protected function ruleMappingComparison(Rule $rule1, Rule $rule2): int {
|
||||||
$mapping1 = $rule1->getUserMapping();
|
$mapping1 = $rule1->getUserMapping();
|
||||||
$mapping2 = $rule2->getUserMapping();
|
$mapping2 = $rule2->getUserMapping();
|
||||||
|
|
||||||
|
|
84
lib/Manager/GroupfolderManager.php
Normal file
84
lib/Manager/GroupfolderManager.php
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace OCA\OrganizationFolders\Manager;
|
||||||
|
|
||||||
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||||
|
use OCP\IDBConnection;
|
||||||
|
use OCP\EventDispatcher\IEventDispatcher;
|
||||||
|
use OCP\Log\Audit\CriticalActionPerformedEvent;
|
||||||
|
|
||||||
|
use OCA\GroupFolders\Folder\FolderManager;
|
||||||
|
|
||||||
|
class GroupfolderManager {
|
||||||
|
public function __construct(
|
||||||
|
protected IDBConnection $db,
|
||||||
|
protected FolderManager $folderManager,
|
||||||
|
protected IEventDispatcher $eventDispatcher,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMemberGroups(int $id) {
|
||||||
|
$qb = $this->db->getQueryBuilder();
|
||||||
|
$qb->select('group_id', 'permissions')
|
||||||
|
->from('group_folders_groups')
|
||||||
|
->where($qb->expr()->eq('folder_id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
|
||||||
|
|
||||||
|
return $qb->executeQuery()->fetchAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
// the FolderManager function for this does not allow setting the permissions, defaulting to all permissions :/
|
||||||
|
public function addMemberGroup(int $folderId, string $groupId, int $permissions = \OCP\Constants::PERMISSION_ALL): void {
|
||||||
|
$qb = $this->db->getQueryBuilder();
|
||||||
|
|
||||||
|
$qb->insert('group_folders_groups')
|
||||||
|
->values([
|
||||||
|
'folder_id' => $qb->createNamedParameter($folderId, IQueryBuilder::PARAM_INT),
|
||||||
|
'group_id' => $qb->createNamedParameter($groupId),
|
||||||
|
'circle_id' => $qb->createNamedParameter(''),
|
||||||
|
'permissions' => $qb->createNamedParameter($permissions, IQueryBuilder::PARAM_INT)
|
||||||
|
]);
|
||||||
|
$qb->executeStatement();
|
||||||
|
|
||||||
|
$this->eventDispatcher->dispatchTyped(new CriticalActionPerformedEvent('The group "%s" was given access to the groupfolder with id %d', [$groupId, $folderId]));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function memberGroupIdComparison(array $memberGroup1, array $memberGroup2): int {
|
||||||
|
return $memberGroup1["group_id"] <=> $memberGroup2["group_id"];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function memberGroupComparison(array $memberGroup1, array $memberGroup2): int {
|
||||||
|
return $memberGroup1["group_id"] <=> $memberGroup2["group_id"] ?: $memberGroup1["permissions"] <=> $memberGroup2["permissions"];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function overwriteMemberGroups(int $id, array $memberGroups): array {
|
||||||
|
$existingMemberGroups = $this->getMemberGroups($id);
|
||||||
|
|
||||||
|
// new members to be added
|
||||||
|
$newMemberGroups = array_udiff($memberGroups, $existingMemberGroups, $this->memberGroupIdComparison(...));
|
||||||
|
|
||||||
|
// old members to be deleted
|
||||||
|
$removedMemberGroups = array_udiff($existingMemberGroups, $memberGroups, $this->memberGroupIdComparison(...));
|
||||||
|
|
||||||
|
$potentiallyUpdatedMemberGroups = array_uintersect($memberGroups, $existingMemberGroups, $this->memberGroupIdComparison(...));
|
||||||
|
$notUpdatedMemberGroups = array_uintersect($memberGroups, $existingMemberGroups, $this->memberGroupComparison(...));
|
||||||
|
|
||||||
|
// member groups with changed permissions
|
||||||
|
$updatedMemberGroups = array_udiff($potentiallyUpdatedMemberGroups, $notUpdatedMemberGroups, $this->memberGroupIdComparison(...));
|
||||||
|
|
||||||
|
foreach($removedMemberGroups as $removedMemberGroup) {
|
||||||
|
$this->folderManager->removeApplicableGroup($id, $removedMemberGroup["group_id"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($newMemberGroups as $newMemberGroup) {
|
||||||
|
$this->addMemberGroup($id, $newMemberGroup["group_id"], $newMemberGroup["permissions"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($updatedMemberGroups as $updatedMemberGroup) {
|
||||||
|
$this->folderManager->setGroupPermissions($id, $updatedMemberGroup["group_id"], $updatedMemberGroup["permissions"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ["created" => $newMemberGroups, "removed" => $removedMemberGroups, "updated" => $updatedMemberGroups];
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,11 +27,11 @@ class OrganizationFolder implements JsonSerializable, TableSerializable {
|
||||||
return $this->quota;
|
return $this->quota;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOrganizationProvider(): string {
|
public function getOrganizationProvider(): ?string {
|
||||||
return $this->organizationProvider;
|
return $this->organizationProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOrganizationId(): int {
|
public function getOrganizationId(): ?int {
|
||||||
return $this->organizationId;
|
return $this->organizationId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ class OrganizationFolderService {
|
||||||
name: $groupfolder["mount_point"],
|
name: $groupfolder["mount_point"],
|
||||||
quota: $groupfolder["quota"],
|
quota: $groupfolder["quota"],
|
||||||
organizationProvider: $groupfolder["organization_provider"],
|
organizationProvider: $groupfolder["organization_provider"],
|
||||||
organizationId: $groupfolder["organization_id"],
|
organizationId: (int)$groupfolder["organization_id"],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ class OrganizationFolderService {
|
||||||
name: $groupfolder["mount_point"],
|
name: $groupfolder["mount_point"],
|
||||||
quota: $groupfolder["quota"],
|
quota: $groupfolder["quota"],
|
||||||
organizationProvider: $groupfolder["organization_provider"],
|
organizationProvider: $groupfolder["organization_provider"],
|
||||||
organizationId: $groupfolder["organization_id"],
|
organizationId: (int)$groupfolder["organization_id"],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue