Log actions
This commit is contained in:
parent
2f3e28757e
commit
3894d72439
|
|
@ -4,6 +4,7 @@ namespace App\Controller;
|
|||
|
||||
use App\Entity\Apps;
|
||||
use App\Entity\Roles;
|
||||
use App\Entity\User;
|
||||
use App\Entity\UsersOrganizations;
|
||||
use App\Form\OrganizationForm;
|
||||
use App\Service\ActionService;
|
||||
|
|
@ -25,7 +26,7 @@ class OrganizationController extends AbstractController
|
|||
|
||||
public function __construct(private readonly EntityManagerInterface $entityManager,
|
||||
private readonly OrganizationsService $organizationsService,
|
||||
private readonly UserOrganizationService $usersOrganizationService)
|
||||
private readonly UserOrganizationService $usersOrganizationService, private readonly ActionService $actionService)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -63,7 +64,6 @@ class OrganizationController extends AbstractController
|
|||
$form->handleRequest($request);
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$organization = $form->getData();
|
||||
// dd($form);
|
||||
$logoFile = $form->get('logoUrl')->getData();
|
||||
|
||||
if ($logoFile) {
|
||||
|
|
@ -82,6 +82,9 @@ class OrganizationController extends AbstractController
|
|||
}
|
||||
$this->entityManager->persist($organization);
|
||||
$this->entityManager->flush();
|
||||
$user = $this->getUser() ?? throw $this->createNotFoundException(self::NOT_FOUND);
|
||||
$user = $this->entityManager->getRepository(User::class)->findOneBy(['email' => $user->getUserIdentifier()]);
|
||||
$this->actionService->createAction("Création d'une organisation",$user, null, "{$user->getUserIdentifier()} a crée l'organisation {$organization->getName()}");
|
||||
$this->addFlash('success', 'Organization created successfully');
|
||||
return $this->redirectToRoute('organization_index');
|
||||
}
|
||||
|
|
@ -141,7 +144,7 @@ class OrganizationController extends AbstractController
|
|||
public function edit(Request $request): Response
|
||||
{
|
||||
$id = $request->attributes->get('id');
|
||||
if (!$this->isGranted('ROLE_SUPER_ADMIN')) {
|
||||
if (!$this->isGranted('ROLE_ADMIN')) {
|
||||
throw $this->createNotFoundException(self::ACCESS_DENIED);
|
||||
}
|
||||
$organization = $this->entityManager->getRepository(Organizations::class)->find($id);
|
||||
|
|
@ -167,6 +170,9 @@ class OrganizationController extends AbstractController
|
|||
// Update the 'logoUrl' property to store the file name
|
||||
$organization->setLogoUrl($newFilename);
|
||||
}
|
||||
$user = $this->getUser() ?? throw $this->createNotFoundException(self::NOT_FOUND);
|
||||
$user = $this->entityManager->getRepository(User::class)->findOneBy(['email' => $user->getUserIdentifier()]);
|
||||
$this->actionService->createAction("Modification d'une organisation",$user, $organization, "{$user->getUserIdentifier()} a modifié l'organisation {$organization->getName()}");
|
||||
$this->entityManager->persist($organization);
|
||||
$this->entityManager->flush();
|
||||
$this->addFlash('success', 'Organization updated successfully');
|
||||
|
|
@ -193,6 +199,9 @@ class OrganizationController extends AbstractController
|
|||
}
|
||||
|
||||
$organization->setIsActive(false);
|
||||
$user = $this->getUser() ?? throw $this->createNotFoundException(self::NOT_FOUND);
|
||||
$user = $this->entityManager->getRepository(User::class)->findOneBy(['email' => $user->getUserIdentifier()]);
|
||||
$this->actionService->createAction("Création d'une organisation",$user, $organization, "{$user->getUserIdentifier()} a désactivé l'organisation {$organization->getName()}");
|
||||
$this->entityManager->persist($organization);
|
||||
$this->entityManager->flush();
|
||||
$this->addFlash('success', 'Organization deactivated successfully');
|
||||
|
|
@ -215,6 +224,9 @@ class OrganizationController extends AbstractController
|
|||
|
||||
$organization->setIsActive(true);
|
||||
$this->entityManager->persist($organization);
|
||||
$user = $this->getUser() ?? throw $this->createNotFoundException(self::NOT_FOUND);
|
||||
$user = $this->entityManager->getRepository(User::class)->findOneBy(['email' => $user->getUserIdentifier()]);
|
||||
$this->actionService->createAction("Création d'une organisation",$user, $organization, "{$user->getUserIdentifier()} a activé l'organisation {$organization->getName()}");
|
||||
$this->entityManager->flush();
|
||||
$this->addFlash('success', 'Organization activated successfully');
|
||||
return $this->redirectToRoute('organization_index');
|
||||
|
|
|
|||
Loading…
Reference in New Issue