set action log on user entity
This commit is contained in:
parent
e6c8d5a462
commit
cbdb47fb17
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20250804101742 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('ALTER TABLE actions ADD description VARCHAR(255) DEFAULT NULL');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this down() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('CREATE SCHEMA public');
|
||||||
|
$this->addSql('ALTER TABLE actions DROP description');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Entity\Actions;
|
||||||
use App\Entity\Apps;
|
use App\Entity\Apps;
|
||||||
use App\Entity\Roles;
|
use App\Entity\Roles;
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
|
|
@ -101,6 +102,11 @@ class UserController extends AbstractController
|
||||||
//FOR DEV PURPOSES ONLY
|
//FOR DEV PURPOSES ONLY
|
||||||
|
|
||||||
$this->entityManager->persist($data);
|
$this->entityManager->persist($data);
|
||||||
|
|
||||||
|
$action = new Actions();
|
||||||
|
$action->setActionType('Création utilisateur');
|
||||||
|
$action->setUsers($this->getUser());
|
||||||
|
$this->entityManager->persist($action);
|
||||||
$this->entityManager->flush();
|
$this->entityManager->flush();
|
||||||
|
|
||||||
// Redirect to user index
|
// Redirect to user index
|
||||||
|
|
@ -137,6 +143,11 @@ class UserController extends AbstractController
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
//Persist changes to the user entity
|
//Persist changes to the user entity
|
||||||
$entityManager->persist($user);
|
$entityManager->persist($user);
|
||||||
|
//Log the action
|
||||||
|
$action = new Actions();
|
||||||
|
$action->setActionType('Modification utilisateur');
|
||||||
|
$action->setUsers($this->getUser());
|
||||||
|
$entityManager->persist($action);
|
||||||
$entityManager->flush();
|
$entityManager->flush();
|
||||||
|
|
||||||
//Redirect to user profile after successful edit
|
//Redirect to user profile after successful edit
|
||||||
|
|
@ -171,6 +182,11 @@ class UserController extends AbstractController
|
||||||
// Handle user deletion logic
|
// Handle user deletion logic
|
||||||
$user->setIsDeleted(true);
|
$user->setIsDeleted(true);
|
||||||
$entityManager->persist($user);
|
$entityManager->persist($user);
|
||||||
|
// Log the action
|
||||||
|
$action = new Actions();
|
||||||
|
$action->setActionType('Suppression utilisateur');
|
||||||
|
$action->setUsers($this->getUser());
|
||||||
|
$entityManager->persist($action);
|
||||||
$entityManager->flush();
|
$entityManager->flush();
|
||||||
|
|
||||||
return $this->redirectToRoute('user_index');
|
return $this->redirectToRoute('user_index');
|
||||||
|
|
@ -193,6 +209,11 @@ class UserController extends AbstractController
|
||||||
|
|
||||||
// Handle user deletion logic
|
// Handle user deletion logic
|
||||||
$entityManager->remove($user);
|
$entityManager->remove($user);
|
||||||
|
// Log the action
|
||||||
|
$action = new Actions();
|
||||||
|
$action->setActionType('Suppression définitive utilisateur');
|
||||||
|
$action->setUsers($this->getUser());
|
||||||
|
$entityManager->persist($action);
|
||||||
$entityManager->flush();
|
$entityManager->flush();
|
||||||
|
|
||||||
return $this->redirectToRoute('user_index');
|
return $this->redirectToRoute('user_index');
|
||||||
|
|
@ -215,6 +236,11 @@ class UserController extends AbstractController
|
||||||
}
|
}
|
||||||
$user->setIsActive(false);
|
$user->setIsActive(false);
|
||||||
$entityManager->persist($user);
|
$entityManager->persist($user);
|
||||||
|
// Log the action
|
||||||
|
$action = new Actions();
|
||||||
|
$action->setActionType('Désactivation utilisateur');
|
||||||
|
$action->setUsers($this->getUser());
|
||||||
|
$entityManager->persist($action);
|
||||||
$entityManager->flush();
|
$entityManager->flush();
|
||||||
return $this->redirectToRoute('user_index');
|
return $this->redirectToRoute('user_index');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,14 @@ class Actions
|
||||||
#[ORM\ManyToOne(inversedBy: 'actions')]
|
#[ORM\ManyToOne(inversedBy: 'actions')]
|
||||||
private ?Organizations $Organization = null;
|
private ?Organizations $Organization = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 255, nullable: true)]
|
||||||
|
private ?string $description = null;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->date = new \DateTimeImmutable();
|
||||||
|
}
|
||||||
|
|
||||||
public function getId(): ?int
|
public function getId(): ?int
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
|
|
@ -77,4 +85,16 @@ class Actions
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDescription(): ?string
|
||||||
|
{
|
||||||
|
return $this->description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDescription(?string $description): static
|
||||||
|
{
|
||||||
|
$this->description = $description;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Service;
|
namespace App\Service;
|
||||||
|
|
||||||
|
use App\Entity\Actions;
|
||||||
use App\Entity\Apps;
|
use App\Entity\Apps;
|
||||||
use App\Entity\Organizations;
|
use App\Entity\Organizations;
|
||||||
use App\Entity\Roles;
|
use App\Entity\Roles;
|
||||||
|
|
@ -333,6 +334,12 @@ readonly class UserOrganizationService
|
||||||
]);
|
]);
|
||||||
foreach ($userOrganizations as $uo) {
|
foreach ($userOrganizations as $uo) {
|
||||||
$uo->setIsActive(false);
|
$uo->setIsActive(false);
|
||||||
|
//Log action
|
||||||
|
$action = new Actions();
|
||||||
|
$action->setActionType("Désactivation role" );
|
||||||
|
$action->setDescription("Désactivation du rôle " . $uo->getRole()->getName() . " pour l'utilisateur " . $user->getUserIdentifier() . " dans l'organisation " . $organization->getName());
|
||||||
|
$action->setOrganization($organization);
|
||||||
|
$action->setUsers($user);
|
||||||
$this->entityManager->persist($uo);
|
$this->entityManager->persist($uo);
|
||||||
}
|
}
|
||||||
$this->entityManager->flush();
|
$this->entityManager->flush();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue