Skip to content

Commit

Permalink
Fixed issue #18294: User can not see group created and user in group …
Browse files Browse the repository at this point in the history
…created (#3504)
  • Loading branch information
Shnoulle committed Oct 2, 2023
1 parent f5e3a0f commit f83e0e8
Showing 1 changed file with 18 additions and 30 deletions.
48 changes: 18 additions & 30 deletions application/helpers/common_helper.php
Expand Up @@ -674,43 +674,30 @@ function getUserList($outputformat = 'fullinfoarray')
$usercontrolSameGroupPolicy == true
) {
if (isset($myuid)) {
$sDatabaseType = Yii::app()->db->getDriverName();
if ($sDatabaseType == 'mssql' || $sDatabaseType == "sqlsrv" || $sDatabaseType == "dblib") {
$sSelectFields = 'users_name,uid,email,full_name,parent_id,CAST(password as varchar) as password';
} else {
$sSelectFields = 'users_name,uid,email,full_name,parent_id,password';
}

// List users from same group as me + all my childs
// a subselect is used here because MSSQL does not like to group by text
// also Postgres does like this one better
$uquery = " SELECT {$sSelectFields} from {{users}} where uid in (
SELECT uid from {{user_in_groups}} where ugid in (
SELECT ugid from {{user_in_groups}} where uid={$myuid}
)
)
UNION
SELECT {$sSelectFields} from {{users}} v where v.parent_id={$myuid}
UNION
SELECT {$sSelectFields} from {{users}} v where uid={$myuid}";
$userGroupList = getUserGroupList();
$criteria = new CDBCriteria();
$criteria->order = 'full_name, users_name, t.uid';
$criteria->with = 'groups';
/* users in usergroup */
$criteria->addInCondition('groups.ugid', $userGroupList);
/* childs of this user */
$criteria->compare('parent_id', $myuid, false, 'OR');
/* himself */
$criteria->compare('t.uid', $myuid, false, 'OR');
$oUsers = User::model()->findAll($criteria);
} else {
return array(); // Or die maybe
}
} else {
$uquery = "SELECT * FROM {{users}} ORDER BY uid";
}

$uresult = Yii::app()->db->createCommand($uquery)->query()->readAll(); //Checked

if (count($uresult) == 0 && !empty($myuid)) {
//user is not in a group and usercontrolSameGroupPolicy is activated - at least show their own userinfo
$uquery = "SELECT u.* FROM {{users}} AS u WHERE u.uid=" . $myuid;
$uresult = Yii::app()->db->createCommand($uquery)->query()->readAll(); //Checked
$oUsers = User::model()->findAll([
'order' => 'full_name, users_name, t.uid'
]);
}

$userlist = array();
$userlist[0] = "Reserved for logged in user";
foreach ($uresult as $srow) {
foreach ($oUsers as $oUser) {
$srow = $oUser->getAttributes();
if ($outputformat != 'onlyuidarray') {
if ($srow['uid'] != Yii::app()->session['loginID']) {
$userlist[] = array(
Expand Down Expand Up @@ -4205,7 +4192,8 @@ function getUserGroupList()
$sQuery = "SELECT distinct a.ugid, a.name, a.owner_id FROM {{user_groups}} AS a LEFT JOIN {{user_in_groups}} AS b ON a.ugid = b.ugid WHERE 1=1 ";
if (shouldFilterUserGroupList()) {
$userid = intval(App()->session['loginID']);
$sQuery .= "AND (b.uid = {$userid})";
$sQuery .= " AND (b.uid = {$userid})";
$sQuery .= " OR (a.owner_id = {$userid})";
}
$sQuery .= " ORDER BY name";

Expand Down

0 comments on commit f83e0e8

Please sign in to comment.