mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 11:23:10 +00:00
Refactor display of rights in users/listright page
This commit is contained in:
parent
1f4443d857
commit
19f1e28308
4 changed files with 191 additions and 119 deletions
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -22,85 +22,110 @@ 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 %}
|
||||||
|
|
||||||
|
{% 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>
|
||||||
|
<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>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Droit</th>
|
<th>{% trans "Username" %}</th>
|
||||||
<th>Gid</th>
|
<th>{% trans "Membership" %}</th>
|
||||||
<th>Groupe/permission critique</th>
|
<th>{% trans "Last seen" %}</th>
|
||||||
<th>Informations</th>
|
<th>{% trans "Actions" %}</th>
|
||||||
<th>Details</th>
|
<th>{% trans "Last action" %}</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
{% if superuser_right %}
|
{% for user in superusers %}
|
||||||
<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 }})
|
|
||||||
</button>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
Donne tous les droits sur Re2o.
|
|
||||||
</td>
|
|
||||||
<td class="text-right">
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan=5>
|
<td>{{ user.pseudo }}</td>
|
||||||
<div class="panel-group" id="accordion_superuser" role="tablist" aria-multiselectable="true" style="margin-bottom: 0px;">
|
{% if user.is_adherent %}
|
||||||
<div class="panel" style="border: none;">
|
<td class="text-success">{% trans "Member" %}</td>
|
||||||
<div class="panel-collapse collapse in" id="collapseListRight_user_superuser" role="tabpanel">
|
{% elif not user.end_adhesion %}
|
||||||
<ul class="list-group" style="margin-bottom: 0px">
|
<td class="text-warning">{% trans "No membership records" %}</td>
|
||||||
{% for user in superuser_right %}
|
{% else %}
|
||||||
<li class="list-group-item col-xs-12 col-sm-6 col-md-4" style="border:none;">
|
<td class="text-danger">
|
||||||
{{user}}
|
{% blocktrans with user.end_adhesion as end_date %}Not since {{ end_date }}{% endblocktrans %}
|
||||||
<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>
|
|
||||||
</div>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% for listright in listright_list %}
|
<td>{{ user.last_login }}</td>
|
||||||
<tr class="active">
|
<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>
|
<td>
|
||||||
{{ listright.name }}
|
<a class="btn btn-danger" role="button" href="{% url 'users:del-superuser' user.id %}">
|
||||||
</td>
|
<span class="fa fa-user-times" aria-hidden="true"></span>
|
||||||
<td>{{ listright.gid }}</td>
|
</a>
|
||||||
<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>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
{% endfor %}
|
||||||
<td colspan=5>
|
</table>
|
||||||
<div class="panel-group" id="accordion_{{listright.gid}}" role="tablist" aria-multiselectable="true" style="margin-bottom: 0px;">
|
</div>
|
||||||
<div class="panel" style="border: none;">
|
</div>
|
||||||
<div class="panel-collapse collapse in" id="collapseListRight_perm_{{listright.gid}}" role="tabpanel">
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% 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">
|
<ul class="list-group" style="margin-bottom: 0px">
|
||||||
{% for perm in listright.permissions.all %}
|
{% for perm in right.permissions.all %}
|
||||||
<li class="list-group-item col-xs-6 col-sm-4 col-md-3" style="border:none;">
|
<li class="list-group-item col-xs-6 col-sm-4 col-md-3" style="border:none;">
|
||||||
{{perm.name}}
|
{{perm.name}}
|
||||||
</li>
|
</li>
|
||||||
|
@ -108,32 +133,62 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel" style="border: none;">
|
</div>
|
||||||
<div class="panel-collapse collapse in" id="collapseListRight_user_{{listright.gid}}" role="tabpanel">
|
|
||||||
<ul class="list-group" style="margin-bottom: 0px">
|
{% if users %}
|
||||||
{% for user in listright.user_set.all %}
|
<div class="modal fade" id="modal_{{right.id}}" tabindex="-1" role="dialog" aria-labelledby="Users">
|
||||||
<li class="list-group-item col-xs-12 col-sm-6 col-md-4" style="border:none;">
|
<div class="modal-dialog" role="document">
|
||||||
{{user}}
|
<div class="modal-content">
|
||||||
<a role="button" href="{% url 'users:del-group' user.id listright.id %}" title="{{ desc|default:"Supprimer" }}">
|
<div class="modal-header">
|
||||||
<i class="fa fa-times" style="color:red"></i>
|
<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>
|
</a>
|
||||||
</li>
|
|
||||||
{% endfor %}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
</div>
|
||||||
<script>
|
</div>
|
||||||
$("#listRights_table").ready( function () {
|
</div>
|
||||||
var listRights_div = [{% for listright in listright_list %}[$("#accordion_{{listright.gid}}"), $("#collapseListRight_user_{{listright.gid}}"), $("#collapseListRight_perm_{{listright.gid}}")], {% endfor %}];
|
</div>
|
||||||
for (var i=0 ; i<listRights_div.length ; i++) {
|
</div>
|
||||||
listRights_div[i][1].collapse({ toggle: true, parent: listRights_div[i][0] });
|
{% endif %}
|
||||||
listRights_div[i][2].collapse({ toggle: true, parent: listRights_div[i][0] });
|
{% endfor %}
|
||||||
}
|
|
||||||
} );
|
|
||||||
</script>
|
|
||||||
|
|
|
@ -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 %}
|
||||||
|
|
||||||
|
|
|
@ -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,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue