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

Commit 1c6b175

Browse files
committed
Send also info about the workspaces shared with current user.
Fix shares list issue - Ability for admin to list shares of a given user.
1 parent db00364 commit 1c6b175

File tree

2 files changed

+63
-8
lines changed

2 files changed

+63
-8
lines changed

core/src/plugins/access.ajxp_conf/class.ajxp_confAccessDriver.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,20 @@ public function switchAction($action, $httpVars, $fileVars)
624624
HTMLWriter::charsetHeader("application/json");
625625
$roleData = $role->getDataArray(true);
626626
$allReps = ConfService::getRepositoriesList("all", false);
627+
$sharedRepos = array();
628+
if(isSet($userObject)){
629+
// Add User shared Repositories as well
630+
$acls = $userObject->mergedRole->listAcls();
631+
if(count($acls)) {
632+
$sharedRepos = ConfService::getConfStorageImpl()->listRepositoriesWithCriteria(array(
633+
"uuid" => array_keys($acls),
634+
"parent_uuid" => AJXP_FILTER_NOT_EMPTY,
635+
"owner_user_id" => AJXP_FILTER_NOT_EMPTY
636+
));
637+
$allReps = array_merge($allReps, $sharedRepos);
638+
}
639+
}
640+
627641
$repos = array();
628642
$repoDetailed = array();
629643
// USER
@@ -642,7 +656,6 @@ public function switchAction($action, $httpVars, $fileVars)
642656
)){
643657
continue;
644658
}
645-
$repos[$repositoryId] = SystemTextEncoding::toUTF8($repositoryObject->getDisplay());
646659
$meta = array();
647660
if($repositoryObject->getOption("META_SOURCES") != null){
648661
$meta = array_keys($repositoryObject->getOption("META_SOURCES"));
@@ -653,6 +666,28 @@ public function switchAction($action, $httpVars, $fileVars)
653666
"scope" => $repositoryObject->securityScope(),
654667
"meta" => $meta
655668
);
669+
670+
if(array_key_exists($repositoryId, $sharedRepos)){
671+
$sharedRepos[$repositoryId] = SystemTextEncoding::toUTF8($repositoryObject->getDisplay());
672+
$repoParentLabel = $repoParentId = $repositoryObject->getParentId();
673+
$repoOwnerLabel = $repoOwnerId = $repositoryObject->getOwner();
674+
if(isSet($allReps[$repoParentId])){
675+
$repoParentLabel = SystemTextEncoding::toUTF8($allReps[$repoParentId]->getDisplay());
676+
}
677+
$ownerObject = ConfService::getConfStorageImpl()->createUserObject($repoOwnerId);
678+
if(isSet($ownerObject)){
679+
$repoOwnerLabel = $ownerObject->personalRole->filterParameterValue("core.conf", "USER_DISPLAY_NAME", AJXP_REPO_SCOPE_ALL, $repoOwnerId);
680+
}
681+
$repoDetailed[$repositoryId]["share"] = array(
682+
"parent_user" => $repoOwnerId,
683+
"parent_user_label" => $repoOwnerLabel,
684+
"parent_repository" => $repoParentId,
685+
"parent_repository_label" => $repoParentLabel
686+
);
687+
}else{
688+
$repos[$repositoryId] = SystemTextEncoding::toUTF8($repositoryObject->getDisplay());
689+
}
690+
656691
}
657692
// Make sure it's utf8
658693
$data = array(
@@ -663,6 +698,7 @@ public function switchAction($action, $httpVars, $fileVars)
663698
"GLOBAL_PLUGINS" => array("action.avatar", "action.disclaimer", "action.scheduler", "action.skeleton", "action.updater")
664699
),
665700
"REPOSITORIES" => $repos,
701+
"SHARED_REPOSITORIES" => $sharedRepos,
666702
"REPOSITORIES_DETAILS" => $repoDetailed,
667703
"PROFILES" => array("standard|Standard","admin|Administrator","shared|Shared","guest|Guest")
668704
)

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

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,8 @@ public function switchAction($action, $httpVars, $fileVars)
506506
$currentUser = true;
507507
if($userContext == "global" && AuthService::getLoggedUser()->isAdmin()){
508508
$currentUser = false;
509+
}else if($userContext == "user" && AuthService::getLoggedUser()->isAdmin() && !empty($httpVars["user_id"])){
510+
$currentUser = AJXP_Utils::sanitize($httpVars["user_id"], AJXP_SANITIZE_EMAILCHARS);
509511
}
510512
$nodes = $this->listSharesAsNodes("/data/repositories/$parentRepoId/shares", $currentUser, $parentRepoId);
511513

