Add user to organization
This commit is contained in:
parent
6efbeb0fa2
commit
1053a2ab22
|
|
@ -4,6 +4,7 @@ namespace App\Controller;
|
||||||
|
|
||||||
use App\Entity\Actions;
|
use App\Entity\Actions;
|
||||||
use App\Entity\Apps;
|
use App\Entity\Apps;
|
||||||
|
use App\Entity\Organizations;
|
||||||
use App\Entity\Roles;
|
use App\Entity\Roles;
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
use App\Form\UserForm;
|
use App\Form\UserForm;
|
||||||
|
|
@ -88,6 +89,7 @@ class UserController extends AbstractController
|
||||||
public function new(Request $request): Response
|
public function new(Request $request): Response
|
||||||
{
|
{
|
||||||
$form = $this->createForm(UserForm::class);
|
$form = $this->createForm(UserForm::class);
|
||||||
|
$organizationId = $request->query->get('organizationId');
|
||||||
|
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
|
|
@ -96,17 +98,38 @@ class UserController extends AbstractController
|
||||||
$data = $form->getData();
|
$data = $form->getData();
|
||||||
// Handle user creation logic here
|
// Handle user creation logic here
|
||||||
|
|
||||||
|
|
||||||
//FOR DEV PURPOSES ONLY
|
//FOR DEV PURPOSES ONLY
|
||||||
$data->setPictureUrl("");
|
$data->setPictureUrl("");
|
||||||
$data->setPassword($this->userService->generateRandomPassword());
|
$data->setPassword($this->userService->generateRandomPassword());
|
||||||
//FOR DEV PURPOSES ONLY
|
//FOR DEV PURPOSES ONLY
|
||||||
|
$orgId = $request->get('organization_id');
|
||||||
|
if ($orgId) {
|
||||||
|
$organization = $this->entityManager->getRepository(Organizations::class)->find($orgId);
|
||||||
|
$roleUser = $this->entityManager->getRepository(Roles::class)->findOneBy(['name' => 'USER']);
|
||||||
|
if (!$organization || !$roleUser) {
|
||||||
|
throw $this->createNotFoundException(self::NOT_FOUND);
|
||||||
|
}
|
||||||
|
$uo = new UsersOrganizations();
|
||||||
|
$uo->setOrganization($organization);
|
||||||
|
$uo->setRole($roleUser);
|
||||||
|
$uo->setUsers($data);
|
||||||
|
|
||||||
|
//log the action
|
||||||
|
$action = new Actions();
|
||||||
|
$action->setActionType('Création utilisateur dans une organisation');
|
||||||
|
$action->setUsers($this->getUser());
|
||||||
|
$action->setOrganization($organization);
|
||||||
|
$this->entityManager->persist($uo);
|
||||||
|
}else{
|
||||||
|
$action = new Actions();
|
||||||
|
$action->setActionType('Création utilisateur');
|
||||||
|
$action->setUsers($this->getUser());
|
||||||
|
}
|
||||||
$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->persist($action);
|
||||||
|
|
||||||
|
|
||||||
$this->entityManager->flush();
|
$this->entityManager->flush();
|
||||||
|
|
||||||
// Redirect to user index
|
// Redirect to user index
|
||||||
|
|
@ -115,6 +138,7 @@ class UserController extends AbstractController
|
||||||
|
|
||||||
return $this->render('user/new.html.twig', [
|
return $this->render('user/new.html.twig', [
|
||||||
'form' => $form->createView(),
|
'form' => $form->createView(),
|
||||||
|
'organizationId' => $organizationId,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,8 @@
|
||||||
{% include 'user/userListSmall.html.twig' with {
|
{% include 'user/userListSmall.html.twig' with {
|
||||||
title: 'Nouveaux utilisateurs',
|
title: 'Nouveaux utilisateurs',
|
||||||
users: newUsers,
|
users: newUsers,
|
||||||
empty_message: 'Aucun nouvel utilisateur trouvé.'
|
empty_message: 'Aucun nouvel utilisateur trouvé.',
|
||||||
|
organizationId: organization.id
|
||||||
} %}
|
} %}
|
||||||
</div>
|
</div>
|
||||||
<div class="col mb-3 mb-sm-0">
|
<div class="col mb-3 mb-sm-0">
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,11 @@
|
||||||
<form method="post" action="{{ path('user_new') }}" enctype="multipart/form-data">
|
<form method="post" action="{{ path('user_new') }}" enctype="multipart/form-data">
|
||||||
{{ form_start(form) }}
|
{{ form_start(form) }}
|
||||||
{{ form_widget(form) }}
|
{{ form_widget(form) }}
|
||||||
|
{% if organizationId is defined %}
|
||||||
|
<div class="form-group">
|
||||||
|
<input hidden type="text" value="{{ organizationId }}" name="organization_id">
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
<button type="submit" class="btn btn-primary">Enregistrer</button>
|
<button type="submit" class="btn btn-primary">Enregistrer</button>
|
||||||
{{ form_end(form) }}
|
{{ form_end(form) }}
|
||||||
</form>
|
</form>
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,9 @@
|
||||||
<div class="card border-0">
|
<div class="card border-0">
|
||||||
<div class="card-title p-3 d-flex justify-content-between align-items-center ">
|
<div class="card-title p-3 d-flex justify-content-between align-items-center ">
|
||||||
<h3>{{ title }}</h3>
|
<h3>{{ title }}</h3>
|
||||||
|
{% if organizationId is defined %}
|
||||||
|
<a href="{{ path('user_new', {'organizationId': organizationId}) }}" class="btn btn-primary">Ajouter un utilisateur</a>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<table class="table align-middle table-borderless">
|
<table class="table align-middle table-borderless">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue