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

Commit

Permalink
Implement a remote search feature for users. Declare specific remote_…
Browse files Browse the repository at this point in the history
…indexation attribute in nodes to force search engine to query server, even in "local" mode. Ability to open a user at the correct page
  • Loading branch information
cdujeu committed Aug 21, 2013
1 parent 57a68ae commit 401cca7
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 27 deletions.
5 changes: 5 additions & 0 deletions core/src/plugins/access.ajxp_conf/ajxp_confActions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
<serverCallback methodName="switchAction" restParams="/dir+/"></serverCallback>
</processing>
</action>
<action name="admin_search">
<processing>
<serverCallback methodName="searchAction" developerComment="Remote search implementation, currently only supporting users search."/>
</processing>
</action>
<action name="stat">
<processing>
<serverCallback methodName="switchAction" developerComment="To comply with GUI client, always returns true."/>
Expand Down
88 changes: 79 additions & 9 deletions core/src/plugins/access.ajxp_conf/class.ajxp_confAccessDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,52 @@ function preProcessBookmarkAction($action, &$httpVars, $fileVars){

}

function switchAction($action, $httpVars, $fileVars){
function recursiveSearchGroups($baseGroup, $term){

$groups = AuthService::listChildrenGroups($baseGroup);
foreach($groups as $groupId => $groupLabel){

if(preg_match("/$term/i", $groupLabel) == TRUE ){
$nodeKey = "/data/users/".trim($baseGroup, "/")."/".ltrim($groupId,"/");
$meta = array(
"icon" => "users-folder.png",
"ajxp_mime" => "group"
);
if(in_array($nodeKey, $this->currentBookmarks)) $meta = array_merge($meta, array("ajxp_bookmarked" => "true", "overlay_icon" => "bookmark.png"));
echo AJXP_XMLWriter::renderNode($nodeKey, $groupLabel, false, $meta, true, false);
}
$this->recursiveSearchGroups(rtrim($baseGroup, "/")."/".$groupId, $term);

}

$users = AuthService::listUsers($baseGroup, $term);
foreach($users as $userId => $userObject){

$nodeKey = "/data/users/".trim($userObject->getGroupPath(),"/")."/".$userId;
$meta = array(
"icon" => "user.png",
"ajxp_mime" => "user"
);
if(in_array($nodeKey, $this->currentBookmarks)) $meta = array_merge($meta, array("ajxp_bookmarked" => "true", "overlay_icon" => "bookmark.png"));
echo AJXP_XMLWriter::renderNode($nodeKey, $userId, false, $meta, true, false);

}

}


function searchAction($action, $httpVars, $fileVars){

if(! AJXP_Utils::decodeSecureMagic($httpVars["dir"]) == "/data/users") return;
$query = AJXP_Utils::decodeSecureMagic($httpVars["query"]);
AJXP_XMLWriter::header();

$this->recursiveSearchGroups("/", $query);
AJXP_XMLWriter::close();

}

function switchAction($action, $httpVars, $fileVars){
if(!isSet($this->actions[$action])) return;
parent::accessPreprocess($action, $httpVars, $fileVars);
$loggedUser = AuthService::getLoggedUser();
Expand Down Expand Up @@ -321,16 +366,20 @@ function switchAction($action, $httpVars, $fileVars){
}
$child = $splits[0];
if(isSet($rootNodes[$root]["CHILDREN"][$child])){
$atts = array();
if($child == "users"){
$atts["remote_indexation"] = "admin_search";
}
$callback = $rootNodes[$root]["CHILDREN"][$child]["LIST"];
if(is_string($callback) && method_exists($this, $callback)){
if(!$returnNodes) AJXP_XMLWriter::header();
$res = call_user_func(array($this, $callback), implode("/", $splits), $root, $hash, $returnNodes);
if(!$returnNodes) AJXP_XMLWriter::header("tree", $atts);
$res = call_user_func(array($this, $callback), implode("/", $splits), $root, $hash, $returnNodes, isSet($httpVars["file"])?$httpVars["file"]:'');
if(!$returnNodes) AJXP_XMLWriter::close();
}else if(is_array($callback)){
$res = call_user_func($callback, implode("/", $splits), $root, $hash, $returnNodes);
$res = call_user_func($callback, implode("/", $splits), $root, $hash, $returnNodes, isSet($httpVars["file"])?$httpVars["file"]:'');
}
if($returnNodes){
AJXP_XMLWriter::header();
AJXP_XMLWriter::header("tree", $atts);
if(isSet($res["/".$dir."/".$httpVars["file"]])){
print $res["/".$dir."/".$httpVars["file"]];
}
Expand All @@ -356,6 +405,7 @@ function switchAction($action, $httpVars, $fileVars){
foreach ($nodes as $key => $data){
$bmString = '';
if(in_array($parentName.$key, $this->currentBookmarks)) $bmString = ' ajxp_bookmarked="true" overlay_icon="bookmark.png" ';
if($key == "users") $bmString .= ' remote_indexation="admin_search"';
print '<tree text="'.AJXP_Utils::xmlEntities($data["LABEL"]).'" description="'.AJXP_Utils::xmlEntities($data["DESCRIPTION"]).'" icon="'.$data["ICON"].'" filename="'.$parentName.$key.'" '.$bmString.'/>';
}
AJXP_XMLWriter::close();
Expand Down Expand Up @@ -1581,7 +1631,30 @@ function listPlugins($dir, $root = NULL, $hash = null, $returnNodes = false){
return $allNodes;
}

function listUsers($root, $child, $hashValue = null, $returnNodes = false){
function listUsers($root, $child, $hashValue = null, $returnNodes = false, $findNodePosition=null){

$USER_PER_PAGE = 50;
if($root == "users") $baseGroup = "/";
else $baseGroup = substr($root, strlen("users"));

if($findNodePosition != null && $hashValue == null){

// Loop on each page to find the correct page.
$count = AuthService::authCountUsers($baseGroup);
$pages = ceil($count / $USER_PER_PAGE);
for($i = 0; $i < $pages ; $i ++){

$tests = $this->listUsers($root, $child, $i+1, true, $findNodePosition);
if(is_array($tests) && isSet($tests["/data/".$root."/".$findNodePosition])){
return array("/data/".$root."/".$findNodePosition => str_replace("ajxp_mime", "page_position='".($i+1)."' ajxp_mime", $tests["/data/".$root."/".$findNodePosition]));
}

}

return array();

}

$allNodes = array();
$columns = '<columns switchDisplayMode="list" switchGridMode="filelist" template_name="ajxp_conf.users">
<column messageId="ajxp_conf.6" attributeName="ajxp_label" sortType="String" defaultWidth="40%"/>
Expand All @@ -1600,10 +1673,7 @@ function listUsers($root, $child, $hashValue = null, $returnNodes = false){
}
if(!$returnNodes) AJXP_XMLWriter::sendFilesListComponentConfig($columns);
if(!AuthService::usersEnabled()) return ;
$USER_PER_PAGE = 50;
if(empty($hashValue)) $hashValue = 1;
if($root == "users") $baseGroup = "/";
else $baseGroup = substr($root, strlen("users"));

$count = AuthService::authCountUsers($baseGroup);
if(AuthService::authSupportsPagination() && $count >= $USER_PER_PAGE){
Expand Down
1 change: 1 addition & 0 deletions core/src/plugins/auth.serial/class.serialAuthDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function listUsers($baseGroup = "/"){
$users = array_combine(array_map("strtolower", array_keys($users)), array_values($users));
}
ConfService::getConfStorageImpl()->filterUsersByGroup($users, $baseGroup, false);
ksort($users);
return $users;
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/gui.ajax/res/js/ajaxplorer.js

Large diffs are not rendered by default.

57 changes: 40 additions & 17 deletions core/src/plugins/gui.ajax/res/js/ajaxplorer/class.SearchEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ Class.create("SearchEngine", AjxpPane, {
var folder = ajaxplorer.getContextNode().getPath();
if(folder == "/") folder = "";
window.setTimeout(function(){
this.searchFolderContent(folder);
this.searchFolderContent(folder, ajaxplorer.getContextNode().getMetadata().get("remote_indexation"));
}.bind(this), 0);
},
/**
Expand Down Expand Up @@ -516,17 +516,17 @@ Class.create("SearchEngine", AjxpPane, {
* Put a folder to search in the queue
* @param path String
*/
appendFolderToQueue : function(path){
this._queue.push(path);
appendFolderToQueue : function(path, remoteIndexation){
this._queue.push({path:path,remoteIndexation:remoteIndexation?remoteIndexation:false});
},
/**
* Process the next element of the queue, or finish
*/
searchNext : function(){
if(this._queue.length){
var path = this._queue.first();
var element = this._queue.first();
this._queue.shift();
this.searchFolderContent(path);
this.searchFolderContent(element.path, element.remoteIndexation);
}else{
this.updateStateFinished();
}
Expand All @@ -536,7 +536,7 @@ Class.create("SearchEngine", AjxpPane, {
* Should reference the IAjxpNodeProvider instead!! Still a "ls" here!
* @param currentFolder String
*/
searchFolderContent : function(currentFolder){
searchFolderContent : function(currentFolder, remote_indexation){
if(this._state == 'interrupt') {
this.updateStateFinished();
return;
Expand All @@ -557,16 +557,39 @@ Class.create("SearchEngine", AjxpPane, {
this.setOnLoad($(this._resultsBoxId));
connexion.sendAsync();
}else{
/* LIST CONTENT, SEARCH CLIENT SIDE, AND RECURSE */
var connexion = new Connexion();
connexion.addParameter('get_action', 'ls');
connexion.addParameter('options', 'a' + (this.hasMetaSearch()?'l':''));
connexion.addParameter('dir', currentFolder);
connexion.onComplete = function(transport){
this._parseXmlAndSearchString(transport.responseXML, currentFolder);
this.searchNext();
}.bind(this);
connexion.sendAsync();

if(remote_indexation){

var connexion = new Connexion();
connexion.addParameter('get_action', remote_indexation);
connexion.addParameter('query', this.crtText);
connexion.addParameter('dir', currentFolder);
if(this.hasMetaSearch()){
connexion.addParameter('fields', this.getSearchColumns().join(','));
}
connexion.onComplete = function(transport){
this._parseResults(transport.responseXML, currentFolder);
this.removeOnLoad($(this._resultsBoxId));
this.searchNext();
}.bind(this);
this.setOnLoad($(this._resultsBoxId));
connexion.sendAsync();

}else{

/* LIST CONTENT, SEARCH CLIENT SIDE, AND RECURSE */
var connexion = new Connexion();
connexion.addParameter('get_action', 'ls');
connexion.addParameter('options', 'a' + (this.hasMetaSearch()?'l':''));
connexion.addParameter('dir', currentFolder);
connexion.onComplete = function(transport){
this._parseXmlAndSearchString(transport.responseXML, currentFolder);
this.searchNext();
}.bind(this);
connexion.sendAsync();

}

}
},

Expand All @@ -588,7 +611,7 @@ Class.create("SearchEngine", AjxpPane, {
if(!node.isLeaf())
{
var newPath = node.getPath();
this.appendFolderToQueue(newPath);
this.appendFolderToQueue(newPath, node.getMetadata().get("remote_indexation"));
}
}
}
Expand Down

0 comments on commit 401cca7

Please sign in to comment.