@@ -2124,18 +2126,30 @@ public function findSharesForRepo($repositoryId){
21242126
return $this->getShareStore()->findSharesForRepo($repositoryId);
21252127
}
21262128

2129+
/**
2130+
* @param bool|string $currentUser if true, currently logged user. if false all users. If string, user ID.
2131+
* @param string $parentRepositoryId
2132+
* @param null $cursor
2133+
* @return array
2134+
*/
21272135
public function listShares($currentUser = true, $parentRepositoryId="", $cursor = null){
2128-
if(AuthService::usersEnabled()){
2129-
$crtUser = ($currentUser?AuthService::getLoggedUser()->getId():'');
2136+
if($currentUser === false){
2137+
$crtUser = "";
2138+
}else if(AuthService::usersEnabled()){
2139+
if($currentUser === true){
2140+
$crtUser = AuthService::getLoggedUser()->getId();
2141+
}else{
2142+
$crtUser = $currentUser;
2143+
}
21302144
}else{
2131-
$crtUser = ($currentUser?'shared':'');
2145+
$crtUser = "shared";
21322146
}
21332147
return $this->getShareStore()->listShares($crtUser, $parentRepositoryId, $cursor);
21342148
}
21352149

21362150
/**
21372151
* @param $rootPath
2138-
* @param bool $currentUser
2152+
* @param bool|string $currentUser if true, currently logged user. if false all users. If string, user ID.
21392153
* @param string $parentRepositoryId
21402154
* @param null $cursor
21412155
* @param bool $xmlPrint
@@ -2180,11 +2194,16 @@ public function listSharesAsNodes($rootPath, $currentUser = true, $parentReposit
21802194
$meta["copy_url"] = $this->buildPublicletLink($hash);
21812195
}
21822196
$meta["shared_element_parent_repository"] = $repoObject->getParentId();
2183-
if(!empty($parent)){
2197+
if(!empty($parent)) {
21842198
$parentPath = $parent->getOption("PATH", false, $meta["owner"]);
21852199
$meta["shared_element_parent_repository_label"] = $parent->getDisplay();
21862200
}else{
2187-
$meta["shared_element_parent_repository_label"] = $repoObject->getParentId();
2201+
$crtParent = ConfService::getRepositoryById($repoObject->getParentId());
2202+
if(!empty($crtParent)){
2203+
$meta["shared_element_parent_repository_label"] = $crtParent->getDisplay();
2204+
}else {
2205+
$meta["shared_element_parent_repository_label"] = $repoObject->getParentId();
2206+
}
21882207
}
21892208
if($shareType != "repository"){
21902209
if($repoObject->hasContentFilter()){
@@ -2200,7 +2219,7 @@ public function listSharesAsNodes($rootPath, $currentUser = true, $parentReposit
22002219
}else{
22012220
$meta["original_path"] = $repoObject->getOption("PATH");
22022221
}
2203-
if(isSet($parentPath) && strpos($meta["original_path"], $parentPath) === 0){
2222+
if(!empty($parentPath) && strpos($meta["original_path"], $parentPath) === 0){
22042223
$meta["original_path"] = substr($meta["original_path"], strlen($parentPath));
22052224
}
22062225

0 commit comments

Comments
 (0)