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

Commit

Permalink
Fix duplicates when listing users in groups
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Sep 18, 2014
1 parent a1cbfa3 commit 883bcdf
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 16 deletions.
4 changes: 2 additions & 2 deletions core/src/core/classes/class.AuthService.php
Expand Up @@ -951,15 +951,15 @@ public static function countUsersForRepository($repositoryId, $details = false)
* @param bool $cleanLosts
* @return array
*/
public static function listUsers($baseGroup = "/", $regexp = null, $offset = -1, $limit = -1, $cleanLosts = true)
public static function listUsers($baseGroup = "/", $regexp = null, $offset = -1, $limit = -1, $cleanLosts = true, $recursive = true)
{
$baseGroup = self::filterBaseGroup($baseGroup);
$authDriver = ConfService::getAuthDriverImpl();
$confDriver = ConfService::getConfStorageImpl();
$allUsers = array();
$paginated = false;
if (($regexp != null || $offset != -1 || $limit != -1) && $authDriver->supportsUsersPagination()) {
$users = $authDriver->listUsersPaginated($baseGroup, $regexp, $offset, $limit);
$users = $authDriver->listUsersPaginated($baseGroup, $regexp, $offset, $limit, $recursive);
$paginated = true;
} else {
$users = $authDriver->listUsers($baseGroup);
Expand Down
Expand Up @@ -1834,7 +1834,7 @@ public function listUsers($root, $child, $hashValue = null, $returnNodes = false
if (AuthService::authSupportsPagination() && $count >= $USER_PER_PAGE) {
$offset = ($hashValue - 1) * $USER_PER_PAGE;
if(!$returnNodes) AJXP_XMLWriter::renderPaginationData($count, $hashValue, ceil($count/$USER_PER_PAGE));
$users = AuthService::listUsers($baseGroup, "", $offset, $USER_PER_PAGE);
$users = AuthService::listUsers($baseGroup, "", $offset, $USER_PER_PAGE, true, false);
if ($hashValue == 1) {
$groups = AuthService::listChildrenGroups($baseGroup);
} else {
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/auth.ldap/class.ldapAuthDriver.php
Expand Up @@ -317,7 +317,7 @@ public function supportsUsersPagination()
}

// $baseGroup = "/"
public function listUsersPaginated($baseGroup, $regexp, $offset, $limit)
public function listUsersPaginated($baseGroup, $regexp, $offset, $limit, $recursive = true)
{
if (!empty($this->hasGroupsMapping)) {
if ($baseGroup == "/") {
Expand Down
6 changes: 3 additions & 3 deletions core/src/plugins/auth.multi/class.multiAuthDriver.php
Expand Up @@ -218,13 +218,13 @@ public function supportsUsersPagination()
}

// $baseGroup = "/"
public function listUsersPaginated($baseGroup, $regexp, $offset, $limit)
public function listUsersPaginated($baseGroup, $regexp, $offset, $limit, $recursive = true)
{
if (!empty($this->baseName) && $regexp == null) {
return $this->drivers[$this->baseName]->listUsersPaginated($baseGroup, $regexp, $offset, $limit);
return $this->drivers[$this->baseName]->listUsersPaginated($baseGroup, $regexp, $offset, $limit, $recursive);
} else {
$keys = array_keys($this->drivers);
return $this->drivers[$keys[0]]->listUsersPaginated($baseGroup, $regexp, $offset, $limit) + $this->drivers[$keys[1]]->listUsersPaginated($baseGroup, $regexp, $offset, $limit);
return $this->drivers[$keys[0]]->listUsersPaginated($baseGroup, $regexp, $offset, $limit, $recursive) + $this->drivers[$keys[1]]->listUsersPaginated($baseGroup, $regexp, $offset, $limit, $recursive);
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/auth.remote/class.remoteAuthDriver.php
Expand Up @@ -124,7 +124,7 @@ public function listUsers()
return $users;
}

public function listUsersPaginated($baseGroup, $regexp, $offset = -1 , $limit = -1)
public function listUsersPaginated($baseGroup, $regexp, $offset = -1 , $limit = -1, $recursive = true)
{
$users = $this->listUsers();
$result = array();
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/auth.serial/class.serialAuthDriver.php
Expand Up @@ -78,7 +78,7 @@ public function supportsUsersPagination()
}

// $baseGroup = "/"
public function listUsersPaginated($baseGroup, $regexp, $offset = -1 , $limit = -1)
public function listUsersPaginated($baseGroup, $regexp, $offset = -1 , $limit = -1, $recursive = true)
{
$users = $this->listUsers($baseGroup);
$result = array();
Expand Down
Expand Up @@ -84,7 +84,7 @@ public function supportsUsersPagination()
}

// $baseGroup = "/"
public function listUsersPaginated($baseGroup, $regexp, $offset = -1 , $limit = -1)
public function listUsersPaginated($baseGroup, $regexp, $offset = -1 , $limit = -1, $recursive = true)
{
$users = $this->listUsers($baseGroup);
$result = array();
Expand Down
14 changes: 9 additions & 5 deletions core/src/plugins/auth.sql/class.sqlAuthDriver.php
Expand Up @@ -58,16 +58,20 @@ public function supportsUsersPagination()
}

// $baseGroup = "/"
public function listUsersPaginated($baseGroup, $regexp, $offset, $limit)
public function listUsersPaginated($baseGroup, $regexp, $offset, $limit, $recursive = true)
{
$ignoreHiddens = "NOT EXISTS (SELECT * FROM [ajxp_user_rights] AS c WHERE [c.login]=[u.login] AND [c.repo_uuid] = 'ajxp.hidden')";

if($recursive){
$groupPathCondition = "[groupPath] LIKE %like~";
}else{
$groupPathCondition = "[groupPath] = %s";
}
if ($regexp != null) {
$res = dibi::query("SELECT * FROM [ajxp_users] AS u WHERE [login] ".AJXP_Utils::regexpToLike($regexp)." AND [groupPath] LIKE %like~ AND $ignoreHiddens ORDER BY [login] ASC %lmt %ofs", AJXP_Utils::cleanRegexp($regexp), $baseGroup, $limit, $offset) ;
$res = dibi::query("SELECT * FROM [ajxp_users] AS u WHERE [login] ".AJXP_Utils::regexpToLike($regexp)." AND $groupPathCondition AND $ignoreHiddens ORDER BY [login] ASC %lmt %ofs", AJXP_Utils::cleanRegexp($regexp), $baseGroup, $limit, $offset) ;
} else if ($offset != -1 || $limit != -1) {
$res = dibi::query("SELECT * FROM [ajxp_users] AS u WHERE [groupPath] LIKE %like~ AND $ignoreHiddens ORDER BY [login] ASC %lmt %ofs", $baseGroup, $limit, $offset);
$res = dibi::query("SELECT * FROM [ajxp_users] AS u WHERE $groupPathCondition AND $ignoreHiddens ORDER BY [login] ASC %lmt %ofs", $baseGroup, $limit, $offset);
} else {
$res = dibi::query("SELECT * FROM [ajxp_users] AS u WHERE [groupPath] LIKE %like~ AND $ignoreHiddens ORDER BY [login] ASC", $baseGroup);
$res = dibi::query("SELECT * FROM [ajxp_users] AS u WHERE $groupPathCondition AND $ignoreHiddens ORDER BY [login] ASC", $baseGroup);
}
$pairs = $res->fetchPairs('login', 'password');
return $pairs;
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/core.auth/class.AbstractAuthDriver.php
Expand Up @@ -233,7 +233,7 @@ public function findUserPage($userLogin, $usersPerPage){
return -1;
}

public function listUsersPaginated($baseGroup, $regexp, $offset, $limit)
public function listUsersPaginated($baseGroup, $regexp, $offset, $limit, $recursive = true)
{
return $this->listUsers($baseGroup);
}
Expand Down

0 comments on commit 883bcdf

Please sign in to comment.