Merge branch 'ent-8447-conteo-erroneo-de-usuarios-en-index' into 'develop'

Fix users count on index and user list

See merge request artica/pandorafms!4702
This commit is contained in:
Daniel Rodriguez 2022-03-10 10:48:38 +00:00
commit cc6ab1a10a
3 changed files with 38 additions and 11 deletions

View File

@ -545,6 +545,13 @@ if ($search) {
}
}
foreach ($info1 as $user_id => $user_info) {
// If user is not admin then don't display admin users.
if ($user_is_admin === false && (bool) $user_info['is_admin'] === true) {
unset($info1[$user_id]);
}
}
$info = $info1;
// Prepare pagination.
@ -557,11 +564,6 @@ $rowPair = true;
$iterator = 0;
$cont = 0;
foreach ($info as $user_id => $user_info) {
if (!$user_is_admin && $user_info['is_admin']) {
// If user is not admin then don't display admin users.
continue;
}
// User profiles.
if ($user_is_admin || $user_id == $config['id_user'] || isset($group_um[0])) {
$user_profiles = db_get_all_rows_field_filter(

View File

@ -11186,11 +11186,29 @@ function reporting_get_stats_users($data)
$tdata = [];
$tdata[0] = html_print_image('images/user.png', true, ['title' => __('Defined users'), 'class' => 'invert_filter']);
$user_groups = users_get_strict_mode_groups($config['id_user'], false);
if (array_key_exists(0, $user_groups)) {
$users = users_get_user_users($config['id_user'], 'AR', true);
$user_is_admin = users_is_admin();
$users = [];
if ($user_is_admin) {
$users = get_users('', ['disabled' => 0], ['id_user', 'is_admin']);
} else {
$users = users_get_user_users($config['id_user'], 'AR', false);
$group_um = users_get_groups_UM($config['id_user']);
// 0 is the group 'all'.
if (isset($group_um[0])) {
$users = get_users('', ['disabled' => 0], ['id_user', 'is_admin']);
} else {
foreach ($group_um as $group => $value) {
$users = array_merge($users, users_get_users_by_group($group, $value, false));
}
}
}
foreach ($users as $user_id => $user_info) {
// If user is not admin then don't display admin users.
if ($user_is_admin === false && (bool) $user_info['is_admin'] === true) {
unset($users[$user_id]);
}
}
$tdata[1] = count($users);

View File

@ -777,10 +777,13 @@ function users_get_groups_UM($id_user)
/**
* Obtiene una matriz con los grupos como clave y si tiene o no permiso UM sobre ese grupo(valor)
*
* @param string User id
* @param string $id_group User id.
* @param boolean $um Um.
* @param boolean $disabled Reurn also disabled users.
*
* @return array Return .
*/
function users_get_users_by_group($id_group, $um=false)
function users_get_users_by_group($id_group, $um=false, $disabled=true)
{
$sql = sprintf(
"SELECT tusuario.* FROM tusuario
@ -789,6 +792,10 @@ function users_get_users_by_group($id_group, $um=false)
$id_group
);
if ($disabled === false) {
$sql .= 'WHERE tusuario.disabled = 0';
}
$users = db_get_all_rows_sql($sql);
$return = [];
foreach ($users as $key => $user) {