8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-10-05 18:42:12 +00:00

Refactor display of rights in users/listright page

This commit is contained in:
Maël Kervella 2018-06-27 19:37:13 +00:00
parent 1f4443d857
commit 19f1e28308
4 changed files with 191 additions and 119 deletions

View file

@ -108,3 +108,9 @@ footer a {
overflow-y: visible; overflow-y: visible;
} }
/* Make modal wider on wide screens */
@media (min-width: 1024px) {
.modal-dialog {
width: 1000px
}
}

View file

@ -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. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
{% endcomment %} {% endcomment %}
<table id="listRights_table" class="table"> {% load i18n %}
<thead>
<tr> {% if superusers.count %}
<th>Droit</th> <div class="panel panel-default">
<th>Gid</th> <div class="panel-heading clearfix" data-toggle="collapse" data-target="#collapse_superuser">
<th>Groupe/permission critique</th> <div class="pull-right">
<th>Informations</th> <a data-toggle="modal" data-target="#modal_superuser">
<th>Details</th> <span class="badge">{{superusers.count}} <i class="fa fa-user"></i></span>
<th></th> </a>
</tr> </div>
</thead> <h4 class="text-danger">
{% if superuser_right %} <i class="fa fa-address-book"></i>
<tr class="active"> Superuser
<td>Superuser</td> </h4>
<td></td> Django's specific pre-defined right that supersed any other rights.
<td>True</td> </div>
<td> <div class="panel-collapse collapse" id="collapse_superuser">
<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"> <div class="panel-body">
Utilisateurs ({{ superuser_right.count }}) <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> </button>
</td> <h4 class="modal-title" id="myModalLabel">Users in Superuser</h4>
<td> </div>
Donne tous les droits sur Re2o. <div class="modal-body">
</td> <div class="table-responsive">
<td class="text-right"> <table class="table table-striped">
</td> <thead>
</tr> <tr>
<tr> <th>{% trans "Username" %}</th>
<td colspan=5> <th>{% trans "Membership" %}</th>
<div class="panel-group" id="accordion_superuser" role="tablist" aria-multiselectable="true" style="margin-bottom: 0px;"> <th>{% trans "Last seen" %}</th>
<div class="panel" style="border: none;"> <th>{% trans "Actions" %}</th>
<div class="panel-collapse collapse in" id="collapseListRight_user_superuser" role="tabpanel"> <th>{% trans "Last action" %}</th>
<ul class="list-group" style="margin-bottom: 0px"> <th></th>
{% for user in superuser_right %} </tr>
<li class="list-group-item col-xs-12 col-sm-6 col-md-4" style="border:none;"> </thead>
{{user}} {% for user in superusers %}
<a role="button" href="{% url 'users:del-superuser' user.pk %}" title="{{ desc|default:"Supprimer" }}"> <tr>
<i class="fa fa-times" style="color:red"></i> <td>{{ user.pseudo }}</td>
</a> {% if user.is_adherent %}
</li> <td class="text-success">{% trans "Member" %}</td>
{% endfor %} {% elif not user.end_adhesion %}
</ul> <td class="text-warning">{% trans "No membership records" %}</td>
</div> {% else %}
</div> <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> </div>
</td> </div>
</tr> </div>
</div>
</div>
{% endif %}
{% endif %} {% for right, users in rights.items %}
{% for listright in listright_list %} <div class="panel panel-default">
<tr class="active"> <div class="panel-heading clearfix" data-toggle="collapse" data-target="#collapse_{{right.id}}">
<td> <div class="pull-right">
{{ listright.name }} {% if users %}
</td> <a data-toggle="modal" data-target="#modal_{{right.id}}">
<td>{{ listright.gid }}</td> <span class="badge">{{users.count}} <i class="fa fa-user"></i></span>
<td>{{ listright.critical }}</td> </a>
<td> {% else %}
<div class="dropdown"> <span class="badge">{{users.count}} <i class="fa fa-user"></i></span>
<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}}"> {% endif %}
Utilisateurs ({{ listright.user_set.all|length }}) {% include 'buttons/edit.html' with href='users:edit-listright' id=right.id %}
</button> {% include 'buttons/history.html' with href='users:history' name='listright' id=right.id %}
<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}}"> </div>
Ensemble des permissions ({{ listright.permissions.all|length }}) <h4 class="{% if right.critical %}text-danger{% endif %}">
</button> <i class="fa fa-address-book"></i>
</div> {{right.name}} ({{ right.gid }})
</td> </h4>
<td>{{ listright.details }}</td> {{ right.details }}
<td class="text-right"> </div>
{% include 'buttons/edit.html' with href='users:edit-listright' id=listright.id %} <div class="panel-collapse collapse" id="collapse_{{right.id}}">
{% include 'buttons/history.html' with href='users:history' name='listright' id=listright.id %} <div class="panel-body">
</td> <h4>Total: {{ right.permissions.count }} permissions</h4>
</tr> <ul class="list-group" style="margin-bottom: 0px">
<tr> {% for perm in right.permissions.all %}
<td colspan=5> <li class="list-group-item col-xs-6 col-sm-4 col-md-3" style="border:none;">
<div class="panel-group" id="accordion_{{listright.gid}}" role="tablist" aria-multiselectable="true" style="margin-bottom: 0px;"> {{perm.name}}
<div class="panel" style="border: none;"> </li>
<div class="panel-collapse collapse in" id="collapseListRight_perm_{{listright.gid}}" role="tabpanel"> {% endfor %}
<ul class="list-group" style="margin-bottom: 0px"> </ul>
{% for perm in listright.permissions.all %} </div>
<li class="list-group-item col-xs-6 col-sm-4 col-md-3" style="border:none;"> </div>
{{perm.name}} </div>
</li>
{% endfor %} {% if users %}
</ul> <div class="modal fade" id="modal_{{right.id}}" tabindex="-1" role="dialog" aria-labelledby="Users">
</div> <div class="modal-dialog" role="document">
</div> <div class="modal-content">
<div class="panel" style="border: none;"> <div class="modal-header">
<div class="panel-collapse collapse in" id="collapseListRight_user_{{listright.gid}}" role="tabpanel"> <button type="button" class="close" data-dismiss="modal" aria-label="Close">
<ul class="list-group" style="margin-bottom: 0px"> <i class="fa fa-times"></i>
{% for user in listright.user_set.all %} </button>
<li class="list-group-item col-xs-12 col-sm-6 col-md-4" style="border:none;"> <h4 class="modal-title" id="myModalLabel">Users in {{ right.name }}</h4>
{{user}} </div>
<a role="button" href="{% url 'users:del-group' user.id listright.id %}" title="{{ desc|default:"Supprimer" }}"> <div class="modal-body">
<i class="fa fa-times" style="color:red"></i> <div class="table-responsive">
</a> <table class="table table-striped">
</li> <thead>
{% endfor %} <tr>
</ul> <th>{% trans "Username" %}</th>
</div> <th>{% trans "Membership" %}</th>
</div> <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>
</td> </div>
</tr> </div>
{% endfor %} </div>
</table> </div>
{% endif %}
<script> {% endfor %}
$("#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>

View file

@ -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> <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 %} {% 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> <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 />
<br /> <br />
{% include "users/aff_listright.html" %}
{% endblock %} {% endblock %}

View file

@ -39,7 +39,7 @@ from django.urls import reverse
from django.shortcuts import get_object_or_404, render, redirect from django.shortcuts import get_object_or_404, render, redirect
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.decorators import login_required, permission_required 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.utils import timezone
from django.db import transaction from django.db import transaction
from django.http import HttpResponse from django.http import HttpResponse
@ -806,15 +806,27 @@ def index_shell(request):
@can_view_all(ListRight) @can_view_all(ListRight)
def index_listright(request): def index_listright(request):
""" Affiche l'ensemble des droits""" """ Affiche l'ensemble des droits"""
listright_list = ListRight.objects.order_by('unix_name')\ rights = {}
.prefetch_related('permissions').prefetch_related('user_set') for right in (ListRight.objects
superuser_right = User.objects.filter(is_superuser=True) .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( return render(
request, request,
'users/index_listright.html', 'users/index_listright.html',
{ {
'listright_list': listright_list, 'rights': rights,
'superuser_right' : superuser_right, 'superusers' : superusers,
} }
) )