Skip to content
Snippets Groups Projects
Verified Commit 08d5bce9 authored by Damien's avatar Damien
Browse files

FEAT #10742 TIME 0:45 Manage substitute with substituted

parent b0b6480b
No related branches found
No related tags found
No related merge requests found
......@@ -35,7 +35,7 @@ class UserController
{
$queryParams = $request->getQueryParams();
$select = ['id', 'firstname', 'lastname'];
$select = ['id', 'firstname', 'lastname', 'substitute'];
if (!empty($queryParams['mode']) && $queryParams['mode'] == 'rest') {
if (!UserController::hasPrivilege(['userId' => $GLOBALS['id'], 'privilege' => 'manage_rest_users'])) {
return $response->withStatus(403)->withJson(['errors' => 'Privilege forbidden']);
......@@ -56,6 +56,10 @@ class UserController
'orderBy' => ['lastname', 'firstname']
]);
foreach ($users as $key => $user) {
$users[$key]['substitute'] = !empty($user['substitute']);
}
return $response->withJson(['users' => $users]);
}
......@@ -191,9 +195,20 @@ class UserController
}
$set['substitute'] = null;
if (!empty($body['substitute']) && $args['id'] != $body['substitute']) {
$existingUser = UserModel::getById(['id' => $body['substitute'], 'select' => [1]]);
$existingUser = UserModel::getById(['id' => $body['substitute'], 'select' => ['substitute']]);
if (empty($existingUser)) {
return $response->withStatus(400)->withJson(['errors' => 'Substitute user does not exist']);
} elseif (!empty($existingUser['substitute'])) {
return $response->withStatus(400)->withJson(['errors' => 'Substitute user has already substituted']);
}
$substitutedUsers = UserModel::get(['select' => ['id'], 'where' => ['substitute = ?'], 'data' => [$args['id']]]);
foreach ($substitutedUsers as $user) {
UserModel::update([
'set' => ['substitute' => $body['substitute']],
'where' => ['id = ?'],
'data' => [$user['id']]
]);
}
$set['substitute'] = $body['substitute'];
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment