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

Commit

Permalink
Fix to #1068: removed external users and added Groups instead
Browse files Browse the repository at this point in the history
  • Loading branch information
ghecquet committed Mar 23, 2016
1 parent b2129d0 commit 7c05d5c
Show file tree
Hide file tree
Showing 31 changed files with 141 additions and 117 deletions.
6 changes: 3 additions & 3 deletions core/src/core/classes/class.AuthService.php
Expand Up @@ -960,12 +960,12 @@ public static function getUsersForRepository($repositoryId)
* Retrieve the current users who have either read or write access to a repository
* @param $repositoryId
* @param string $rolePrefix
* @param bool $countOnly
* @param bool $splitByType
* @return array
*/
public static function getRolesForRepository($repositoryId, $rolePrefix = '', $countOnly = false)
public static function getRolesForRepository($repositoryId, $rolePrefix = '', $splitByType = false)
{
return ConfService::getConfStorageImpl()->getRolesForRepository($repositoryId, $rolePrefix, $countOnly);
return ConfService::getConfStorageImpl()->getRolesForRepository($repositoryId, $rolePrefix, $splitByType);
}

/**
Expand Down
Expand Up @@ -374,11 +374,11 @@
}
var blocks = [];
var data = this.state.data;
if(data['core.users'] && data['core.users']['internal'] != undefined && data['core.users']['external'] != undefined){
if(data['core.users'] && data['core.users']['users'] != undefined && data['core.users']['groups'] != undefined){
blocks.push(
<HomeWorkspaceLegendInfoBlock key="core.users" badgeTitle={MessageHash[527]} iconClass="icon-group">
{MessageHash[531]} {data['core.users']['internal']}
<br/>{MessageHash[532]} {data['core.users']['external']}
{data['core.users']['users'] ? (MessageHash[531] + ' ' + data['core.users']['users']) : ''}
{data['core.users']['groups'] ? (MessageHash[532] + ' ' + data['core.users']['groups']) : ''}
</HomeWorkspaceLegendInfoBlock>
);
}
Expand Down Expand Up @@ -524,4 +524,4 @@
WelcomeComponents.TutorialPane = TutorialPane;
global.WelcomeComponents = WelcomeComponents;

})(window);
})(window);
132 changes: 78 additions & 54 deletions core/src/plugins/conf.sql/class.sqlConfDriver.php
Expand Up @@ -537,43 +537,100 @@ public function getUsersForRepository($repositoryId)
* @abstract
* @param string $repositoryId
* @param string $rolePrefix
* @param bool $countOnly
* @param bool $splitByType
* @return array()
*/
public function getRolesForRepository($repositoryId, $rolePrefix = '', $countOnly = false){
public function getRolesForRepository($repositoryId, $rolePrefix = '', $splitByType = false){
$allRoles = array();

// Initing select
$q['select']['role_id'] = '[role_id]';

if ($splitByType) {
$q['select']['type'] = 'case when [role_id] LIKE \'AJXP_USR%\' then \'role_user\' when [role_id] LIKE \'AJXP_GRP%\' then \'role_grp\' else \'role_role\' end';
}

// Initing from
$q['from']['a'] = '[ajxp_roles]';

// Initing where and args
if(is_numeric($repositoryId)){
$likeRepositoryId = "i:$repositoryId;s:";
}else{
$likeRepositoryId = '"'.$repositoryId.'";s:';
}
switch ($this->sqlDriver["driver"]) {
case "sqlite":
case "sqlite3":
case "postgre":
if(!empty($rolePrefix)){
$children_results = dibi::query('SELECT [role_id] FROM [ajxp_roles] WHERE [searchable_repositories] LIKE %~like~ AND [role_id] LIKE %like~ GROUP BY [role_id]', '"'.$repositoryId.'";s:', $rolePrefix);
}else{
$children_results = dibi::query('SELECT [role_id] FROM [ajxp_roles] WHERE [searchable_repositories] LIKE %~like~ GROUP BY [role_id]', '"'.$repositoryId.'";s:');
}
$q['where'][] = ['[searchable_repositories] LIKE %~like~', $likeRepositoryId];
break;
case "mysql":
if(!empty($rolePrefix)){
$children_results = dibi::query('SELECT [role_id] FROM [ajxp_roles] WHERE [serial_role] LIKE %~like~ AND [role_id] LIKE %like~ GROUP BY [role_id]', '"'.$repositoryId.'";s:', $rolePrefix);
}else{
$children_results = dibi::query('SELECT [role_id] FROM [ajxp_roles] WHERE [serial_role] LIKE %~like~ GROUP BY [role_id]', '"'.$repositoryId.'";s:');
}
$q['where'][] = ['[serial_role] LIKE %~like~', $likeRepositoryId];
break;
default:
return "ERROR!, DB driver ". $this->sqlDriver["driver"] ." not supported yet in __FUNCTION__";
}
$all = $children_results->fetchAll();

if(!empty($rolePrefix)){
$q['where'][] = ['[role_id] LIKE %like~', $rolePrefix];
}

// Initing group by
$q['groupBy'][] = '[role_id]';

// Building the request from $q

// Building select
$reqStr = 'SELECT';
foreach ($q['select'] as $k => $v) {
$selectStr[] = $v.' as '.$k;
}
$reqStr .= ' ';
$reqStr .= join(', ', $selectStr);
$reqStr .= ' ';

// Building from
$reqStr .= 'FROM';
foreach ($q['from'] as $k => $v) {
$from[] = $v.' '.$k;
}
$reqStr .= ' ';
$reqStr .= join(', ', $from);
$reqStr .= ' ';

// Building where
if (!empty($q['where'])) {
$reqStr .= 'WHERE %and';
$reqStr .= ' ';
}

// Building group by
if (!empty($q['where'])) {
$reqStr .= 'GROUP BY';
$reqStr .= ' ';
$reqStr .= join(', ', $q['groupBy']);
$reqStr .= ' ';
}

$res = dibi::query($reqStr, $q['where']);
$all = $res->fetchAll();
foreach ($all as $item) {
$rId = $item["role_id"];
$allRoles[] = $rId;
$rId = $item['role_id'];

if ($splitByType) {
$type = $item['type'];
$allRoles[$type][] = $rId;
} else {
$allRoles[] = $rId;
}
}

return $allRoles;
}


public function getUsersForRole($roleId, $countOnly = false){
public function getUsersForRole($roleId, $countOnly = false) {
if($countOnly){
$res = dibi::query("SELECT count([login]) FROM [ajxp_user_rights] WHERE [repo_uuid] = %s AND [rights] LIKE %~like~", "ajxp.roles", '"'.$roleId.'";b:1');
return $res->fetchSingle();
Expand Down Expand Up @@ -602,52 +659,19 @@ public function countUsersForRepository($repositoryId, $details = false, $admin=
else return $groupUsers;
}
}

// Users from roles
$internal = 0;
$roles = $this->getRolesForRepository($repositoryId);
foreach($roles as $rId){
if(strpos($rId, "AJXP_USR_/") === 0) continue;
$internal += $this->getUsersForRole($rId, true);
}
$roles = $this->getRolesForRepository($repositoryId, '', $details);

// NEW METHOD : SEARCH PERSONAL ROLE
if(is_numeric($repositoryId)){
$likeValue = "i:$repositoryId;s:";
}else{
$likeValue = '"'.$repositoryId.'";s:';
}
switch ($this->sqlDriver["driver"]) {
case "sqlite":
case "sqlite3":
case "postgre":
$q = 'SELECT count([role_id]) FROM [ajxp_roles] WHERE [role_id] LIKE \'AJXP_USR_/%\' AND [searchable_repositories] LIKE %~like~';
break;
case "mysql":
$q = 'SELECT count([role_id]) as c FROM [ajxp_roles] WHERE [role_id] LIKE \'AJXP_USR_/%\' AND [serial_role] LIKE %~like~';
break;
default:
return "ERROR!, DB driver ". $this->sqlDriver["driver"] ." not supported yet in __FUNCTION__";
}
if($details){
if($this->sqlDriver["driver"] == "sqlite" || $this->sqlDriver["driver"] == "sqlite3"){
$internalClause = " AND NOT EXISTS (SELECT * FROM [ajxp_user_rights] WHERE [ajxp_roles].[role_id]='AJXP_USR_/'||[ajxp_user_rights].[login] AND [ajxp_user_rights].[repo_uuid] = 'ajxp.parent_user')";
$externalClause = " AND EXISTS (SELECT * FROM [ajxp_user_rights] WHERE [ajxp_roles].[role_id]='AJXP_USR_/'||[ajxp_user_rights].[login] AND [ajxp_user_rights].[repo_uuid] = 'ajxp.parent_user')";
}else{
$internalClause = " AND NOT EXISTS (SELECT * FROM [ajxp_user_rights] WHERE [ajxp_roles].[role_id]=CONCAT('AJXP_USR_/',[ajxp_user_rights].[login]) AND [ajxp_user_rights].[repo_uuid] = 'ajxp.parent_user')";
$externalClause = " AND EXISTS (SELECT * FROM [ajxp_user_rights] WHERE [ajxp_roles].[role_id]=CONCAT('AJXP_USR_/',[ajxp_user_rights].[login]) AND [ajxp_user_rights].[repo_uuid] = 'ajxp.parent_user')";
}
$intRes = dibi::query($q.$internalClause, $likeValue);
$extRes = dibi::query($q.$externalClause, $likeValue);
return array(
'internal' => $internal + $intRes->fetchSingle(),
'external' => $extRes->fetchSingle()
'users' => count($roles['role_user']),
'groups' => count($roles['role_group']) + count($roles['role_role'])
);
}else{
$res = dibi::query($q, $likeValue);
return $internal + $res->fetchSingle();

return count($roles);
}
//$all = $res->fetchAll();
}


Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/core.ajaxplorer/i18n/ca.php
Expand Up @@ -587,8 +587,8 @@
"527"=> "Compartit amb",
"528"=> "Usuaris interns",
"530"=> "Usuaris externs",
"531"=> "Int.",
"532"=> "Ext.",
"531"=> "Users",
"531"=> "Groups",
"533" => "Identificador emprat per accedir, per favor empri caràcters alfanumèrics en minúscules o correu electrònic.",
"534" => "Contrasenya emprada per acceder",
"535" => "Enviar contrasenya per correu electrònic",
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/core.ajaxplorer/i18n/cs.php
Expand Up @@ -586,8 +586,8 @@
"527"=> "Sdíleno s",
"528"=> "Interními uživateli",
"530"=> "Externími uživateli",
"531"=> "Int.",
"532"=> "Ext.",
"531"=> "Users",
"531"=> "Groups",
"533" => "Identifikátor použitý pro přihlášení, použijte prosím pouze písmena a čísla nebo znaky emailu malými písmeny.",
"534" => "Heslo pro přihlášení",
"535" => "Poslat heslo e-mailem",
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/core.ajaxplorer/i18n/da.php
Expand Up @@ -589,8 +589,8 @@
"527"=> "Shared with",
"528"=> "Internal users",
"530"=> "External users",
"531"=> "Int.",
"532"=> "Ext.",
"531"=> "Users",
"531"=> "Groups",
"533" => "Identifier used to login, please use alphanumeric or email lowercase characters.",
"534" => "Password used to login",
"535" => "Send password by email",
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/core.ajaxplorer/i18n/de.php
Expand Up @@ -593,8 +593,8 @@
"527"=> "Geteilt mit",
"528"=> "Interne Benutzer",
"530"=> "Externe Benutzer",
"531"=> "Intern",
"532"=> "Extern",
"531"=> "Users",
"531"=> "Groups",
"533" => "Identifier used to login, please use alphanumeric or email lowercase characters.",
"534" => "Password used to login",
"535" => "Sende Passwort via E-Mail",
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/core.ajaxplorer/i18n/en.php
Expand Up @@ -586,8 +586,8 @@
"527"=> "Shared with",
"528"=> "Internal users",
"530"=> "External users",
"531"=> "Int.",
"532"=> "Ext.",
"531"=> "Users",
"531"=> "Groups",
"533" => "Identifier used to login, please use alphanumeric or email lowercase characters.",
"534" => "Password used to login",
"535" => "Send password by email",
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/core.ajaxplorer/i18n/es.php
Expand Up @@ -591,8 +591,8 @@
"527"=> "Compartido con",
"528"=> "Usuarios internos",
"530"=> "Usuarios externos",
"531"=> "Int.",
"532"=> "Ext.",
"531"=> "Users",
"531"=> "Groups",
"533" => "Identificador usado para acceder, por favor utilice caracteres alfanuméricos en minúsculas o correo electrónico.",
"534" => "Contraseña usada para acceder",
"535" => "Enviar contraseña por correo electrónico",
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/core.ajaxplorer/i18n/et.php
Expand Up @@ -587,8 +587,8 @@
"527"=> "Shared with",
"528"=> "Internal users",
"530"=> "External users",
"531"=> "Int.",
"532"=> "Ext.",
"531"=> "Users",
"531"=> "Groups",
"533" => "Identifier used to login, please use alphanumeric or email lowercase characters.",
"534" => "Password used to login",
"535" => "Send password by email",
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/core.ajaxplorer/i18n/eus.php
Expand Up @@ -585,8 +585,8 @@
"527"=> "Shared with",
"528"=> "Internal users",
"530"=> "External users",
"531"=> "Int.",
"532"=> "Ext.",
"531"=> "Users",
"531"=> "Groups",
"533" => "Identifier used to login, please use alphanumeric or email lowercase characters.",
"534" => "Password used to login",
"535" => "Send password by email",
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/core.ajaxplorer/i18n/fi.php
Expand Up @@ -587,8 +587,8 @@
"527"=> "Shared with",
"528"=> "Internal users",
"530"=> "External users",
"531"=> "Int.",
"532"=> "Ext.",
"531"=> "Users",
"531"=> "Groups",
"533" => "Identifier used to login, please use alphanumeric or email lowercase characters.",
"534" => "Password used to login",
"535" => "Send password by email",
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/core.ajaxplorer/i18n/fr.php
Expand Up @@ -586,8 +586,8 @@
"527"=> "Partagé",
"528"=> "Utilisateurs internes",
"530"=> "Utilisateurs externes",
"531"=> "Int.",
"532"=> "Ext.",
"531"=> "Users",
"531"=> "Groups",
"533" => "Identifiant utilisé pour se logger, veuillez utiliser des caractères alphanumériques ou d'email, en minuscule.",
"534" => "Mot de passe utilisé pour se logger",
"535" => "Envoyer le mot de passe par email",
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/core.ajaxplorer/i18n/gr.php
Expand Up @@ -584,8 +584,8 @@
"527"=> "Shared with",
"528"=> "Internal users",
"530"=> "External users",
"531"=> "Int.",
"532"=> "Ext.",
"531"=> "Users",
"531"=> "Groups",
"533" => "Identifier used to login, please use alphanumeric or email lowercase characters.",
"534" => "Password used to login",
"535" => "Send password by email",
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/core.ajaxplorer/i18n/he.php
Expand Up @@ -584,8 +584,8 @@
"527"=> "Shared with",
"528"=> "Internal users",
"530"=> "External users",
"531"=> "Int.",
"532"=> "Ext.",
"531"=> "Users",
"531"=> "Groups",
"533" => "Identifier used to login, please use alphanumeric or email lowercase characters.",
"534" => "Password used to login",
"535" => "Send password by email",
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/core.ajaxplorer/i18n/hu.php
Expand Up @@ -589,8 +589,8 @@
"527"=> "Shared with",
"528"=> "Internal users",
"530"=> "External users",
"531"=> "Int.",
"532"=> "Ext.",
"531"=> "Users",
"531"=> "Groups",
"533" => "Identifier used to login, please use alphanumeric or email lowercase characters.",
"534" => "Password used to login",
"535" => "Send password by email",
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/core.ajaxplorer/i18n/it.php
Expand Up @@ -604,8 +604,8 @@
"527"=> "Condiviso con",
"528"=> "Utenti Interni",
"530"=> "Utenti Esterni",
"531"=> "Int.",
"532"=> "Est.",
"531"=> "Users",
"531"=> "Groups",
"533" => "Identifier used to login, please use alphanumeric or email lowercase characters.",
"534" => "Password used to login",
"535" => "Send password by email",
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/core.ajaxplorer/i18n/ja.php
Expand Up @@ -589,8 +589,8 @@
"527"=> "Shared with",
"528"=> "Internal users",
"530"=> "External users",
"531"=> "Int.",
"532"=> "Ext.",
"531"=> "Users",
"531"=> "Groups",
"533" => "Identifier used to login, please use alphanumeric or email lowercase characters.",
"534" => "Password used to login",
"535" => "Send password by email",
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/core.ajaxplorer/i18n/kr.php
Expand Up @@ -593,8 +593,8 @@
"527"=> "Shared with",
"528"=> "Internal users",
"530"=> "External users",
"531"=> "Int.",
"532"=> "Ext.",
"531"=> "Users",
"531"=> "Groups",
"533" => "Identifier used to login, please use alphanumeric or email lowercase characters.",
"534" => "Password used to login",
"535" => "Send password by email",
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/core.ajaxplorer/i18n/nl.php
Expand Up @@ -590,8 +590,8 @@
"527"=> "Shared with",
"528"=> "Internal users",
"530"=> "External users",
"531"=> "Int.",
"532"=> "Ext.",
"531"=> "Users",
"531"=> "Groups",
"533" => "Identifier used to login, please use alphanumeric or email lowercase characters.",
"534" => "Password used to login",
"535" => "Send password by email",
Expand Down

0 comments on commit 7c05d5c

Please sign in to comment.