Commit 643ac803 authored by Moreau Elise's avatar Moreau Elise
Browse files

resolve group id bug

parent 6f0274a1
......@@ -14,23 +14,29 @@ class AddUsersGroupAction extends GroupAction
*/
protected function action(): Response
{
$parsedRequestBody = (array)$this->request->getParsedBody();
$groupId = (int) $this->resolveArg('id');
$group = $this->groupRepository->find($groupId);
if (!isset($parsedRequestBody['ids']))
{
return $this->response
->withHeader('Location', '/groups/' . $groupId)
->withStatus(302);
}
$parsedRequestBody = (array)$this->request->getParsedBody();
$group = $this->groupRepository->find($groupId);
$user_ids = $parsedRequestBody['ids'];
if (!isset($group)) {
throw new GroupNotFoundException();
}
$users_query = $this->userRepository->createQueryBuilder('u');
$users_list = $users_query
->where('u.id IN (:user_ids)')
->setParameter('user_ids', $user_ids)
->getQuery()
->getResult();
foreach ($users_list as $user) {
if (!$group->hasUser($user->getId())) {
$user->addGroup($group);
......
......@@ -50,7 +50,7 @@ class CreateGroupAction extends GroupAction
$this->logger->info("Group has been created.");
return $this->response
->withHeader('Location', '/groups' . $groupId)
->withHeader('Location', '/groups' . $group->getId())
->withStatus(302);
}
......
......@@ -19,7 +19,7 @@ class AccountAction extends UserAction
->withHeader('Location', '/login')
->withStatus(302);
}
$user = $this->userRepository->find($_SESSION['userId']);
if (!isset($user)) {
......
Supports Markdown
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