Verified Commit ab13c3f4 authored by Damien's avatar Damien

FEAT #10730 TIME 0:15 hasAdmin

parent d7219049
......@@ -67,4 +67,29 @@ class PrivilegeController
return false;
}
public static function hasAdmin(array $args)
{
ValidatorModel::notEmpty($args, ['userId']);
ValidatorModel::intVal($args, ['userId']);
$groups = UserGroupModel::get(['select' => ['group_id'], 'where' => ['user_id = ?'], 'data' => [$args['userId']]]);
$allGroups = array_column($groups, 'group_id');
if (!empty($allGroups)) {
$privileges = UserGroupModel::getPrivileges(['select' => ['privilege'], 'where' => ['group_id in (?)'], 'data' => [$allGroups]]);
$privileges = array_column($privileges, 'privilege');
if (!empty($privileges)) {
foreach (PrivilegeController::PRIVILEGES as $value) {
if ($value['type'] == 'admin' && in_array($value['id'], $privileges)) {
return true;
}
}
}
}
return false;
}
}
......@@ -71,9 +71,6 @@ class UserController
}
$user = UserController::getUserInformationsById(['id' => $args['id']]);
if ($GLOBALS['id'] != $args['id']) {
unset($user['preferences'], $user['availableLanguages']);
}
$user['groups'] = [];
$userGroups = UserGroupModel::get(['select' => ['group_id'], 'where' => ['user_id = ?'], 'data' => [$args['id']]]);
......@@ -496,8 +493,11 @@ class UserController
$user['picture'] = 'data:image/png;base64,' . $user['picture'];
}
$user['preferences'] = json_decode($user['preferences'], true);
$user['availableLanguages'] = LanguageController::getAvailableLanguages();
if ($GLOBALS['id'] == $args['id']) {
$user['preferences'] = json_decode($user['preferences'], true);
$user['availableLanguages'] = LanguageController::getAvailableLanguages();
$user['hasAdmin'] = PrivilegeController::hasAdmin(['userId' => $args['id']]);
}
return $user;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment