Skip to content

Commit

Permalink
Admin : améliorer la liste des utilisateurs admin (#905)
Browse files Browse the repository at this point in the history
* Admin user list: improve delete. Indicate if user is withdrawn.

* Add lastLogin column

* Make page visible to admin. Improve user name display
  • Loading branch information
raphodn authored Jul 4, 2023
1 parent 24ff993 commit e15ce74
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 42 deletions.
6 changes: 3 additions & 3 deletions app/Resources/views/admin/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@
<a href="{{ path("roles_list") }}" class="waves-effect waves-light btn deep-purple">
<i class="material-icons left">list</i>Liste des roles
</a>
<a href="{{ path("admin_users_list") }}" class="waves-effect waves-light btn deep-purple">
<i class="material-icons left">list</i>Liste des utilisateurs admin
</a>
{% endif %}

{% if is_granted("ROLE_SUPER_ADMIN") %}
Expand All @@ -162,9 +165,6 @@
<a href="{{ path("user_install_admin") }}" class="waves-effect waves-light btn deep-purple">
<i class="material-icons left">add</i>Ajouter un admin
</a>
<a href="{{ path("admins_list") }}" class="waves-effect waves-light btn deep-purple">
<i class="material-icons left">list</i>Liste des utilisateurs admin
</a>

<h6>Divers</h6>
<a href="{{ path("client_list") }}" class="waves-effect waves-light btn">
Expand Down
73 changes: 41 additions & 32 deletions app/Resources/views/admin/user/admin_list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,51 @@

<table class="striped">
<thead>
<tr>
<th data-col="m.member_number">#</th>
<th data-col="m.username">Username</th>
<th data-col="m.email">Email</th>
<th>Actions</th>
</tr>
<tr>
<th>Etat</th>
<th>Utilisateur</th>
<th>Email</th>
<th>Dernière connexion</th>
{% if is_granted("ROLE_SUPER_ADMIN") %}
<th>Actions</th>
{% endif %}
</tr>
</thead>
<tbody>
{% for admin in admins %}
<tr>
<td>
{% if admin.beneficiary %}
<a href="{{ path('member_show', { 'member_number': admin.beneficiary.membership.memberNumber }) }}">
{{ admin.beneficiary.membership.memberNumber }}
</a>
{% endif %}
</td>
<td>{{ admin.username }}</td>
<td>{{ admin.email }}</td>
<td>
{{ form_start(delete_forms[admin.id]) }}
{{ form_widget(delete_forms[admin.id]) }}
{% if admin.beneficiary %}
<a href="{{ path('user_remove_role', { 'id': admin.id, 'role': 'ROLE_ADMIN' }) }}" class="orange btn-floating small" title="Enlever le rôle">
<i class="material-icons left">arrow_downward</i>
</a>

{% for admin in admins %}
<tr>
<td>
{% if admin.beneficiary and admin.beneficiary.membership.withdrawn %}
<i class="material-icons" title="Compte fermé">{{ member_withdrawn_material_icon }}</i>
{% endif %}
</td>
<td>
{% include "admin/member/_partial/member_or_user_link.html.twig" with { user: admin, target_blank: true } %}
</td>
<td>{{ admin.email }}</td>
{% if admin.lastLogin %}
<td title="{{ admin.lastLogin | date_fr_full_with_time }}">{{ admin.lastLogin | date_short }}</td>
{% else %}
<button type="submit" class="btn-floating waves-effect waves-light red" title="⚠️ Supprimer l'utilisateur ⚠️">
<i class="material-icons left">close</i>
</button>
<td></td>
{% endif %}
{{ form_end(delete_forms[admin.id]) }}
</td>
</tr>
{% endfor %}
{% if is_granted("ROLE_SUPER_ADMIN") %}
<td>
{{ form_start(delete_forms[admin.id]) }}
{{ form_widget(delete_forms[admin.id]) }}
{% if admin.beneficiary %}
<a href="{{ path('user_remove_role', { 'id': admin.id, 'role': 'ROLE_ADMIN' }) }}" class="orange btn-floating small" title="Enlever le rôle">
<i class="material-icons left">arrow_downward</i>
</a>
{% else %}
<a href="#" class="btn-floating waves-effect waves-light red" onclick="var r = confirm('Etes-vous sûr de vouloir supprimer cet utilisateur ?!'); if (r == true) {$(this).closest('form').submit();}; event.stopPropagation();" title="⚠️ Supprimer l'utilisateur ⚠️">
<i class="material-icons left">delete</i>
</a>
{% endif %}
{{ form_end(delete_forms[admin.id]) }}
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
Expand Down
7 changes: 3 additions & 4 deletions src/AppBundle/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,12 @@ public function usersAction(Request $request, SearchUserFormHelper $formHelper)
/**
* Lists all users with ROLE_ADMIN.
*
* @param Request $request , SearchUserFormHelper $formHelper
* @param SearchUserFormHelper $formHelper
* @param Request $request
* @return Response
* @Route("/admin_users", name="admins_list", methods={"GET","POST"})
* @Route("/admin_users", name="admin_users_list", methods={"GET"})
* @Security("has_role('ROLE_ADMIN')")
*/
public function adminUsersAction(Request $request, SearchUserFormHelper $formHelper)
public function adminUsersAction(Request $request)
{
$em = $this->getDoctrine()->getManager();

Expand Down
7 changes: 4 additions & 3 deletions src/AppBundle/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,20 +305,21 @@ public function removeClientUserAction(User $user, $client_id)
/**
* Deletes a user entity
*
* @Route("/delete/{id}", name="user_delete", methods={"DELETE"})
* @Route("/{id}/delete", name="user_delete", methods={"DELETE"})
* @Security("has_role('ROLE_SUPER_ADMIN')")
* @param Request $request
* @param User $user
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function deleteAction(Request $request, User $user)
{
$session = new Session();
$em = $this->getDoctrine()->getManager();

$form = $this->createDeleteForm($user);
$form->handleRequest($request);

$session = new Session();
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->remove($user);
$em->flush();

Expand Down
8 changes: 8 additions & 0 deletions src/AppBundle/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,4 +356,12 @@ public function getProcessUpdates()
{
return $this->processUpdates;
}

/**
* @return DateTime
*/
public function getLastLogin()
{
return $this->lastLogin;
}
}

0 comments on commit e15ce74

Please sign in to comment.