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

Commit

Permalink
Add page-based pagination to full directory in address book.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed May 24, 2017
1 parent dfa6672 commit d753572
Show file tree
Hide file tree
Showing 33 changed files with 140 additions and 49 deletions.
45 changes: 37 additions & 8 deletions core/src/core/src/pydio/Core/Model/FilteredUsersList.php
Expand Up @@ -21,6 +21,7 @@
namespace Pydio\Core\Model;


use Psr\Http\Message\ResponseInterface;
use Pydio\Conf\Core\AJXP_Role;
use Pydio\Core\Exception\UserNotFoundException;
use Pydio\Core\Services\ConfService;
Expand Down Expand Up @@ -54,18 +55,23 @@ class FilteredUsersList{
private $excludeCurrent;

/**
* @var bool
* @var string
*/
private $range;

/**
* @var
*/
private $alphaPages;
private $responseRange;

/**
* FilteredUsersList constructor.
* @param ContextInterface $ctx
*/
public function __construct(ContextInterface $ctx, $excludeCurrent = true, $alphaPages = false){
public function __construct(ContextInterface $ctx, $excludeCurrent = true, $range = ''){
$this->ctx = $ctx;
$this->excludeCurrent = $excludeCurrent;
$this->alphaPages = $alphaPages;
$this->range = $range;
}

/**
Expand Down Expand Up @@ -164,12 +170,13 @@ protected function searchUserRolesList($userObject, $rolePrefix, $includeString,
/**
* @param $groupPath string
* @param $searchTerm string
* @param $offset int
* @param $searchLimit int
* @param $filterArray array
* @param $recursive bool
* @return UserInterface[]
*/
protected function listUsers($groupPath, $searchTerm, $searchLimit, $filterArray, $recursive = false){
protected function listUsers($groupPath, $searchTerm, $offset, $searchLimit, $filterArray, $recursive = false){

if(strpos($groupPath, self::TEAM_PREFIX) === 0){

Expand All @@ -189,7 +196,13 @@ protected function listUsers($groupPath, $searchTerm, $searchLimit, $filterArray

} else if($filterArray['users_internal']){
// only internal or both
$users = UsersService::listUsers($groupPath, '^'.$searchTerm, 0, $searchLimit, false, $recursive);
if(!$filterArray['users_external']){
$count = UsersService::authCountUsers($groupPath, '^'.$searchTerm, 'parent', AJXP_FILTER_EMPTY, false);
}else{
$count = UsersService::authCountUsers($groupPath, '^'.$searchTerm, null, null, false);
}
$this->responseRange = ($count > $searchLimit) ? $offset."-".($offset+$searchLimit)."/".$count : null;
$users = UsersService::listUsers($groupPath, '^'.$searchTerm, $offset, $searchLimit, false, $recursive);
if(!$filterArray['users_external']){
$users = array_filter($users, function($userObject) {
/** @var UserInterface $userObject */
Expand Down Expand Up @@ -312,6 +325,16 @@ private function parseFilterValue($value){
];
}

/**
* @param ResponseInterface $response
*/
public function setResponseHeaders(ResponseInterface &$response){
if(!$this->responseRange) return;
$response = $response
->withHeader('Content-Range', $this->responseRange)
->withHeader('Accept-Range', 'user '.$this->getConf('USERS_LIST_COMPLETE_LIMIT'));
}

/**
* @param int $filterValue
* @param bool $allowCreation
Expand All @@ -335,7 +358,13 @@ public function load($filterValue, $allowCreation = true, $searchQuery = '', $gr
$items = [];
$mess = LocaleService::getMessages();
$allowCreation &= $this->getConf('USER_CREATE_USERS');
$searchLimit = $this->alphaPages ? -1 : $this->getConf('USERS_LIST_COMPLETE_LIMIT');
if(empty($this->range)){
$offset = 0;
$searchLimit = $this->getConf('USERS_LIST_COMPLETE_LIMIT');
}else{
list($offset, $end) = explode('-', $this->range);
$searchLimit = min($end - $offset, $this->getConf('USERS_LIST_COMPLETE_LIMIT'));
}
$baseGroup = $this->computeBaseGroup($groupPathFilter, $searchQuery);

if(!empty($searchQuery)) {
Expand All @@ -348,7 +377,7 @@ public function load($filterValue, $allowCreation = true, $searchQuery = '', $gr
$allGroups = [];
$allUsers = [];
if( $FILTER['users_internal'] || $FILTER['users_external'] ){
$allUsers = $this->listUsers($baseGroup, $searchQuery, $searchLimit, $FILTER, empty($groupPathFilter));
$allUsers = $this->listUsers($baseGroup, $searchQuery, $offset, $searchLimit, $FILTER, empty($groupPathFilter));
}
if( $FILTER['groups'] ) {
$allGroups = $this->listGroupsOrRoles($baseGroup);
Expand Down
1 change: 1 addition & 0 deletions core/src/plugins/core.ajaxplorer/i18n/ca.php
Expand Up @@ -725,5 +725,6 @@
"622" => "Error Stack",
"623" => "Copy",
"624" => "Copied!",
"625" => "Letter",

);
14 changes: 12 additions & 2 deletions core/src/plugins/core.ajaxplorer/i18n/conf/es.php
Expand Up @@ -176,5 +176,15 @@
"Redirect URL" => "Redireccionar URL",
"API endpoint - Used to launch the window allowing the user to authenticate and accept the terms of the app" => "API endpoint - Usado para lanzar la ventana que permite a los usuarios autenticarse y aceptar los terminos de uso de la aplicación",
"API endpoint - Used to refresh or validate the token retrieved in the authentication part" => "API endpoint - Usado para regenerar o validar el token en la parte de la autenticación",
"API setting - Redirect URL for the OAuth Application" => "Configuración de la API - Redirecciona la URL para la Aplicación OAuth"
);
"API setting - Redirect URL for the OAuth Application" => "Configuración de la API - Redirecciona la URL para la Aplicación OAuth",
"Download Folder (Legacy)" => "Download Folder (Legacy)",
"Absolute path to the public folder where temporary download links will be created. This is used for legacy purpose, newly created links do not use it anymore, but use the Base URI instead." => "Absolute path to the public folder where temporary download links will be created. This is used for legacy purpose, newly created links do not use it anymore, but use the Base URI instead.",
"If not inferred directly from the current pydio URL plus the public base URI, replace the public access URL here." => "If not inferred directly from the current pydio URL plus the public base URI, replace the public access URL here.",
"Public Base URI" => "Public Base URI",
"URI where to serve the public links" => "URI where to serve the public links",
"Enable for all users" => "Enable for all users",
"Enable WebDAV for all users by default. If set to false, users will have to manually enable WebDAV via their preferences panel." => "Enable WebDAV for all users by default. If set to false, users will have to manually enable WebDAV via their preferences panel.",
"Download Delegation" => "Download Delegation",
"Delegates download operations to an alternative agent, either webserver or pydio agent. Warning, this requires external modules to be installed. When using XSendFile/XaccelRedirect, you have to manually add the folders where files will be downloaded in the module configuration" => "Delegates download operations to an alternative agent, either webserver or pydio agent. Warning, this requires external modules to be installed. When using XSendFile/XaccelRedirect, you have to manually add the folders where files will be downloaded in the module configuration",
"Core Connexion" => "Core Connexion",
);
1 change: 1 addition & 0 deletions core/src/plugins/core.ajaxplorer/i18n/cs.php
Expand Up @@ -722,4 +722,5 @@
"622" => "Error Stack",
"623" => "Copy",
"624" => "Copied!",
"625" => "Letter",
);
1 change: 1 addition & 0 deletions core/src/plugins/core.ajaxplorer/i18n/da.php
Expand Up @@ -727,5 +727,6 @@
"622" => "Error Stack",
"623" => "Copy",
"624" => "Copied!",
"625" => "Letter",
/* END SENTENCE */
);
3 changes: 2 additions & 1 deletion core/src/plugins/core.ajaxplorer/i18n/de.php
Expand Up @@ -729,6 +729,7 @@
"622" => "Fehlerstapel",
"623" => "Kopieren",
"624" => "Erfolgreich kopiert!",
"625" => "Letter",
/* END SENTENCE */
/* password strength tester */
);
);
1 change: 1 addition & 0 deletions core/src/plugins/core.ajaxplorer/i18n/en.php
Expand Up @@ -724,4 +724,5 @@
"622" => "Error Stack",
"623" => "Copy",
"624" => "Copied!",
"625" => "Letter",
);
1 change: 1 addition & 0 deletions core/src/plugins/core.ajaxplorer/i18n/es.php
Expand Up @@ -729,4 +729,5 @@
"622" => "Error Stack",
"623" => "Copy",
"624" => "Copied!",
"625" => "Letter",
);
1 change: 1 addition & 0 deletions core/src/plugins/core.ajaxplorer/i18n/et.php
Expand Up @@ -725,5 +725,6 @@
"622" => "Error Stack",
"623" => "Copy",
"624" => "Copied!",
"625" => "Letter",
/* END SENTENCE */
);
1 change: 1 addition & 0 deletions core/src/plugins/core.ajaxplorer/i18n/eus.php
Expand Up @@ -723,5 +723,6 @@
"622" => "Error Stack",
"623" => "Copy",
"624" => "Copied!",
"625" => "Letter",
/* END SENTENCE */
);
1 change: 1 addition & 0 deletions core/src/plugins/core.ajaxplorer/i18n/fi.php
Expand Up @@ -725,5 +725,6 @@
"622" => "Error Stack",
"623" => "Copy",
"624" => "Copied!",
"625" => "Letter",
/* END SENTENCE */
);
1 change: 1 addition & 0 deletions core/src/plugins/core.ajaxplorer/i18n/fr.php
Expand Up @@ -724,5 +724,6 @@
"622" => "Pile d'erreurs",
"623" => "Copier",
"624" => "Copié!",
"625" => "Lettre",
/* END SENTENCE */
);
1 change: 1 addition & 0 deletions core/src/plugins/core.ajaxplorer/i18n/gr.php
Expand Up @@ -722,5 +722,6 @@
"622" => "Error Stack",
"623" => "Copy",
"624" => "Copied!",
"625" => "Letter",
/* END SENTENCE */
);
1 change: 1 addition & 0 deletions core/src/plugins/core.ajaxplorer/i18n/he.php
Expand Up @@ -722,5 +722,6 @@
"622" => "Error Stack",
"623" => "Copy",
"624" => "Copied!",
"625" => "Letter",
/* END SENTENCE */
);
1 change: 1 addition & 0 deletions core/src/plugins/core.ajaxplorer/i18n/hu.php
Expand Up @@ -727,5 +727,6 @@
"622" => "Error Stack",
"623" => "Copy",
"624" => "Copied!",
"625" => "Letter",
/* END SENTENCE */
);
1 change: 1 addition & 0 deletions core/src/plugins/core.ajaxplorer/i18n/it.php
Expand Up @@ -742,5 +742,6 @@
"622" => "Error Stack",
"623" => "Copy",
"624" => "Copied!",
"625" => "Letter",
/* END SENTENCE */
);
1 change: 1 addition & 0 deletions core/src/plugins/core.ajaxplorer/i18n/ja.php
Expand Up @@ -727,6 +727,7 @@
"622" => "Error Stack",
"623" => "Copy",
"624" => "Copied!",
"625" => "Letter",
/* 文章はここまで */
/* 文章終了 */
);
1 change: 1 addition & 0 deletions core/src/plugins/core.ajaxplorer/i18n/kr.php
Expand Up @@ -731,5 +731,6 @@
"622" => "Error Stack",
"623" => "Copy",
"624" => "Copied!",
"625" => "Letter",
/* END SENTENCE */
);
1 change: 1 addition & 0 deletions core/src/plugins/core.ajaxplorer/i18n/nl.php
Expand Up @@ -728,5 +728,6 @@
"622" => "Error Stack",
"623" => "Copy",
"624" => "Copied!",
"625" => "Letter",
/* END SENTENCE */
);
1 change: 1 addition & 0 deletions core/src/plugins/core.ajaxplorer/i18n/no.php
Expand Up @@ -726,5 +726,6 @@
"622" => "Error Stack",
"623" => "Copy",
"624" => "Copied!",
"625" => "Letter",
/* END SENTENCE */
);
1 change: 1 addition & 0 deletions core/src/plugins/core.ajaxplorer/i18n/pl.php
Expand Up @@ -722,5 +722,6 @@
"622" => "Error Stack",
"623" => "Copy",
"624" => "Copied!",
"625" => "Letter",
/* END SENTENCE */
);
1 change: 1 addition & 0 deletions core/src/plugins/core.ajaxplorer/i18n/pt-br.php
Expand Up @@ -722,6 +722,7 @@
"622" => "Error Stack",
"623" => "Copy",
"624" => "Copied!",
"625" => "Letter",
/* END SENTENCE */
/* testador de força de senha */
);
1 change: 1 addition & 0 deletions core/src/plugins/core.ajaxplorer/i18n/pt.php
Expand Up @@ -722,6 +722,7 @@
"622" => "Error Stack",
"623" => "Copy",
"624" => "Copied!",
"625" => "Letter",
/* END SENTENCE */
/* password strength tester */
);
1 change: 1 addition & 0 deletions core/src/plugins/core.ajaxplorer/i18n/ru.php
Expand Up @@ -722,6 +722,7 @@
"622" => "Error Stack",
"623" => "Copy",
"624" => "Copied!",
"625" => "Letter",
/* END SENTENCE */
/* password strength tester */
);
1 change: 1 addition & 0 deletions core/src/plugins/core.ajaxplorer/i18n/si.php
Expand Up @@ -723,5 +723,6 @@
"622" => "Error Stack",
"623" => "Copy",
"624" => "Copied!",
"625" => "Letter",
/* END SENTENCE */
);
1 change: 1 addition & 0 deletions core/src/plugins/core.ajaxplorer/i18n/sv.php
Expand Up @@ -722,5 +722,6 @@
"622" => "Error Stack",
"623" => "Copy",
"624" => "Copied!",
"625" => "Letter",
/* END SENTENCE */
);
1 change: 1 addition & 0 deletions core/src/plugins/core.ajaxplorer/i18n/tr.php
Expand Up @@ -725,5 +725,6 @@
"622" => "Error Stack",
"623" => "Copy",
"624" => "Copied!",
"625" => "Letter",
/* END SENTENCE */
);
1 change: 1 addition & 0 deletions core/src/plugins/core.ajaxplorer/i18n/zh-tw.php
Expand Up @@ -725,5 +725,6 @@
"622" => "Error Stack",
"623" => "Copy",
"624" => "Copied!",
"625" => "Letter",
/* END SENTENCE */
);
1 change: 1 addition & 0 deletions core/src/plugins/core.ajaxplorer/i18n/zh.php
Expand Up @@ -734,5 +734,6 @@
"622" => "Error Stack",
"623" => "Copy",
"624" => "Copied!",
"625" => "Letter",
/* END SENTENCE */
);
5 changes: 4 additions & 1 deletion core/src/plugins/core.conf/AbstractConfDriver.php
Expand Up @@ -1294,6 +1294,7 @@ public function switchAction(ServerRequestInterface $requestInterface, ResponseI
$groupPath = isSet($httpVars["group_path"]) ? InputFilter::sanitize($httpVars['group_path'], InputFilter::SANITIZE_DIRNAME) : '';
$existingOnly = isSet($httpVars["existing_only"]) && $httpVars["existing_only"] === "true";
$excludeCurrent = isSet($httpVars["exclude_current"]) && ($httpVars["exclude_current"] === "false" || $httpVars["exclude_current"] === false) ? false : true;
$range = isSet($httpVars["range"]) ? $httpVars["range"] : null;
if($alphaPages){
if($crtValue === '') $crtValue = 'a';
$existingOnly = true;
Expand All @@ -1309,8 +1310,10 @@ public function switchAction(ServerRequestInterface $requestInterface, ResponseI
}
}

$list = new FilteredUsersList($ctx, $excludeCurrent, $alphaPages);
$list = new FilteredUsersList($ctx, $excludeCurrent, $range);
$items = $list->load($filterValue, !$existingOnly, $crtValue, $groupPath);
$list->setResponseHeaders($responseInterface);

$format = $httpVars["format"];
if(!isSet($format)) $format = 'json';
switch($format){
Expand Down

0 comments on commit d753572

Please sign in to comment.