From 3ca5eea8776f3d5700c2f85d95c5c1e047f3e32a Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 4 Sep 2025 09:11:37 +0200 Subject: [PATCH] Log action --- src/Controller/UserController.php | 22 +++++++++++++++------- templates/user/edit.html.twig | 1 + templates/user/userInformation.html.twig | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index fffcead..7853ef0 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -132,14 +132,22 @@ class UserController extends AbstractController $user->setModifiedAt(new \DateTimeImmutable('now')); $this->entityManager->persist($user); $this->entityManager->flush(); - $this->actionService->createAction("Edit user information", $actingUser, null, $user->getUserIdentifier()); + if ($request->get('organizationId')) { + $org = $this->entityManager->getRepository(Organizations::class)->find($request->get('organizationId')); + if ($org) { + $this->actionService->createAction("Edit user information", $actingUser, $org, $user->getUserIdentifier()); + } + } else { + $this->actionService->createAction("Edit user information", $actingUser, null, $user->getUserIdentifier()); + } - return $this->redirectToRoute('user_show', ['id' => $user->getId()]); + return $this->redirectToRoute('user_show', ['id' => $user->getId(), 'organizationId' => $request->get('organizationId')]); } return $this->render('user/edit.html.twig', [ 'user' => $user, 'form' => $form->createView(), + 'organizationId' => $request->get('organizationId') ]); } throw $this->createAccessDeniedException(self::ACCESS_DENIED); @@ -158,12 +166,12 @@ class UserController extends AbstractController if ($form->isSubmitted() && $form->isValid()) { - // Handle file upload + // Handle file upload $picture = $form->get('pictureUrl')->getData(); if ($picture) { $this->userService->handleProfilePicture($user, $picture); - }else{ + } else { $user->setPictureUrl(""); } //FOR TEST PURPOSES, SETTING A DEFAULT RANDOM PASSWORD @@ -175,7 +183,7 @@ class UserController extends AbstractController $uo->setUsers($user); $uo->setOrganization($org); $this->entityManager->persist($uo); - $this->actionService->createAction("Create new user", $user, $org, "Added user to organization". $user->getUserIdentifier()." for organization ".$org->getName()); + $this->actionService->createAction("Create new user", $user, $org, "Added user to organization" . $user->getUserIdentifier() . " for organization " . $org->getName()); } } @@ -266,7 +274,7 @@ class UserController extends AbstractController $this->userOrganizationAppService->deactivateAllUserOrganizationsAppLinks($uo); $this->entityManager->persist($uo); $this->entityManager->flush(); - $this->actionService->createAction("Deactivate user in organization", $actingUser, $org, $org->getName()." for user ".$user->getUserIdentifier()); + $this->actionService->createAction("Deactivate user in organization", $actingUser, $org, $org->getName() . " for user " . $user->getUserIdentifier()); return $this->redirectToRoute('user_index'); } @@ -298,7 +306,7 @@ class UserController extends AbstractController $uo->setIsActive(true); $this->entityManager->persist($uo); $this->entityManager->flush(); - $this->actionService->createAction("Activate user in organization", $actingUser, $org, $org->getName()." for user ".$user->getUserIdentifier()); + $this->actionService->createAction("Activate user in organization", $actingUser, $org, $org->getName() . " for user " . $user->getUserIdentifier()); return $this->redirectToRoute('user_index'); } diff --git a/templates/user/edit.html.twig b/templates/user/edit.html.twig index ac41d80..a747074 100644 --- a/templates/user/edit.html.twig +++ b/templates/user/edit.html.twig @@ -11,6 +11,7 @@ {{ form_start(form, {'action': path('user_edit', {'id': user.id}), 'method': 'PUT'}) }} {{ form_widget(form) }} + {{ form_end(form) }} diff --git a/templates/user/userInformation.html.twig b/templates/user/userInformation.html.twig index f16ae22..f4f5d7b 100644 --- a/templates/user/userInformation.html.twig +++ b/templates/user/userInformation.html.twig @@ -24,7 +24,7 @@ {% endif %} {% endif %} - Modifier + Modifier