Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit e3872ab

Browse files
committed
Sharing: pass original node down to the rightsManager, and send an event when updating/remove rights on user or roles.
1 parent b8449cb commit e3872ab

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

core/src/plugins/action.share/src/ShareCenter.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ public function switchAction(ServerRequestInterface &$requestInterface, Response
648648
$users = array(); $groups = array();
649649
$this->getRightsManager()->createUsersFromParameters($httpVars, $users, $groups);
650650

651-
$result = $this->createSharedRepository($httpVars, $isUpdate, $users, $groups);
651+
$result = $this->createSharedRepository($httpVars, $isUpdate, $users, $groups, $ajxpNode);
652652

653653
if (is_object($result) && $result instanceof Repository) {
654654

@@ -1573,7 +1573,7 @@ public function createSharedMinisite($httpVars, &$update)
15731573
$users = array(); $groups = array();
15741574
$users[$hiddenUserEntry["ID"]] = $hiddenUserEntry;
15751575

1576-
$newRepo = $this->createSharedRepository($httpVars, $repoUpdate, $users, $groups);
1576+
$newRepo = $this->createSharedRepository($httpVars, $repoUpdate, $users, $groups, $userSelection->getUniqueNode());
15771577

15781578
$shareObject->setParentRepositoryId($this->repository->getId());
15791579
$shareObject->attachToRepository($newRepo->getId());
@@ -1619,10 +1619,11 @@ public function createSharedMinisite($httpVars, &$update)
16191619
* @param bool $update
16201620
* @param array $users
16211621
* @param array $groups
1622+
* @param AJXP_Node $originalNode
16221623
* @return Repository
16231624
* @throws \Exception
16241625
*/
1625-
public function createSharedRepository($httpVars, &$update, $users=array(), $groups=array())
1626+
public function createSharedRepository($httpVars, &$update, $users=array(), $groups=array(), $originalNode = null)
16261627
{
16271628
// ERRORS
16281629
// 100 : missing args
@@ -1642,7 +1643,7 @@ public function createSharedRepository($httpVars, &$update, $users=array(), $gro
16421643
$newRepo = $this->createOrLoadSharedRepository($httpVars, $update);
16431644

16441645
$selection = UserSelection::fromContext($this->currentContext, $httpVars);
1645-
$this->getRightsManager()->assignSharedRepositoryPermissions($currentRepo, $newRepo, $update, $users, $groups, $selection);
1646+
$this->getRightsManager()->assignSharedRepositoryPermissions($currentRepo, $newRepo, $update, $users, $groups, $selection, $originalNode);
16461647

16471648
// HANDLE WATCHES ON CHILDREN AND PARENT
16481649
foreach($users as $userName => $userEntry){
@@ -1773,7 +1774,7 @@ public function shareNode(ContextInterface $ctx, $ajxpNode, $httpVars, &$update)
17731774
return null;
17741775
}
17751776

1776-
$newRepo = $this->createSharedRepository($httpVars, $update, $users, $groups);
1777+
$newRepo = $this->createSharedRepository($httpVars, $update, $users, $groups, $ajxpNode);
17771778

17781779
foreach($shareObjects as $shareObject){
17791780

core/src/plugins/action.share/src/Store/ShareRightsManager.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,10 @@ public function computeSharedRepositoryAccessRights($repoId, $mixUsersAndGroups,
409409
* @param array $users
410410
* @param array $groups
411411
* @param \Pydio\Access\Core\Model\UserSelection $selection
412+
* @param AJXP_Node $originalNode
412413
* @throws \Exception
413414
*/
414-
public function assignSharedRepositoryPermissions($parentRepository, $childRepository, $isUpdate, $users, $groups, $selection){
415+
public function assignSharedRepositoryPermissions($parentRepository, $childRepository, $isUpdate, $users, $groups, $selection, $originalNode = null){
415416

416417
$childRepoId = $childRepository->getId();
417418
if($isUpdate){
@@ -458,13 +459,19 @@ public function assignSharedRepositoryPermissions($parentRepository, $childRepos
458459
}
459460

460461
$userObject->save("superuser");
462+
if(!empty($originalNode)){
463+
Controller::applyHook("node.share.assign_right", array($this->context, $userObject, $childRepository, $originalNode));
464+
}
461465
}
462466

463467
foreach ($groups as $group => $groupEntry) {
464468
$r = $groupEntry["RIGHT"];
465469
$grRole = RolesService::getOrCreateRole($group, $this->context->hasUser() ? $this->context->getUser()->getGroupPath() : "/");
466470
$grRole->setAcl($childRepoId, $r);
467471
RolesService::updateRole($grRole);
472+
if(!empty($originalNode)) {
473+
Controller::applyHook("node.share.assign_right", array($this->context, $group, $childRepository, $originalNode));
474+
}
468475
}
469476

470477
}
@@ -491,6 +498,7 @@ public function unregisterRemovedUsers($repoId, $newUsers, $newGroups, $watcherN
491498
$userObject = UsersService::getUserById($user, false);
492499
$userObject->getPersonalRole()->setAcl($repoId, "");
493500
$userObject->save("superuser");
501+
Controller::applyHook("node.share.remove_right", array($this->context, $userObject, $repoId));
494502
}
495503
if($this->watcher !== false && $watcherNode !== null){
496504
$this->watcher->removeWatchFromFolder(
@@ -509,6 +517,7 @@ public function unregisterRemovedUsers($repoId, $newUsers, $newGroups, $watcherN
509517
if ($role !== false) {
510518
$role->setAcl($repoId, "");
511519
RolesService::updateRole($role);
520+
Controller::applyHook("node.share.remove_right", array($this->context, $groupId, $repoId));
512521
}
513522
}
514523
}

0 commit comments

Comments
 (0)