Display indivodual user informations
This commit is contained in:
parent
26637e497a
commit
71c6f82b77
|
|
@ -4,9 +4,11 @@ namespace App\Controller;
|
|||
|
||||
use App\Entity\Organizations;
|
||||
use App\Entity\User;
|
||||
use App\Entity\UserOrganizatonApp;
|
||||
use App\Entity\UsersOrganizations;
|
||||
use App\Form\UserForm;
|
||||
use App\Service\ActionService;
|
||||
use App\Service\UserOrganizationAppService;
|
||||
use App\Service\UserOrganizationService;
|
||||
use App\Service\UserService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
|
@ -26,7 +28,7 @@ class UserController extends AbstractController
|
|||
private readonly UserOrganizationService $userOrganizationService,
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly UserService $userService,
|
||||
private readonly ActionService $actionService,
|
||||
private readonly ActionService $actionService, private readonly UserOrganizationAppService $userOrganizationAppService,
|
||||
)
|
||||
{
|
||||
}
|
||||
|
|
@ -65,4 +67,43 @@ class UserController extends AbstractController
|
|||
'usersByOrganization' => $usersByOrganization,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/view/{id}', name: 'show', methods: ['GET'])]
|
||||
public function view(int $id, Request $request): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted('ROLE_USER');
|
||||
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier());
|
||||
if($this->userService->hasAccessTo($actingUser)){
|
||||
$user = $this->entityManager->getRepository(User::class)->find($id);
|
||||
try{
|
||||
$orgId = $request->query->get('organizationId');
|
||||
if($orgId){
|
||||
$orgs = $this->entityManager->getRepository(Organizations::class)->findBy(['id' =>$orgId]);
|
||||
$uo = $this->entityManager->getRepository(UsersOrganizations::class)->findBy(['users' => $user, 'organization' => $orgs, 'isActive' => true]);
|
||||
if(!$uo){
|
||||
throw $this->createNotFoundException(self::NOT_FOUND);
|
||||
}
|
||||
}
|
||||
else{
|
||||
$uo = $this->entityManager->getRepository(UsersOrganizations::class)->findBy(['users'=> $user, 'isActive' => true]);
|
||||
foreach ($uo as $u){
|
||||
$orgs[] = $u->getOrganization();
|
||||
}
|
||||
}
|
||||
$uoa = $this->entityManager->getRepository(UserOrganizatonApp::class)->findBy(['userOrganization'=> $uo, 'isActive' => true]);
|
||||
$uoa = $this->userOrganizationAppService->groupUserOrganizationAppsByApplication($uoa);
|
||||
dd($uoa, $orgs["name"]);
|
||||
}catch(\Exception $e){
|
||||
//ignore
|
||||
}
|
||||
}else{
|
||||
throw $this->createAccessDeniedException(self::ACCESS_DENIED);
|
||||
}
|
||||
|
||||
return $this->render('user/show.html.twig', [
|
||||
'user' => $user,
|
||||
'uoas' => $uoa ?? null,
|
||||
'orgs' => $orgs ?? null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Entity\UserOrganizatonApp;
|
||||
|
||||
class UserOrganizationAppService
|
||||
{
|
||||
/**
|
||||
* @param UserOrganizatonApp[] $userOrgApps
|
||||
* @return array
|
||||
*/
|
||||
public function groupUserOrganizationAppsByApplication(array $userOrgApps): array
|
||||
{
|
||||
$grouped = [];
|
||||
|
||||
foreach ($userOrgApps as $uoa) {
|
||||
$app = $uoa->getApplication();
|
||||
$appId = $app->getId();
|
||||
$roleEntity = $uoa->getRole();
|
||||
|
||||
if (!isset($grouped[$appId])) {
|
||||
$grouped[$appId] = [
|
||||
'userOrganization'=> $uoa->getUserOrganization(),
|
||||
'application' => $app,
|
||||
'roles' => [],
|
||||
];
|
||||
}
|
||||
|
||||
$grouped[$appId]['roles'][] = [
|
||||
'id' => $roleEntity->getId(),
|
||||
'name' => $roleEntity->getName(), // adjust to your Role entity fields
|
||||
];
|
||||
}
|
||||
|
||||
// if you want a simple indexed array instead of associative keyed by appId
|
||||
return array_values($grouped);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -69,10 +69,10 @@
|
|||
</div>
|
||||
</a>
|
||||
<div class="dropdown-menu dropdown-menu-right navbar-dropdown px-2" aria-labelledby="profileDropdown" data-bs-popper="static">
|
||||
{# <a class="dropdown-item border-bottom" style="padding-left: 8px;" href="{{ path('user_show', {'id': app.user.id}) }}">#}
|
||||
{# <i class="me-2">{{ ux_icon('bi:gear', {height: '20px', width: '20px'}) }}</i> #}
|
||||
{# Profil#}
|
||||
{# </a>#}
|
||||
<a class="dropdown-item border-bottom" style="padding-left: 8px;" href="{{ path('user_show', {'id': app.user.id}) }}">
|
||||
<i class="me-2">{{ ux_icon('bi:gear', {height: '20px', width: '20px'}) }}</i>
|
||||
Profil
|
||||
</a>
|
||||
<div style="padding:8px 0;" class="row border-bottom">
|
||||
<div class="col-2 m-auto">
|
||||
<i >{{ ux_icon('bi:menu-up', {height: '20px', width: '20px'}) }}</i>
|
||||
|
|
|
|||
|
|
@ -1,34 +1,53 @@
|
|||
{% block body %}
|
||||
{% set roles = uoa.roles %}
|
||||
|
||||
<div class="card mb-4 me-4">
|
||||
<div class="card col-6 mb-4 me-4">
|
||||
<div class="card-header">
|
||||
<div class="d-flex">
|
||||
{% if application.logoUrl %}
|
||||
<img src="{{ asset(application.logoUrl) }}" alt="Logo {{ application.name }}"
|
||||
{% if uoa.application.logoUrl %}
|
||||
<img src="{{ asset(uoa.application.logoUrl) }}" alt="Logo {{ uoa.application.name }}"
|
||||
class="rounded-circle me-2" style="width:40px; height:40px;">
|
||||
{% endif %}
|
||||
<h1 class="mb-0">{{ application.name|title }}</h1>
|
||||
<h1 class="mb-0">{{ uoa.application.name|title }}</h1>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<p>{{ application.description|default('Aucune description disponible.') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
{% if is_granted('ROLE_ADMIN') %}
|
||||
<form method="POST" action="{{ path('user_organization_edit', {'id' : uo.uoId}) }}"
|
||||
data-controller="user"
|
||||
data-user-roles-array-value="{{ rolesArray|json_encode }}"
|
||||
data-user-selected-role-ids-value="{{ selectedRoleIds|json_encode }}">
|
||||
<div class="form-group mb-3">
|
||||
<label for="roles">Roles</label>
|
||||
<select class="choices" data-type="select-multiple" id="roles" name="roles[]" multiple>
|
||||
</select>
|
||||
<p><b> Description : </b>{{ uoa.application.description|default('Aucune description disponible.') }}</p>
|
||||
{% if roles|length is not null %}
|
||||
<div class="col">
|
||||
<p><b>Rôles :</b>
|
||||
|
||||
{% for role in roles %}
|
||||
{% if role.name == "SUPER ADMIN" %}
|
||||
<span class="badge bg-danger">{{ role.name|capitalize }}</span>
|
||||
{% elseif role.name == "ADMIN" %}
|
||||
<span class="badge bg-danger">{{ role.name|capitalize }}</span>
|
||||
{% else %}
|
||||
<span class="badge bg-primary">{{ role.name|capitalize }}</span>
|
||||
{% endif %}
|
||||
{% if not loop.last %} - {% endif %}
|
||||
{% else %}
|
||||
<p>Aucun rôle attribué.</p>
|
||||
{% endfor %}
|
||||
</p>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Sauvegarder</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
</div>
|
||||
{# {% if is_granted('ROLE_ADMIN') %} #}
|
||||
{# <form method="POST" action="{{ path('user_organization_edit', {'id' : uo.uoId}) }}" #}
|
||||
{# data-controller="user" #}
|
||||
{# data-user-roles-array-value="{{ rolesArray|json_encode }}" #}
|
||||
{# data-user-selected-role-ids-value="{{ selectedRoleIds|json_encode }}"> #}
|
||||
{# <div class="form-group mb-3"> #}
|
||||
{# <label for="roles">Roles</label> #}
|
||||
{# <select class="choices" data-type="select-multiple" id="roles" name="roles[]" multiple> #}
|
||||
{# </select> #}
|
||||
{# </div> #}
|
||||
{# <button type="submit" class="btn btn-primary">Sauvegarder</button> #}
|
||||
{# </form> #}
|
||||
{# {% endif %} #}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -6,30 +6,18 @@
|
|||
{% if is_granted("ROLE_ADMIN") %}
|
||||
<div class="col d-flex justify-content-between align-items-center ">
|
||||
<h1 class="mb-4">Gestion Utilisateur</h1>
|
||||
<a href="{{ path('user_deactivate', {'id': user.id}) }}" class="btn btn-danger">Désactiver</a>
|
||||
{# <a href="{{ path('user_deactivate', {'id': user.id}) }}" class="btn btn-danger">Désactiver</a> #}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% include 'user/userInformation.html.twig' %}
|
||||
|
||||
<h1 class="mt-5 mb-4">Organisations</h1>
|
||||
<div class="row">
|
||||
{% if userOrganizations is empty %}
|
||||
<div class="col-md-10 m-auto p-auto">
|
||||
<h3>Aucune organisation associée à cet utilisateur.</h3>
|
||||
</div>
|
||||
{% elseif userOrganizations|length == 1 %}
|
||||
{% for organization in userOrganizations[0].apps %}
|
||||
{{ dump(userOrganizations) }}
|
||||
<h1 class="mt-5 mb-4">Vos applications</h1>
|
||||
<div class="d-flex ">
|
||||
{% for uoa in uoas %}
|
||||
{% include 'user/application/information.html.twig' %}
|
||||
{% endfor %}
|
||||
|
||||
|
||||
{# {% include 'user/application/information.html.twig' #}
|
||||
{# with {'application': application, 'roles' : } %} #}
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
{% for organization in userOrganizations %}
|
||||
{% include 'user/organization/userOrganizationInformation.html.twig'
|
||||
with {'organization': organization.organization, 'roles': organization.roles, 'apps': organization.apps, 'uoId': organization.uoId} %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
<div class="card border-0">
|
||||
<div class="card-title shadow-sm p-3 d-flex justify-content-between align-items-center">
|
||||
<h2>{{ user.surname|capitalize }} {{ user.name|capitalize }}</h2>
|
||||
<a href="{{ path('user_edit', {'id': user.id}) }}" class="btn btn-primary">Modifier</a>
|
||||
{# <a href="{{ path('user_edit', {'id': user.id}) }}" class="btn btn-primary">Modifier</a>#}
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p> <b>Email: </b>{{ user.email }}</p>
|
||||
|
|
|
|||
|
|
@ -69,17 +69,17 @@
|
|||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{# {% if organizationId is defined and organizationId %} #}
|
||||
{# <a href="{{ path('user_show', {'id': user.entity.id, 'organizationId': organizationId}) }}" #}
|
||||
{# class="p-3 align-middle color-primary"> #}
|
||||
{# {{ ux_icon('fa6-regular:eye', {height: '30px', width: '30px'}) }} #}
|
||||
{# </a> #}
|
||||
{# {% else %} #}
|
||||
{# <a href="{{ path('user_show', {'id': user.entity.id}) }}" #}
|
||||
{# class="p-3 align-middle color-primary"> #}
|
||||
{# {{ ux_icon('fa6-regular:eye', {height: '30px', width: '30px'}) }} #}
|
||||
{# </a> #}
|
||||
{# {% endif %} #}
|
||||
{% if organizationId is defined and organizationId %}
|
||||
<a href="{{ path('user_show', {'id': user.entity.id, 'organizationId': organizationId}) }}"
|
||||
class="p-3 align-middle color-primary">
|
||||
{{ ux_icon('fa6-regular:eye', {height: '30px', width: '30px'}) }}
|
||||
</a>
|
||||
{% else %}
|
||||
<a href="{{ path('user_show', {'id': user.entity.id}) }}"
|
||||
class="p-3 align-middle color-primary">
|
||||
{{ ux_icon('fa6-regular:eye', {height: '30px', width: '30px'}) }}
|
||||
</a>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
|
|
|||
Loading…
Reference in New Issue