Permalink
Browse files

Sharing: pass original node down to the rightsManager, and send an ev…

…ent when updating/remove rights on user or roles.
  • Loading branch information...
1 parent b8449cb commit e3872abb3b5c2d3af76ad5c480d26dfcc4e573ed @cdujeu cdujeu committed Sep 30, 2016
@@ -648,7 +648,7 @@ public function switchAction(ServerRequestInterface &$requestInterface, Response
$users = array(); $groups = array();
$this->getRightsManager()->createUsersFromParameters($httpVars, $users, $groups);
- $result = $this->createSharedRepository($httpVars, $isUpdate, $users, $groups);
+ $result = $this->createSharedRepository($httpVars, $isUpdate, $users, $groups, $ajxpNode);
if (is_object($result) && $result instanceof Repository) {
@@ -1573,7 +1573,7 @@ public function createSharedMinisite($httpVars, &$update)
$users = array(); $groups = array();
$users[$hiddenUserEntry["ID"]] = $hiddenUserEntry;
- $newRepo = $this->createSharedRepository($httpVars, $repoUpdate, $users, $groups);
+ $newRepo = $this->createSharedRepository($httpVars, $repoUpdate, $users, $groups, $userSelection->getUniqueNode());
$shareObject->setParentRepositoryId($this->repository->getId());
$shareObject->attachToRepository($newRepo->getId());
@@ -1619,10 +1619,11 @@ public function createSharedMinisite($httpVars, &$update)
* @param bool $update
* @param array $users
* @param array $groups
+ * @param AJXP_Node $originalNode
* @return Repository
* @throws \Exception
*/
- public function createSharedRepository($httpVars, &$update, $users=array(), $groups=array())
+ public function createSharedRepository($httpVars, &$update, $users=array(), $groups=array(), $originalNode = null)
{
// ERRORS
// 100 : missing args
@@ -1642,7 +1643,7 @@ public function createSharedRepository($httpVars, &$update, $users=array(), $gro
$newRepo = $this->createOrLoadSharedRepository($httpVars, $update);
$selection = UserSelection::fromContext($this->currentContext, $httpVars);
- $this->getRightsManager()->assignSharedRepositoryPermissions($currentRepo, $newRepo, $update, $users, $groups, $selection);
+ $this->getRightsManager()->assignSharedRepositoryPermissions($currentRepo, $newRepo, $update, $users, $groups, $selection, $originalNode);
// HANDLE WATCHES ON CHILDREN AND PARENT
foreach($users as $userName => $userEntry){
@@ -1773,7 +1774,7 @@ public function shareNode(ContextInterface $ctx, $ajxpNode, $httpVars, &$update)
return null;
}
- $newRepo = $this->createSharedRepository($httpVars, $update, $users, $groups);
+ $newRepo = $this->createSharedRepository($httpVars, $update, $users, $groups, $ajxpNode);
foreach($shareObjects as $shareObject){
@@ -409,9 +409,10 @@ public function computeSharedRepositoryAccessRights($repoId, $mixUsersAndGroups,
* @param array $users
* @param array $groups
* @param \Pydio\Access\Core\Model\UserSelection $selection
+ * @param AJXP_Node $originalNode
* @throws \Exception
*/
- public function assignSharedRepositoryPermissions($parentRepository, $childRepository, $isUpdate, $users, $groups, $selection){
+ public function assignSharedRepositoryPermissions($parentRepository, $childRepository, $isUpdate, $users, $groups, $selection, $originalNode = null){
$childRepoId = $childRepository->getId();
if($isUpdate){
@@ -458,13 +459,19 @@ public function assignSharedRepositoryPermissions($parentRepository, $childRepos
}
$userObject->save("superuser");
+ if(!empty($originalNode)){
+ Controller::applyHook("node.share.assign_right", array($this->context, $userObject, $childRepository, $originalNode));
+ }
}
foreach ($groups as $group => $groupEntry) {
$r = $groupEntry["RIGHT"];
$grRole = RolesService::getOrCreateRole($group, $this->context->hasUser() ? $this->context->getUser()->getGroupPath() : "/");
$grRole->setAcl($childRepoId, $r);
RolesService::updateRole($grRole);
+ if(!empty($originalNode)) {
+ Controller::applyHook("node.share.assign_right", array($this->context, $group, $childRepository, $originalNode));
+ }
}
}
@@ -491,6 +498,7 @@ public function unregisterRemovedUsers($repoId, $newUsers, $newGroups, $watcherN
$userObject = UsersService::getUserById($user, false);
$userObject->getPersonalRole()->setAcl($repoId, "");
$userObject->save("superuser");
+ Controller::applyHook("node.share.remove_right", array($this->context, $userObject, $repoId));
}
if($this->watcher !== false && $watcherNode !== null){
$this->watcher->removeWatchFromFolder(
@@ -509,6 +517,7 @@ public function unregisterRemovedUsers($repoId, $newUsers, $newGroups, $watcherN
if ($role !== false) {
$role->setAcl($repoId, "");
RolesService::updateRole($role);
+ Controller::applyHook("node.share.remove_right", array($this->context, $groupId, $repoId));
}
}
}

0 comments on commit e3872ab

Please sign in to comment.