feat: list administrative users for admins
This commit is contained in:
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller\Admin\System\User;
|
||||||
|
|
||||||
|
use App\Repository\UserRepository;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||||
|
|
||||||
|
class IndexController extends AbstractController
|
||||||
|
{
|
||||||
|
public function __construct(private readonly UserRepository $userRepository)
|
||||||
|
{}
|
||||||
|
|
||||||
|
#[Route('/admin/system/user', name: 'app_admin_system_user_index')]
|
||||||
|
#[IsGranted('ROLE_ADMIN')]
|
||||||
|
public function index(): Response
|
||||||
|
{
|
||||||
|
$users = $this->userRepository->getAdministrativeUsers();
|
||||||
|
|
||||||
|
return $this->render('admin/system/user/index.html.twig', [
|
||||||
|
'users' => $users,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -147,9 +147,30 @@ class User implements UserInterface, TimestampableEntityInterface
|
|||||||
{
|
{
|
||||||
$roles = ['ROLE_USER', ...$this->roles];
|
$roles = ['ROLE_USER', ...$this->roles];
|
||||||
|
|
||||||
|
if (true === $this->isSuperAdmin()) {
|
||||||
|
$roles[] = 'ROLE_SUPER_ADMIN';
|
||||||
|
}
|
||||||
|
|
||||||
return array_unique($roles);
|
return array_unique($roles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getRolesLabels(): array
|
||||||
|
{
|
||||||
|
$labels = [];
|
||||||
|
|
||||||
|
foreach ($this->roles as $role) {
|
||||||
|
$labels[] = match($role) {
|
||||||
|
'ROLE_ADMIN' => 'Admin',
|
||||||
|
'ROLE_MANAGER' => 'Reisemanager',
|
||||||
|
'ROLE_HOUSE_MANAGER' => 'Hausleitung',
|
||||||
|
'ROLE_TEAMER' => 'Teamer',
|
||||||
|
default => $role,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return $labels;
|
||||||
|
}
|
||||||
|
|
||||||
public function setRoles(array $roles): static
|
public function setRoles(array $roles): static
|
||||||
{
|
{
|
||||||
$this->roles = $roles;
|
$this->roles = $roles;
|
||||||
|
|||||||
@@ -170,6 +170,12 @@ class AdminMenuBuilder extends AbstractMenuBuilder
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
$settingsMenu->addChild('Administrative Benutzer', [
|
||||||
|
'route' => 'app_admin_system_user_index',
|
||||||
|
'linkAttributes' => [
|
||||||
|
'title' => 'Administrative Benutzer',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
$menu->addChild('Logs', [
|
$menu->addChild('Logs', [
|
||||||
'route' => 'app_admin_log_index',
|
'route' => 'app_admin_log_index',
|
||||||
|
|||||||
@@ -21,6 +21,27 @@ class UserRepository extends ServiceEntityRepository
|
|||||||
parent::__construct($registry, User::class);
|
parent::__construct($registry, User::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getAdministrativeUsers(): array
|
||||||
|
{
|
||||||
|
$qb = $this->createQueryBuilder('u');
|
||||||
|
|
||||||
|
return $qb
|
||||||
|
->where($qb->expr()->orX(
|
||||||
|
$qb->expr()->like('u.roles', ':role_admin'),
|
||||||
|
$qb->expr()->like('u.roles', ':role_manager'),
|
||||||
|
$qb->expr()->like('u.roles', ':role_house_manager')
|
||||||
|
))
|
||||||
|
->orderBy('u.lastName', 'ASC')
|
||||||
|
->setParameters([
|
||||||
|
'role_admin' => '%"ROLE_ADMIN"%',
|
||||||
|
'role_manager' => '%"ROLE_MANAGER"%',
|
||||||
|
'role_house_manager' => '%"ROLE_HOUSE_MANAGER"%',
|
||||||
|
])
|
||||||
|
->getQuery()
|
||||||
|
->getResult()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
public function getUsersByRoleAndHotelCode(string $role, string $hotelCode): array
|
public function getUsersByRoleAndHotelCode(string $role, string $hotelCode): array
|
||||||
{
|
{
|
||||||
$hotelCodeBase = substr($hotelCode, 0, 3);
|
$hotelCodeBase = substr($hotelCode, 0, 3);
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
{% extends 'admin/layout.html.twig' %}
|
||||||
|
|
||||||
|
{% block title %}Administrative Benutzer{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h1 class="text-2xl font-bold pb-8">
|
||||||
|
Administrative Benutzer
|
||||||
|
</h1>
|
||||||
|
<div class="data-table-wrapper">
|
||||||
|
<div class="data-table-wrapper__inner">
|
||||||
|
<table class="data-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
Name
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Vorname
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
E-Mail
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Rolle(n)
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Superadmin
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Letzter Login
|
||||||
|
</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for user in users %}
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
{{ user.lastName }}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{ user.firstName }}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{ user.email }}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{ user.rolesLabels|join(', ') }}
|
||||||
|
</td>
|
||||||
|
<td class="text-center">
|
||||||
|
{% if user.superAdmin %}
|
||||||
|
{{ icon('check', 'w-4 h-4 inline-block') }}
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{ user.lastLoginAt ? user.lastLoginAt|date('d.m.Y, H:i') : '-' }}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{% if is_granted('CAN_IMPERSONATE', user) %}
|
||||||
|
<a href="{{ path('app_index', { '_switch_user': user.email }) }}">
|
||||||
|
{{ icon('mask', 'w-4 h-4') }}
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% else %}
|
||||||
|
<tr>
|
||||||
|
<td colspan="6">
|
||||||
|
Keine Daten...
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user