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

Commit

Permalink
Sharing: pass original node down to the rightsManager, and send an ev…
Browse files Browse the repository at this point in the history
…ent when updating/remove rights on user or roles.
  • Loading branch information
cdujeu committed Sep 30, 2016
1 parent b8449cb commit e3872ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
11 changes: 6 additions & 5 deletions core/src/plugins/action.share/src/ShareCenter.php
Expand Up @@ -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) {

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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
Expand All @@ -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){
Expand Down Expand Up @@ -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){

Expand Down
11 changes: 10 additions & 1 deletion core/src/plugins/action.share/src/Store/ShareRightsManager.php
Expand Up @@ -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){
Expand Down Expand Up @@ -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));
}
}

}
Expand All @@ -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(
Expand All @@ -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));
}
}
}
Expand Down

0 comments on commit e3872ab

Please sign in to comment.