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

delete user from a group when admin

parent 3657a0e8
No related branches found
No related tags found
No related merge requests found
<?php
declare(strict_types=1);
namespace App\Application\Actions\Group;
use App\Domain\Group\GroupNotFoundException;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use App\Domain\Group\Group ;
class DeleteUserGroupAction extends GroupAction
{
/**
* {@inheritdoc}
*/
protected function action(): Response
{
$groupId = (int) $this->resolveArg('id');
$group = $this->groupRepository->find($groupId);
$user_id = (int) $this->resolveArg('user_id');
if (!isset($group)) {
throw new GroupNotFoundException();
}
if (!$group->checkAdmin($user_id))
{
return $this->response
->withHeader('Location', '/groups/' . $groupId)
->withStatus(302);
}
$user = $this->userRepository->find($user_id);
$user->removeGroup($group);
$this->em->persist($group);
$this->em->flush();
$this->logger->info("User has been deleted in group.");
$this->flash->addMessage('delete_user', 'User have been deleted in group.');
return $this->response
->withHeader('Location', '/groups/' . $groupId)
->withStatus(302);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment