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

Commit

Permalink
Add selection on listing Role by user roles or all roles
Browse files Browse the repository at this point in the history
Hide prefix on role/group label
  • Loading branch information
c12simple committed Nov 18, 2014
1 parent fd65252 commit 2e2d0e1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
32 changes: 27 additions & 5 deletions core/src/plugins/core.conf/class.AbstractConfDriver.php
Expand Up @@ -1075,10 +1075,26 @@ public function switchAction($action, $httpVars, $fileVars)
if(!is_array($roleOrGroup)){
$roleOrGroup = array("group_switch_value" => $roleOrGroup);
}

$listRoleType = false;

if(isSet($roleOrGroup["PREFIX"])){
$rolePrefix = $loggedUser->mergedRole->filterParameterValue("core.conf", "PREFIX", null, $roleOrGroup["PREFIX"]);
$excludeString = $loggedUser->mergedRole->filterParameterValue("core.conf", "EXCLUDED", null, $roleOrGroup["EXCLUDED"]);
$includeString = $loggedUser->mergedRole->filterParameterValue("core.conf", "INCLUDED", null, $roleOrGroup["INCLUDED"]);
$listUserRolesOnly = $loggedUser->mergedRole->filterParameterValue("core.conf", "LIST_ROLE_BY", null, $roleOrGroup["LIST_ROLE_BY"]);
if (is_array($listUserRolesOnly) && isset($listUserRolesOnly["group_switch_value"])) {
switch ($listUserRolesOnly["group_switch_value"]) {
case "userroles":
$listRoleType = true;
break;
case "allroles":
$listRoleType = false;
break;
default;
break;
}
}
}

