From 3657a0e80582eda12fc4081e865b173707607c77 Mon Sep 17 00:00:00 2001
From: Moreau Elise <moreau.elise13@gmail.com>
Date: Tue, 13 Oct 2020 14:36:24 +0200
Subject: [PATCH] add users in a group if user is admin

---
 src/Application/Actions/Group/AddUserGroupAction.php | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/Application/Actions/Group/AddUserGroupAction.php b/src/Application/Actions/Group/AddUserGroupAction.php
index 04155ee..cff8adf 100755
--- a/src/Application/Actions/Group/AddUserGroupAction.php
+++ b/src/Application/Actions/Group/AddUserGroupAction.php
@@ -20,7 +20,13 @@ class AddUserGroupAction extends GroupAction
         if (!isset($group)) {
             throw new GroupNotFoundException();
         }
+    
         $currentUser = $this->userRepository->find($_SESSION['userId']);
+        if ($this->group->hasUser($currentUser)){
+            return $this->response
+            ->withHeader('Location', '/groups/' . $groupId)
+            ->withStatus(302);
+        }
         $currentUser->addGroup($group);        
 
         $this->em->persist($group);
-- 
GitLab