diff --git a/migrations/Version20250804101742.php b/migrations/Version20250804101742.php new file mode 100644 index 0000000..005109a --- /dev/null +++ b/migrations/Version20250804101742.php @@ -0,0 +1,32 @@ +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'); + } +} diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 2f8c5b1..0760464 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -2,6 +2,7 @@ namespace App\Controller; +use App\Entity\Actions; use App\Entity\Apps; use App\Entity\Roles; use App\Entity\User; @@ -101,6 +102,11 @@ class UserController extends AbstractController //FOR DEV PURPOSES ONLY $this->entityManager->persist($data); + + $action = new Actions(); + $action->setActionType('Création utilisateur'); + $action->setUsers($this->getUser()); + $this->entityManager->persist($action); $this->entityManager->flush(); // Redirect to user index @@ -137,6 +143,11 @@ class UserController extends AbstractController if ($form->isSubmitted() && $form->isValid()) { //Persist changes to the user entity $entityManager->persist($user); + //Log the action + $action = new Actions(); + $action->setActionType('Modification utilisateur'); + $action->setUsers($this->getUser()); + $entityManager->persist($action); $entityManager->flush(); //Redirect to user profile after successful edit @@ -171,6 +182,11 @@ class UserController extends AbstractController // Handle user deletion logic $user->setIsDeleted(true); $entityManager->persist($user); + // Log the action + $action = new Actions(); + $action->setActionType('Suppression utilisateur'); + $action->setUsers($this->getUser()); + $entityManager->persist($action); $entityManager->flush(); return $this->redirectToRoute('user_index'); @@ -193,6 +209,11 @@ class UserController extends AbstractController // Handle user deletion logic $entityManager->remove($user); + // Log the action + $action = new Actions(); + $action->setActionType('Suppression définitive utilisateur'); + $action->setUsers($this->getUser()); + $entityManager->persist($action); $entityManager->flush(); return $this->redirectToRoute('user_index'); @@ -215,6 +236,11 @@ class UserController extends AbstractController } $user->setIsActive(false); $entityManager->persist($user); + // Log the action + $action = new Actions(); + $action->setActionType('Désactivation utilisateur'); + $action->setUsers($this->getUser()); + $entityManager->persist($action); $entityManager->flush(); return $this->redirectToRoute('user_index'); } diff --git a/src/Entity/Actions.php b/src/Entity/Actions.php index aa39be4..ded2ae6 100644 --- a/src/Entity/Actions.php +++ b/src/Entity/Actions.php @@ -25,6 +25,14 @@ class Actions #[ORM\ManyToOne(inversedBy: 'actions')] 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 { return $this->id; @@ -77,4 +85,16 @@ class Actions return $this; } + + public function getDescription(): ?string + { + return $this->description; + } + + public function setDescription(?string $description): static + { + $this->description = $description; + + return $this; + } } diff --git a/src/Service/UserOrganizationService.php b/src/Service/UserOrganizationService.php index ec96780..df97724 100644 --- a/src/Service/UserOrganizationService.php +++ b/src/Service/UserOrganizationService.php @@ -2,6 +2,7 @@ namespace App\Service; +use App\Entity\Actions; use App\Entity\Apps; use App\Entity\Organizations; use App\Entity\Roles; @@ -333,6 +334,12 @@ readonly class UserOrganizationService ]); foreach ($userOrganizations as $uo) { $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->flush();