diff --git a/assets/controllers/user_controller.js b/assets/controllers/user_controller.js
index 82c802a..9a8a7bc 100644
--- a/assets/controllers/user_controller.js
+++ b/assets/controllers/user_controller.js
@@ -628,9 +628,12 @@ export default class extends Controller {
title: "Statut", field: "statut", vertAlign: "middle",
formatter: (cell) => {
const statut = cell.getValue();
- if (statut) {
+ console.log("Statut value:", statut);
+ if (statut === "INVITED") {
+ return `Invité`
+ } else if (statut === "ACTIVE") {
return `Actif`
- } else {
+ }else{
return `Inactif`
}
}
diff --git a/migrations/Version20251028154635.php b/migrations/Version20251028154635.php
new file mode 100644
index 0000000..261fbff
--- /dev/null
+++ b/migrations/Version20251028154635.php
@@ -0,0 +1,32 @@
+addSql('ALTER TABLE users_organizations ADD statut 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 users_organizations DROP statut');
+ }
+}
diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php
index 32ec0b7..6f64b7d 100644
--- a/src/Controller/UserController.php
+++ b/src/Controller/UserController.php
@@ -41,7 +41,7 @@ class UserController extends AbstractController
{
}
-
+//TODO : REMOVE DEAD CODE due to the use of tabulator in the frontend
#[Route('/view/{id}', name: 'show', methods: ['GET'])]
public function view(int $id, Request $request): Response
{
@@ -145,9 +145,7 @@ class UserController extends AbstractController
if ($picture) {
$this->userService->handleProfilePicture($user, $picture);
}
-// else {
-// $user->setPictureUrl("");
-// }
+
//FOR TEST PURPOSES, SETTING A DEFAULT RANDOM PASSWORD
$user->setPassword($this->userService->generateRandomPassword());
if ($orgId) {
@@ -156,8 +154,11 @@ class UserController extends AbstractController
$uo = new UsersOrganizations();
$uo->setUsers($user);
$uo->setOrganization($org);
+ $uo->setStatut("INVITED");
+ $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]);
}
}
@@ -427,7 +428,7 @@ class UserController extends AbstractController
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier());
if ($this->userService->hasAccessTo($actingUser, true) && $this->isGranted("ROLE_ADMIN")) {
$totalUsers = $this->userRepository->count(['isDeleted' => false, 'isActive' => true]);
- return $this->render('user/indexTest.html.twig', [
+ return $this->render('user/index.html.twig', [
'users' => $totalUsers
]);
}
@@ -444,7 +445,8 @@ class UserController extends AbstractController
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier());
if ($this->userService->hasAccessTo($actingUser, true) && $this->isGranted("ROLE_ADMIN")) {
$orgId = $request->query->get('orgId');
- $uos = $this->uoRepository->findBy(['organization' => $orgId, 'isActive' =>true], limit: 5, orderBy: ['createdAt' => 'DESC']);
+ $uos = $this->uoRepository->findBy(['organization' => $orgId, 'statut' => ["ACCEPTED", "INVITED"]],
+ orderBy: ['createdAt' => 'DESC'], limit: 5);
// Map to array (keep isConnected)
@@ -543,22 +545,7 @@ class UserController extends AbstractController
$rows = $qb->setFirstResult($offset)->setMaxResults($size)->getQuery()->getResult();
// Map to array
- $data = array_map(function (UsersOrganizations $uo) {
- $user = $uo->getUsers();
- return [
- 'pictureUrl' => $user->getPictureUrl(),
- 'name' => $user->getSurname(),
- 'prenom' => $user->getName(),
- 'email' => $user->getEmail(),
- 'isConnected' => $this->userService->isUserConnected($user->getUserIdentifier()),
- 'statut' => $uo->isActive(),
- 'showUrl' => $this->generateUrl('user_show', [
- 'id' => $user->getId(),
- 'organizationId' => $uo->getOrganization()->getId(),
- ]),
- 'id' => $user->getId(),
- ];
- }, $rows);
+ $data = $this->userService->formatStatutForOrganizations($rows);
// Return Tabulator-compatible response
$lastPage = (int)ceil($total / $size);
diff --git a/src/Entity/UsersOrganizations.php b/src/Entity/UsersOrganizations.php
index 722a189..b1a9d8a 100644
--- a/src/Entity/UsersOrganizations.php
+++ b/src/Entity/UsersOrganizations.php
@@ -35,6 +35,9 @@ class UsersOrganizations
#[ORM\OneToMany(targetEntity: UserOrganizatonApp::class, mappedBy: 'userOrganization')]
private Collection $userOrganizatonApps;
+ #[ORM\Column(length: 255, nullable: true)]
+ private ?string $statut = null;
+
public function __construct()
{
$this->isActive = true; // Default value for isActive
@@ -117,4 +120,16 @@ class UsersOrganizations
return $this;
}
+
+ public function getStatut(): ?string
+ {
+ return $this->statut;
+ }
+
+ public function setStatut(?string $statut): static
+ {
+ $this->statut = $statut;
+
+ return $this;
+ }
}
diff --git a/src/Service/UserService.php b/src/Service/UserService.php
index bd1e512..8eaed71 100644
--- a/src/Service/UserService.php
+++ b/src/Service/UserService.php
@@ -379,4 +379,27 @@ class UserService
$token->revoke();
}
}
+
+ public function formatStatutForOrganizations(array $rows): array
+ {
+ $formatted = array_map(function (UsersOrganizations $uo) {
+ $user = $uo->getUsers();
+ if ($uo->getStatut() == "INVITED") {
+ $statut = "INVITED";
+ } else {
+ $statut = $uo->isActive() ? "ACTIVE" : "INACTIVE";
+ }
+ return [
+ 'pictureUrl' => $user->getPictureUrl(),
+ 'name' => $user->getSurname(),
+ 'prenom' => $user->getName(),
+ 'email' => $user->getEmail(),
+ 'isConnected' => $this->isUserConnected($user->getUserIdentifier()),
+ 'statut' => $statut,
+ 'showUrl' => '/user/view/' . $user->getId() . '?organizationId=' . $uo->getOrganization()->getId(),
+ 'id' => $user->getId(),
+ ];
+ }, $rows);
+ return $formatted;
+ }
}