switch (strtolower($roleOrGroup["group_switch_value"])) {
Expand All @@ -1094,7 +1110,7 @@ public function switchAction($action, $httpVars, $fileVars)
break;
case 'role':
$allUsers = AuthService::listUsers($baseGroup, $regexp, 0, $limit, false);
$allGroups = $this->getUserRoleList($loggedUser, $rolePrefix, $includeString, $excludeString);
$allGroups = $this->getUserRoleList($loggedUser, $rolePrefix, $includeString, $excludeString, $listRoleType);
break;
case 'rolegroup';
$allUsers = AuthService::listUsers($baseGroup, $regexp, 0, $limit, false);
Expand All @@ -1103,7 +1119,7 @@ public function switchAction($action, $httpVars, $fileVars)
foreach ($authGroups as $gId => $gName) {
$groups["AJXP_GRP_" . AuthService::filterBaseGroup($gId)] = $gName;
}
$roles = $this->getUserRoleList($loggedUser, $rolePrefix, $includeString, $excludeString);
$roles = $this->getUserRoleList($loggedUser, $rolePrefix, $includeString, $excludeString, $listRoleType);

empty($groups) ? $allGroups = $roles : (empty($roles) ? $allGroups = $groups : $allGroups = array_merge($groups, $roles));
//$allGroups = array_merge($groups, $roles);
Expand All @@ -1125,7 +1141,7 @@ public function switchAction($action, $httpVars, $fileVars)
if ($regexp == null && !$usersOnly) {
$users .= "<li class='complete_group_entry' data-group='AJXP_GRP_/' data-label='".$mess["447"]."'><span class='user_entry_label'>".$mess["447"]."</span></li>";
}
if (!$usersOnly) {
if (!$usersOnly && is_array($allGroups)) {
foreach ($allGroups as $groupId => $groupLabel) {
if ($regexp == null || preg_match("/$regexp/i", $groupLabel)) {
$users .= "<li class='complete_group_entry' data-group='$groupId' data-label='$groupLabel' data-entry_id='$groupId'><span class='user_entry_label'>".$groupLabel."</span></li>";
Expand Down Expand Up @@ -1253,10 +1269,14 @@ public function switchAction($action, $httpVars, $fileVars)
* @param $excludeString eliminate roles in this string
* @return array
*/
public function getUserRoleList($userObject, $rolePrefix, $includeString, $excludeString)
public function getUserRoleList($userObject, $rolePrefix, $includeString, $excludeString, $byUserRoles = false)
{
if ($userObject) {
if ($byUserRoles) {
$allUserRoles = $userObject->getRoles();
} else {
$allUserRoles = AuthService::getRolesList();
}
$allRoles = array();
if (isset($allUserRoles)) {

Expand Down Expand Up @@ -1288,7 +1308,9 @@ public function getUserRoleList($userObject, $rolePrefix, $includeString, $exclu
if (isSet($valueFiltersInclude) && !in_array(strtolower(substr($roleId, strlen($rolePrefix))), $valueFiltersInclude)) continue;
$roleObject = AuthService::getRole($roleId);
$label = $roleObject->getLabel();
$allRoles[$roleId] = !empty($label) ? $label : substr($roleId, strlen($rolePrefix));
$label = !empty($label) ? $label : $roleId;

$allRoles[$roleId] = substr($label, strlen($rolePrefix));
}
}
return $allRoles;
Expand Down
10 changes: 10 additions & 0 deletions core/src/plugins/core.conf/manifest.xml
Expand Up @@ -49,13 +49,23 @@
<global_param group_switch_name="GROUP_OR_ROLE" group_switch_label="Role/Group Listing" group_switch_value="RoleGroup" name="GROUP_AND_ROLE" type="hidden" label="" description="" default="rolegroup"/>



<global_param group_switch_name="GROUP_OR_ROLE" group_switch_label="List role by" group_switch_value="Role" name="LIST_ROLE_BY" type="group_switch:LIST_ROLE_BY" label="CONF_MESSAGE[List Roles By]"
description="List role by" default="all" mandatory="true" />
<global_param group_switch_name="LIST_ROLE_BY" group_switch_label="All roles" group_switch_value="allroles" name="ALL_ROLES" type="hidden" label="" description="" default="allrolls"/>
<global_param group_switch_name="LIST_ROLE_BY" group_switch_label="User roles only" group_switch_value="userroles" name="USER_ROLES_ONLY" type="hidden" label="" description="" default="userroles"/>
<global_param group_switch_name="GROUP_OR_ROLE" group_switch_label="Allow Role Listing" group_switch_value="Role" name="PREFIX" type="string" label="CONF_MESSAGE[role prefix]"
description="role refix" default="ldapgroup_" mandatory="false"/>
<global_param group_switch_name="GROUP_OR_ROLE" group_switch_label="Allow Role Listing" group_switch_value="Role" name="EXCLUDED" type="textarea" label="CONF_MESSAGE[Excluded Roles]"
description="Some roles should be disappered in the list. list separated by ',' or start with 'preg:' for regex." default="" mandatory="false" />
<global_param group_switch_name="GROUP_OR_ROLE" group_switch_label="Allow Role Listing" group_switch_value="Role" name="INCLUDED" type="textarea" label="CONF_MESSAGE[Included Roles]"
description="Some roles should be shown in the list. list separated by ',' or start with 'preg:' for regex." default="" mandatory="false" />


<global_param group_switch_name="GROUP_OR_ROLE" group_switch_label="List role by" group_switch_value="Role" name="LIST_ROLE_BY" type="group_switch:LIST_ROLE_BY" label="CONF_MESSAGE[List Roles By]"
description="List role by" default="all" mandatory="true" />
<global_param group_switch_name="LIST_ROLE_BY" group_switch_label="All roles" group_switch_value="allroles" name="ALL_ROLES" type="hidden" label="" description="" default="allrolls"/>
<global_param group_switch_name="LIST_ROLE_BY" group_switch_label="User roles only" group_switch_value="userroles" name="USER_ROLES_ONLY" type="hidden" label="" description="" default="userroles"/>
<global_param group_switch_name="GROUP_OR_ROLE" group_switch_label="Allow Role Listing" group_switch_value="RoleGroup" name="PREFIX" type="string" label="CONF_MESSAGE[role prefix]"
description="role refix" default="ldapgroup_" mandatory="false" />
<global_param group_switch_name="GROUP_OR_ROLE" group_switch_label="Allow Role Listing" group_switch_value="RoleGroup" name="EXCLUDED" type="textarea" label="CONF_MESSAGE[Excluded Roles]"
Expand Down

0 comments on commit 2e2d0e1

Please sign in to comment.