add user to organization

This commit is contained in:
Charles 2025-09-03 15:51:51 +02:00
parent 889010b5ad
commit eaff14acc6
2 changed files with 9 additions and 7 deletions

View File

@ -154,11 +154,11 @@ class UserController extends AbstractController
$user = new User(); $user = new User();
$form = $this->createForm(UserForm::class, $user); $form = $this->createForm(UserForm::class, $user);
$form->handleRequest($request); $form->handleRequest($request);
$orgId = $request->get('organizationId');
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$orgId = $request->query->get('organizationId');
// Handle file upload // Handle file upload
$picture = $form->get('pictureUrl')->getData(); $picture = $form->get('pictureUrl')->getData();
if ($picture) { if ($picture) {
@ -166,6 +166,8 @@ class UserController extends AbstractController
}else{ }else{
$user->setPictureUrl(""); $user->setPictureUrl("");
} }
//FOR TEST PURPOSES, SETTING A DEFAULT RANDOM PASSWORD
$user->setPassword($this->userService->generateRandomPassword());
if ($orgId) { if ($orgId) {
$org = $this->entityManager->getRepository(Organizations::class)->find($orgId); $org = $this->entityManager->getRepository(Organizations::class)->find($orgId);
if ($org) { if ($org) {
@ -173,13 +175,12 @@ class UserController extends AbstractController
$uo->setUsers($user); $uo->setUsers($user);
$uo->setOrganization($org); $uo->setOrganization($org);
$this->entityManager->persist($uo); $this->entityManager->persist($uo);
$this->actionService->createAction("Create new user", $user, $orgId, $user->getUserIdentifier()." for organization ".$org->getName()); $this->actionService->createAction("Create new user", $user, $org, "Added user to organization". $user->getUserIdentifier()." for organization ".$org->getName());
} }
} }
$this->actionService->createAction("Create new user", $actingUser, null, $user->getUserIdentifier()); $this->actionService->createAction("Create new user", $actingUser, null, $user->getUserIdentifier());
//FOR TEST PURPOSES, SETTING A DEFAULT RANDOM PASSWORD
$user->setPassword($this->userService->generateRandomPassword());
$this->entityManager->persist($user); $this->entityManager->persist($user);
$this->entityManager->flush(); $this->entityManager->flush();
@ -189,6 +190,7 @@ class UserController extends AbstractController
return $this->render('user/new.html.twig', [ return $this->render('user/new.html.twig', [
'user' => $user, 'user' => $user,
'form' => $form->createView(), 'form' => $form->createView(),
'organizationId' => $orgId
]); ]);
} }
throw $this->createAccessDeniedException(self::ACCESS_DENIED); throw $this->createAccessDeniedException(self::ACCESS_DENIED);

View File

@ -14,7 +14,7 @@
{{ form_widget(form) }} {{ form_widget(form) }}
{% if organizationId is defined %} {% if organizationId is defined %}
<div class="form-group"> <div class="form-group">
<input hidden type="text" value="{{ organizationId }}" name="organization_id"> <input hidden type="text" value="{{ organizationId }}" name="organizationId">
</div> </div>
{% endif %} {% endif %}
<button type="submit" class="btn btn-primary">Enregistrer</button> <button type="submit" class="btn btn-primary">Enregistrer</button>