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

Commit

Permalink
Conf/Auth driver : use a "ajxp.hidden" property to generally ignore a…
Browse files Browse the repository at this point in the history
…ll internal users created by minisites. Add powerfull methods to query repositories (directly in sql when possible).
  • Loading branch information
cdujeu committed May 1, 2014
1 parent c5a02f6 commit 1047aa8
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 5 deletions.
12 changes: 8 additions & 4 deletions core/src/plugins/auth.sql/class.sqlAuthDriver.php
Expand Up @@ -60,12 +60,14 @@ public function supportsUsersPagination()
// $baseGroup = "/"
public function listUsersPaginated($baseGroup, $regexp, $offset, $limit)
{
$ignoreHiddens = "NOT EXISTS (SELECT * FROM [ajxp_user_rights] AS c WHERE [c.login]=[u.login] AND [c.repo_uuid] = 'ajxp.hidden')";

if ($regexp != null) {
$res = dibi::query("SELECT * FROM [ajxp_users] WHERE [login] ".AJXP_Utils::regexpToLike($regexp)." AND [groupPath] LIKE %like~ ORDER BY [login] ASC", AJXP_Utils::cleanRegexp($regexp), $baseGroup) ;
$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", AJXP_Utils::cleanRegexp($regexp), $baseGroup) ;
} else if ($offset != -1 || $limit != -1) {
$res = dibi::query("SELECT * FROM [ajxp_users] WHERE [groupPath] LIKE %like~ ORDER BY [login] ASC %lmt %ofs", $baseGroup, $limit, $offset);
$res = dibi::query("SELECT * FROM [ajxp_users] AS u WHERE [groupPath] LIKE %like~ AND $ignoreHiddens ORDER BY [login] ASC %lmt %ofs", $baseGroup, $limit, $offset);
} else {
$res = dibi::query("SELECT * FROM [ajxp_users] WHERE [groupPath] LIKE %like~ ORDER BY [login] ASC", $baseGroup);
$res = dibi::query("SELECT * FROM [ajxp_users] AS u WHERE [groupPath] LIKE %like~ AND $ignoreHiddens ORDER BY [login] ASC", $baseGroup);
}
$pairs = $res->fetchPairs('login', 'password');
return $pairs;
Expand All @@ -86,6 +88,7 @@ public function getUsersCount($baseGroup = "/", $regexp = "", $filterProperty =
$ands[] = array("[u.login] ".AJXP_Utils::regexpToLike($regexp), AJXP_Utils::cleanRegexp($regexp));
}
$ands[] = array("[u.groupPath] LIKE %like~", $baseGroup);
$ands[] = array("NOT EXISTS (SELECT * FROM [ajxp_user_rights] AS c WHERE [c.login]=[u.login] AND [c.repo_uuid] = 'ajxp.hidden')");

if($filterProperty !== null && $filterValue !== null){
if($filterProperty == "parent"){
Expand Down Expand Up @@ -114,7 +117,8 @@ public function getUsersCount($baseGroup = "/", $regexp = "", $filterProperty =
public function listUsers($baseGroup="/")
{
$pairs = array();
$res = dibi::query("SELECT * FROM [ajxp_users] WHERE [groupPath] LIKE %like~ ORDER BY [login] ASC", $baseGroup);
$ignoreHiddens = "NOT EXISTS (SELECT * FROM [ajxp_user_rights] AS c WHERE [c.login]=[u.login] AND [c.repo_uuid] = 'ajxp.hidden')";
$res = dibi::query("SELECT * FROM [ajxp_users] as u WHERE [u.groupPath] LIKE %like~ AND $ignoreHiddens ORDER BY [u.login] ASC", $baseGroup);
$rows = $res->fetchAll();
foreach ($rows as $row) {
$grp = $row["groupPath"];
Expand Down
9 changes: 9 additions & 0 deletions core/src/plugins/boot.conf/class.BootConfLoader.php
Expand Up @@ -414,6 +414,15 @@ public function listRepositories($user = null)
// TODO: Implement listRepositories() method.
}

/**
* Returns a list of available repositories (dynamic ones only, not the ones defined in the config file).
* @param Array $criteria
* @return Array
*/
public function listRepositoriesWithCriteria($criteria){

}

/**
* Retrieve a Repository given its unique ID.
*
Expand Down
17 changes: 17 additions & 0 deletions core/src/plugins/conf.serial/class.serialConfDriver.php
Expand Up @@ -125,6 +125,23 @@ public function listRepositories($user = null)
return $all;
}

/**
* Returns a list of available repositories (dynamic ones only, not the ones defined in the config file).
* @param Array $criteria
* @return Array
*/
public function listRepositoriesWithCriteria($criteria){

$all = AJXP_Utils::loadSerialFile($this->repoSerialFile);
if ($criteria != null) {
return ConfService::filterRepositoryListWithCriteria($all, $criteria);
}else{
return $all;
}

}


public function listRoles($roleIds = array(), $excludeReserved = false)
{
$all = AJXP_Utils::loadSerialFile($this->rolesSerialFile);
Expand Down
6 changes: 6 additions & 0 deletions core/src/plugins/conf.sql/class.AJXP_SqlUser.php
Expand Up @@ -357,6 +357,9 @@ public function load()
if (isSet($this->rights["ajxp.parent_user"])) {
$this->setParent($this->rights["ajxp.parent_user"]);
}
if (isSet($this->rights["ajxp.hidden"])){
$this->setHidden(true);
}

$result_prefs = dibi::query('SELECT [name], [val] FROM [ajxp_user_prefs] WHERE [login] = %s', $this->getId());
$this->prefs = $result_prefs->fetchPairs('name', 'val');
Expand Down Expand Up @@ -457,6 +460,9 @@ public function save($context = "superuser")
if ($this->hasParent()) {
$this->rights["ajxp.parent_user"] = $this->parentUser;
}
if($this->isHidden()){
$this->rights["ajxp.hidden"] = 'true';
}

// UPDATE TABLE
dibi::query("DELETE FROM [ajxp_user_rights] WHERE [login]=%s", $this->getId());
Expand Down
62 changes: 61 additions & 1 deletion core/src/plugins/conf.sql/class.sqlConfDriver.php
Expand Up @@ -224,6 +224,65 @@ public function listRepositories($user = null)
return $repositories;
}

/**
* Returns a list of available repositories (dynamic ones only, not the ones defined in the config file).
* @param Array $criteria
* @param int $count possible total count
* @return Array
*/

This comment has been minimized.

Copy link
@cdujeu

cdujeu May 2, 2014

Author Member

@echampet hope you like that one, I tried to do it dibi-like :-)

public function listRepositoriesWithCriteria($criteria, &$count = null){

$wheres = array();
$limit = $groupBy = "";
$order = "ORDER BY display ASC";

$searchableKeys = array("uuid", "parent_uuid", "owner_user_id", "display", "accessType", "isTemplate", "slug", "groupPath");
foreach($criteria as $cName => $cValue){
if(in_array($cName, $searchableKeys)){
if(is_array($cValue)){
$wheres[] = array("[$cName] IN (%s)", $cValue);
}else if(strpos($cValue, "regexp:") === 0){
$regexp = str_replace("regexp:", "", $cValue);
$wheres[] = array("[$cName] ".AJXP_Utils::regexpToLike($regexp), AJXP_Utils::cleanLike($regexp));
}else if ($cValue == AJXP_FILTER_NOT_EMPTY){
$wheres[] = array("[$cName] NOT NULL");
}else if ($cValue == AJXP_FILTER_EMPTY){
$wheres[] = array("[$cName] IS NULL");
}else{
$type = "%s";
if($cName == 'isTemplate') $type = "%d";
$wheres[] = array("[$cName] = $type", $cValue);
}
}else if($cName == "CURSOR"){
$limit = "LIMIT ".$cValue["OFFSET"].",".$cValue["LIMIT"];
}else if($cName == "ORDERBY"){
$order = "ORDER BY ".$cValue["KEY"]." ".$cValue["DIR"];
}else if($cName == "GROUPBY"){
$groupBy = "GROUP BY ".$cValue;
}
}

if(isset($criteria["CURSOR"])){
$res = dibi::query("SELECT COUNT(uuid) FROM [ajxp_repo] WHERE %and", $wheres);
$count = $res->fetchSingle();
}

$res = dibi::query("SELECT * FROM [ajxp_repo] WHERE %and $groupBy $order $limit", $wheres);
$all = $res->fetchAll();

$repositories = Array();
foreach ($all as $repo_row) {
$res_opts = dibi::query('SELECT * FROM [ajxp_repo_options] WHERE [uuid] = %s', $repo_row['uuid']);
$opts = $res_opts->fetchPairs('name', 'val');
$repo = $this->repoFromDb($repo_row, $opts);
$repositories[$repo->getUniqueId()] = $repo;
}

return $repositories;

}


/**
* Get repository by Unique ID (a hash calculated from the serialised object).
*
Expand Down Expand Up @@ -368,8 +427,9 @@ public function deleteRepository($repositoryId)

public function getUserChildren( $userId )
{
$ignoreHiddens = "NOT EXISTS (SELECT * FROM [ajxp_user_rights] WHERE [ajxp_user_rights.login]=[ajxp_users.login] AND [ajxp_user_rights.repo_uuid] = 'ajxp.hidden')";
$children = array();
$children_results = dibi::query('SELECT [ajxp_users].[login] FROM [ajxp_user_rights],[ajxp_users] WHERE [repo_uuid] = %s AND [rights] = %s AND [ajxp_user_rights].[login] = [ajxp_users].[login]', "ajxp.parent_user", $userId);
$children_results = dibi::query('SELECT [ajxp_users].[login] FROM [ajxp_user_rights],[ajxp_users] WHERE [repo_uuid] = %s AND [rights] = %s AND [ajxp_user_rights].[login] = [ajxp_users].[login] AND '.$ignoreHiddens, "ajxp.parent_user", $userId);
$all = $children_results->fetchAll();
foreach ($all as $item) {
$children[] = $this->createUserObject($item["login"]);
Expand Down
20 changes: 20 additions & 0 deletions core/src/plugins/core.conf/class.AbstractAjxpUser.php
Expand Up @@ -41,6 +41,26 @@ abstract class AbstractAjxpUser implements AjxpGroupPathProvider
public $version;
public $parentUser;
public $resolveAsParent = false;
/**
* @var bool
*/
private $hidden;

/**
* @param bool $hidden
*/
public function setHidden($hidden)
{
$this->hidden = $hidden;
}

/**
* @return bool
*/
public function isHidden()
{
return $this->hidden;
}

public $groupPath = "/";
/**
Expand Down
14 changes: 14 additions & 0 deletions core/src/plugins/core.conf/class.AbstractConfDriver.php
Expand Up @@ -217,6 +217,20 @@ abstract public function _savePluginConfig($pluginId, $options);
* @return Array
*/
abstract public function listRepositories($user = null);

/**
* Returns a list of available repositories (dynamic ones only, not the ones defined in the config file).
* @param Array $criteria This parameter can take the following keys
* - Search keys "uuid", "parent_uuid", "owner_user_id", "display", "accessType", "isTemplate", "slug", "groupPath"
* Search values can be either string, array of string, AJXP_FILTER_EMPTY, AJXP_FILTER_NOT_EMPTY or regexp:RegexpString
* - ORDERBY = array("KEY"=>"", "DIR"=>""), GROUPBY, CURSOR = array("OFFSET" => 0, "LIMIT", 30)
* - COUNT_ONLY
*
* @return Array
*/
abstract public function listRepositoriesWithCriteria($criteria);


/**
* Retrieve a Repository given its unique ID.
*
Expand Down

0 comments on commit 1047aa8

Please sign in to comment.