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

Commit

Permalink
Admin Delegation: fix various criteria filtering and workspace listin…
Browse files Browse the repository at this point in the history
…g conditions that were breaking template-created workspaces for group Admin, as well as returning wrong users count (although correct users list).
  • Loading branch information
cdujeu committed Dec 18, 2014
1 parent b25403d commit d6c6c32
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 15 deletions.
2 changes: 2 additions & 0 deletions core/src/core/classes/class.AJXP_Utils.php
Expand Up @@ -1884,6 +1884,7 @@ public static function glob_recursive($pattern, $flags = 0)

public static function regexpToLike($regexp)
{
$regexp = trim($regexp, '/');
$left = "~";
$right = "~";
if ($regexp[0]=="^") {
Expand All @@ -1900,6 +1901,7 @@ public static function regexpToLike($regexp)

public static function cleanRegexp($regexp)
{
$regexp = str_replace("\/", "/", trim($regexp, '/'));
return ltrim(rtrim($regexp, "$"), "^");
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/core/classes/class.AuthService.php
Expand Up @@ -1058,7 +1058,7 @@ public static function authSupportsPagination()
public static function authCountUsers($baseGroup="/", $regexp="", $filterProperty = null, $filterValue = null, $recursive = true)
{
$authDriver = ConfService::getAuthDriverImpl();
return $authDriver->getUsersCount($baseGroup, $regexp, $filterProperty, $filterValue, $recursive);
return $authDriver->getUsersCount(self::filterBaseGroup($baseGroup), $regexp, $filterProperty, $filterValue, $recursive);
}

/**
Expand Down
24 changes: 19 additions & 5 deletions core/src/core/classes/class.ConfService.php
Expand Up @@ -514,8 +514,10 @@ public static function filterRepositoryListWithCriteria($repoList, $criteria){
$repositories = array();
$searchableKeys = array("uuid", "parent_uuid", "owner_user_id", "display", "accessType", "isTemplate", "slug", "groupPath");
foreach ($repoList as $repoId => $repoObject) {
$failOneCriteria = false;
foreach($criteria as $key => $value){
if(!in_array($key, $searchableKeys)) continue;
$criteriumOk = false;
if($key == "uuid") $comp = $repoObject->getUniqueId();
else if($key == "parent_uuid") $comp = $repoObject->getParentId();
else if($key == "owner_user_id") $comp = $repoObject->getUniqueUser();
Expand All @@ -525,16 +527,28 @@ public static function filterRepositoryListWithCriteria($repoList, $criteria){
else if($key == "slug") $comp = $repoObject->getSlug();
else if($key == "groupPath") $comp = $repoObject->getGroupPath();
if(is_array($value) && in_array($comp, $value)){
$repositories[$repoId] = $repoObject;
//$repositories[$repoId] = $repoObject;
$criteriumOk = true;
}else if($value == AJXP_FILTER_EMPTY && empty($comp)){
$repositories[$repoId] = $repoObject;
//$repositories[$repoId] = $repoObject;
$criteriumOk = true;
}else if($value == AJXP_FILTER_NOT_EMPTY && !empty($comp)){
$repositories[$repoId] = $repoObject;
//$repositories[$repoId] = $repoObject;
$criteriumOk = true;
}else if(is_string($value) && strpos($value, "regexp:")===0 && preg_match(str_replace("regexp:", "", $value), $comp)){
$repositories[$repoId] = $repoObject;
//$repositories[$repoId] = $repoObject;
$criteriumOk = true;
}else if($value == $comp){
$repositories[$repoId] = $repoObject;
//$repositories[$repoId] = $repoObject;
$criteriumOk = true;
}
if(!$criteriumOk) {
$failOneCriteria = true;
break;
}
}
if(!$failOneCriteria){
$repositories[$repoId] = $repoObject;
}
}
return $repositories;
Expand Down
2 changes: 1 addition & 1 deletion core/src/core/classes/class.Repository.php
Expand Up @@ -423,7 +423,7 @@ public function getDisplay()
*/
public function getId()
{
if($this->isWriteable()) return $this->getUniqueId();
if($this->isWriteable() || $this->id == null) return $this->getUniqueId();
return $this->id;
}

Expand Down
31 changes: 24 additions & 7 deletions core/src/plugins/access.ajxp_conf/class.ajxp_confAccessDriver.php
Expand Up @@ -241,7 +241,12 @@ public function recursiveSearchGroups($baseGroup, $term)

$users = AuthService::listUsers($baseGroup, $term);
foreach ($users as $userId => $userObject) {
$trimmedG = trim($userObject->getGroupPath(), "/");
$gPath = $userObject->getGroupPath();
$realGroup = AuthService::filterBaseGroup(AuthService::getLoggedUser()->getGroupPath());
if(strlen($realGroup) > 1 && strpos($gPath, $realGroup) === 0){
$gPath = substr($gPath, strlen($realGroup));
}
$trimmedG = trim($gPath, "/");
if(!empty($trimmedG)) $trimmedG .= "/";

$nodeKey = "/data/users/".$trimmedG.$userId;
Expand Down Expand Up @@ -2019,13 +2024,25 @@ public function listRepositories($root, $child, $hashValue = null, $returnNodes

$count = null;
// Load all repositories = normal, templates, and templates children
$repos = ConfService::listRepositoriesWithCriteria(array(
"parent_uuid" => AJXP_FILTER_EMPTY,
"ORDERBY" => array("KEY" => "display", "DIR"=>"ASC"),
"CURSOR" => array("OFFSET" => $offset, "LIMIT" => $REPOS_PER_PAGE)
), $count
);
$currentUserIsGroupAdmin = (AuthService::getLoggedUser() != null && AuthService::getLoggedUser()->getGroupPath() != "/");
if($currentUserIsGroupAdmin){
$repos = ConfService::listRepositoriesWithCriteria(array(
"owner_user_id" => AJXP_FILTER_EMPTY,
"groupPath" => "regexp:/^".str_replace("/", "\/", AuthService::getLoggedUser()->getGroupPath()).'/',
"ORDERBY" => array("KEY" => "display", "DIR"=>"ASC"),
"CURSOR" => array("OFFSET" => $offset, "LIMIT" => $REPOS_PER_PAGE)
), $count
);
}else{
$repos = ConfService::listRepositoriesWithCriteria(array(
"parent_uuid" => AJXP_FILTER_EMPTY,
"ORDERBY" => array("KEY" => "display", "DIR"=>"ASC"),
"CURSOR" => array("OFFSET" => $offset, "LIMIT" => $REPOS_PER_PAGE)
), $count
);
}
if(!$returnNodes){
var_dump($count);
AJXP_XMLWriter::renderPaginationData($count, $hashValue, ceil($count/$REPOS_PER_PAGE));
AJXP_XMLWriter::sendFilesListComponentConfig('<columns switchDisplayMode="list" switchGridMode="filelist" template_name="ajxp_conf.repositories">
<column messageId="ajxp_conf.8" attributeName="ajxp_label" sortType="String"/>
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/conf.sql/class.sqlConfDriver.php
Expand Up @@ -270,7 +270,7 @@ public function listRepositoriesWithCriteria($criteria, &$count = null){
}
}else if(strpos($cValue, "regexp:") === 0){
$regexp = str_replace("regexp:", "", $cValue);
$wheres[] = array("[$cName] ".AJXP_Utils::regexpToLike($regexp), AJXP_Utils::cleanLike($regexp));
$wheres[] = array("[$cName] ".AJXP_Utils::regexpToLike($regexp), AJXP_Utils::cleanRegexp($regexp));
}else if ($cValue == AJXP_FILTER_NOT_EMPTY){
$wheres[] = array("[$cName] IS NOT NULL");
}else if ($cValue == AJXP_FILTER_EMPTY){
Expand Down

0 comments on commit d6c6c32

Please sign in to comment.