Ce serveur Gitlab sera éteint le 30 juin 2020, pensez à migrer vos projets vers les serveurs gitlab-research.centralesupelec.fr et gitlab-student.centralesupelec.fr !

Commit 19f1e283 authored by Maël Kervella's avatar Maël Kervella

Refactor display of rights in users/listright page

parent 1f4443d8
......@@ -108,3 +108,9 @@ footer a {
overflow-y: visible;
}
/* Make modal wider on wide screens */
@media (min-width: 1024px) {
.modal-dialog {
width: 1000px
}
}
......@@ -22,118 +22,173 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
{% endcomment %}
<table id="listRights_table" class="table">
<thead>
<tr>
<th>Droit</th>
<th>Gid</th>
<th>Groupe/permission critique</th>
<th>Informations</th>
<th>Details</th>
<th></th>
</tr>
</thead>
{% if superuser_right %}
<tr class="active">
<td>Superuser</td>
<td></td>
<td>True</td>
<td>
<button class="btn btn-default" data-parent="#accordion_superuser" type="button" data-toggle="collapse" data-target="#collapseListRight_user_superuser" aria-expanded="true" aria-controls="collapseListRight_user_superuser">
Utilisateurs ({{ superuser_right.count }})
{% load i18n %}
{% if superusers.count %}
<div class="panel panel-default">
<div class="panel-heading clearfix" data-toggle="collapse" data-target="#collapse_superuser">
<div class="pull-right">
<a data-toggle="modal" data-target="#modal_superuser">
<span class="badge">{{superusers.count}} <i class="fa fa-user"></i></span>
</a>
</div>
<h4 class="text-danger">
<i class="fa fa-address-book"></i>
Superuser
</h4>
Django's specific pre-defined right that supersed any other rights.
</div>
<div class="panel-collapse collapse" id="collapse_superuser">
<div class="panel-body">
<h4 class="text-danger">Total: All permissions</h4>
</div>
</div>
</div>
<div class="modal fade" id="modal_superuser" tabindex="-1" role="dialog" aria-labelledby="Users">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<i class="fa fa-times"></i>
</button>
</td>
<td>
Donne tous les droits sur Re2o.
</td>
<td class="text-right">
</td>
</tr>
<tr>
<td colspan=5>
<div class="panel-group" id="accordion_superuser" role="tablist" aria-multiselectable="true" style="margin-bottom: 0px;">
<div class="panel" style="border: none;">
<div class="panel-collapse collapse in" id="collapseListRight_user_superuser" role="tabpanel">
<ul class="list-group" style="margin-bottom: 0px">
{% for user in superuser_right %}
<li class="list-group-item col-xs-12 col-sm-6 col-md-4" style="border:none;">
{{user}}
<a role="button" href="{% url 'users:del-superuser' user.pk %}" title="{{ desc|default:"Supprimer" }}">
<i class="fa fa-times" style="color:red"></i>
</a>
</li>
{% endfor %}
</ul>
</div>
</div>
<h4 class="modal-title" id="myModalLabel">Users in Superuser</h4>
</div>
<div class="modal-body">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>{% trans "Username" %}</th>
<th>{% trans "Membership" %}</th>
<th>{% trans "Last seen" %}</th>
<th>{% trans "Actions" %}</th>
<th>{% trans "Last action" %}</th>
<th></th>
</tr>
</thead>
{% for user in superusers %}
<tr>
<td>{{ user.pseudo }}</td>
{% if user.is_adherent %}
<td class="text-success">{% trans "Member" %}</td>
{% elif not user.end_adhesion %}
<td class="text-warning">{% trans "No membership records" %}</td>
{% else %}
<td class="text-danger">
{% blocktrans with user.end_adhesion as end_date %}Not since {{ end_date }}{% endblocktrans %}
</td>
{% endif %}
<td>{{ user.last_login }}</td>
<td>{{ user.action_number }}</td>
{% if not user.last_seen %}
<td class="text-danger">{% trans "Never" %}</td>
{% else %}
<td class="text-success">{{user.last_seen}}</td>
{% endif %}
<td>
<a class="btn btn-danger" role="button" href="{% url 'users:del-superuser' user.id %}">
<span class="fa fa-user-times" aria-hidden="true"></span>
</a>
</td>
</tr>
{% endfor %}
</table>
</div>
</td>
</tr>
</div>
</div>
</div>
</div>
{% endif %}
{% endif %}
{% for listright in listright_list %}
<tr class="active">
<td>
{{ listright.name }}
</td>
<td>{{ listright.gid }}</td>
<td>{{ listright.critical }}</td>
<td>
<div class="dropdown">
<button class="btn btn-default" data-parent="#accordion_{{listright.gid}}" type="button" data-toggle="collapse" data-target="#collapseListRight_user_{{listright.gid}}" aria-expanded="true" aria-controls="collapseListRight_user_{{listright.gid}}">
Utilisateurs ({{ listright.user_set.all|length }})
</button>
<button class="btn btn-default" data-parent="#accordion_{{listright.gid}}" type="button" data-toggle="collapse" data-target="#collapseListRight_perm_{{listright.gid}}" aria-expanded="true" aria-controls="collapseListRight_perm_{{listright.gid}}">
Ensemble des permissions ({{ listright.permissions.all|length }})
</button>
</div>
</td>
<td>{{ listright.details }}</td>
<td class="text-right">
{% include 'buttons/edit.html' with href='users:edit-listright' id=listright.id %}
{% include 'buttons/history.html' with href='users:history' name='listright' id=listright.id %}
</td>
</tr>
<tr>
<td colspan=5>
<div class="panel-group" id="accordion_{{listright.gid}}" role="tablist" aria-multiselectable="true" style="margin-bottom: 0px;">
<div class="panel" style="border: none;">
<div class="panel-collapse collapse in" id="collapseListRight_perm_{{listright.gid}}" role="tabpanel">
<ul class="list-group" style="margin-bottom: 0px">
{% for perm in listright.permissions.all %}
<li class="list-group-item col-xs-6 col-sm-4 col-md-3" style="border:none;">
{{perm.name}}
</li>
{% endfor %}
</ul>
</div>
</div>
<div class="panel" style="border: none;">
<div class="panel-collapse collapse in" id="collapseListRight_user_{{listright.gid}}" role="tabpanel">
<ul class="list-group" style="margin-bottom: 0px">
{% for user in listright.user_set.all %}
<li class="list-group-item col-xs-12 col-sm-6 col-md-4" style="border:none;">
{{user}}
<a role="button" href="{% url 'users:del-group' user.id listright.id %}" title="{{ desc|default:"Supprimer" }}">
<i class="fa fa-times" style="color:red"></i>
</a>
</li>
{% endfor %}
</ul>
</div>
</div>
</div>
</td>
</tr>
{% endfor %}
</table>
{% for right, users in rights.items %}
<div class="panel panel-default">
<div class="panel-heading clearfix" data-toggle="collapse" data-target="#collapse_{{right.id}}">
<div class="pull-right">
{% if users %}
<a data-toggle="modal" data-target="#modal_{{right.id}}">
<span class="badge">{{users.count}} <i class="fa fa-user"></i></span>
</a>
{% else %}
<span class="badge">{{users.count}} <i class="fa fa-user"></i></span>
{% endif %}
{% include 'buttons/edit.html' with href='users:edit-listright' id=right.id %}
{% include 'buttons/history.html' with href='users:history' name='listright' id=right.id %}
</div>
<h4 class="{% if right.critical %}text-danger{% endif %}">
<i class="fa fa-address-book"></i>
{{right.name}} ({{ right.gid }})
</h4>
{{ right.details }}
</div>
<div class="panel-collapse collapse" id="collapse_{{right.id}}">
<div class="panel-body">
<h4>Total: {{ right.permissions.count }} permissions</h4>
<ul class="list-group" style="margin-bottom: 0px">
{% for perm in right.permissions.all %}
<li class="list-group-item col-xs-6 col-sm-4 col-md-3" style="border:none;">
{{perm.name}}
</li>
{% endfor %}
</ul>
</div>
</div>
</div>
<script>
$("#listRights_table").ready( function () {
var listRights_div = [{% for listright in listright_list %}[$("#accordion_{{listright.gid}}"), $("#collapseListRight_user_{{listright.gid}}"), $("#collapseListRight_perm_{{listright.gid}}")], {% endfor %}];
for (var i=0 ; i<listRights_div.length ; i++) {
listRights_div[i][1].collapse({ toggle: true, parent: listRights_div[i][0] });
listRights_div[i][2].collapse({ toggle: true, parent: listRights_div[i][0] });
}
} );
</script>
{% if users %}
<div class="modal fade" id="modal_{{right.id}}" tabindex="-1" role="dialog" aria-labelledby="Users">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<i class="fa fa-times"></i>
</button>
<h4 class="modal-title" id="myModalLabel">Users in {{ right.name }}</h4>
</div>
<div class="modal-body">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>{% trans "Username" %}</th>
<th>{% trans "Membership" %}</th>
<th>{% trans "Last seen" %}</th>
<th>{% trans "Actions" %}</th>
<th>{% trans "Last action" %}</th>
<th></th>
</tr>
</thead>
{% for user in users %}
<tr>
<td>{{ user.pseudo }}</td>
{% if user.is_adherent %}
<td class="text-success">{% trans "Member" %}</td>
{% elif not user.end_adhesion %}
<td class="text-warning">{% trans "No membership records" %}</td>
{% else %}
<td class="text-danger">
{% blocktrans with user.end_adhesion as end_date %}Not since {{ end_date }}{% endblocktrans %}
</td>
{% endif %}
<td>{{ user.last_login }}</td>
<td>{{ user.action_number }}</td>
{% if not user.last_seen %}
<td class="text-danger">{% trans "Never" %}</td>
{% else %}
<td class="text-success">{{user.last_seen}}</td>
{% endif %}
<td>
<a class="btn btn-danger" role="button" href="{% url 'users:del-group' user.id right.id %}">
<span class="fa fa-user-times" aria-hidden="true"></span>
</a>
</td>
</tr>
{% endfor %}
</table>
</div>
</div>
</div>
</div>
</div>
{% endif %}
{% endfor %}
......@@ -34,9 +34,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<a class="btn btn-primary btn-sm" role="button" href="{% url 'users:add-listright' %}"><i class="fa fa-plus"></i> Ajouter un droit ou groupe</a>
{% acl_end %}
<a class="btn btn-danger btn-sm" role="button" href="{% url 'users:del-listright' %}"><i class="fa fa-trash"></i> Supprimer un ou plusieurs droits/groupes</a>
{% include "users/aff_listright.html" with listright_list=listright_list %}
<br />
<br />
<br />
{% include "users/aff_listright.html" %}
{% endblock %}
......@@ -39,7 +39,7 @@ from django.urls import reverse
from django.shortcuts import get_object_or_404, render, redirect
from django.contrib import messages
from django.contrib.auth.decorators import login_required, permission_required
from django.db.models import ProtectedError
from django.db.models import ProtectedError, Count, Max
from django.utils import timezone
from django.db import transaction
from django.http import HttpResponse
......@@ -806,15 +806,27 @@ def index_shell(request):
@can_view_all(ListRight)
def index_listright(request):
""" Affiche l'ensemble des droits"""
listright_list = ListRight.objects.order_by('unix_name')\
.prefetch_related('permissions').prefetch_related('user_set')
superuser_right = User.objects.filter(is_superuser=True)
rights = {}
for right in (ListRight.objects
.order_by('name')
.prefetch_related('permissions')
.prefetch_related('user_set')
):
rights[right] = (right.user_set
.annotate(action_number=Count('revision'),
last_seen=Max('revision__date_created'))
)
superusers = (User.objects
.filter(is_superuser=True)
.annotate(action_number=Count('revision'),
last_seen=Max('revision__date_created'))
)
return render(
request,
'users/index_listright.html',
{
'listright_list': listright_list,
'superuser_right' : superuser_right,
'rights': rights,
'superusers' : superusers,
}
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment