Skip to content
Snippets Groups Projects
Commit 643ac803 authored by Moreau Elise's avatar Moreau Elise
Browse files

resolve group id bug

parent 6f0274a1
Branches
No related tags found
No related merge requests found
...@@ -14,23 +14,29 @@ class AddUsersGroupAction extends GroupAction ...@@ -14,23 +14,29 @@ class AddUsersGroupAction extends GroupAction
*/ */
protected function action(): Response protected function action(): Response
{ {
$parsedRequestBody = (array)$this->request->getParsedBody();
$groupId = (int) $this->resolveArg('id'); $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']; $user_ids = $parsedRequestBody['ids'];
if (!isset($group)) { if (!isset($group)) {
throw new GroupNotFoundException(); throw new GroupNotFoundException();
} }
$users_query = $this->userRepository->createQueryBuilder('u'); $users_query = $this->userRepository->createQueryBuilder('u');
$users_list = $users_query $users_list = $users_query
->where('u.id IN (:user_ids)') ->where('u.id IN (:user_ids)')
->setParameter('user_ids', $user_ids) ->setParameter('user_ids', $user_ids)
->getQuery() ->getQuery()
->getResult(); ->getResult();
foreach ($users_list as $user) { foreach ($users_list as $user) {
if (!$group->hasUser($user->getId())) { if (!$group->hasUser($user->getId())) {
$user->addGroup($group); $user->addGroup($group);
......
...@@ -50,7 +50,7 @@ class CreateGroupAction extends GroupAction ...@@ -50,7 +50,7 @@ class CreateGroupAction extends GroupAction
$this->logger->info("Group has been created."); $this->logger->info("Group has been created.");
return $this->response return $this->response
->withHeader('Location', '/groups' . $groupId) ->withHeader('Location', '/groups' . $group->getId())
->withStatus(302); ->withStatus(302);
} }
......
...@@ -19,7 +19,7 @@ class AccountAction extends UserAction ...@@ -19,7 +19,7 @@ class AccountAction extends UserAction
->withHeader('Location', '/login') ->withHeader('Location', '/login')
->withStatus(302); ->withStatus(302);
} }
$user = $this->userRepository->find($_SESSION['userId']); $user = $this->userRepository->find($_SESSION['userId']);
if (!isset($user)) { if (!isset($user)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment