Added log to create user
This commit is contained in:
parent
346a05e51d
commit
8193e339b0
|
|
@ -16,6 +16,7 @@ use App\Service\UserOrganizationAppService;
|
|||
use App\Service\UserOrganizationService;
|
||||
use App\Service\UserService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
|
@ -36,7 +37,7 @@ class UserController extends AbstractController
|
|||
private readonly UserOrganizationService $userOrganizationService,
|
||||
private readonly UserRepository $userRepository,
|
||||
private readonly UsersOrganizationsRepository $uoRepository,
|
||||
private readonly OrganizationsRepository $organizationRepository,
|
||||
private readonly OrganizationsRepository $organizationRepository, private readonly LoggerInterface $logger,
|
||||
)
|
||||
{
|
||||
}
|
||||
|
|
@ -130,6 +131,7 @@ class UserController extends AbstractController
|
|||
public function new(Request $request): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted('ROLE_ADMIN');
|
||||
try {
|
||||
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier());
|
||||
if ($this->userService->hasAccessTo($actingUser)) {
|
||||
$user = new User();
|
||||
|
|
@ -158,24 +160,32 @@ class UserController extends AbstractController
|
|||
$uo->setIsActive(false);
|
||||
$this->entityManager->persist($uo);
|
||||
$this->actionService->createAction("Create new user", $user, $org, "Added user to organization" . $user->getUserIdentifier() . " for organization " . $org->getName());
|
||||
return $this->redirectToRoute('organization_show', ['id' => $orgId]);
|
||||
$this->logger->notice("User added to organization " . $org->getName());
|
||||
}
|
||||
}
|
||||
|
||||
$this->actionService->createAction("Create new user", $actingUser, null, $user->getUserIdentifier());
|
||||
|
||||
$this->logger->notice("User created " . $user->getUserIdentifier());
|
||||
$this->entityManager->persist($user);
|
||||
$this->entityManager->flush();
|
||||
|
||||
if( $orgId) {
|
||||
return $this->redirectToRoute('user_show', ['id' => $user->getId(), 'organizationId' => $orgId]);
|
||||
}
|
||||
return $this->redirectToRoute('user_index');
|
||||
}
|
||||
|
||||
}
|
||||
return $this->render('user/new.html.twig', [
|
||||
'user' => $user,
|
||||
'form' => $form->createView(),
|
||||
'organizationId' => $orgId
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error($e->getMessage());
|
||||
if( $orgId) {
|
||||
return $this->redirectToRoute('organization_show', ['id' => $orgId]);
|
||||
}
|
||||
return $this->redirectToRoute('user_index');
|
||||
}
|
||||
|
||||
throw $this->createAccessDeniedException(self::ACCESS_DENIED);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue