mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-05 01:16:27 +00:00
Edition graphique des shells pour les admin
This commit is contained in:
parent
53dc43f586
commit
1038625fb8
10 changed files with 279 additions and 5 deletions
|
@ -133,6 +133,7 @@ MODEL_NAME = {
|
|||
'ServiceUser' : users.models.ServiceUser,
|
||||
'School' : users.models.School,
|
||||
'ListRight' : users.models.ListRight,
|
||||
'ListShell' : users.models.ListShell,
|
||||
'Ban' : users.models.Ban,
|
||||
'Whitelist' : users.models.Whitelist,
|
||||
}
|
||||
|
|
|
@ -65,6 +65,7 @@ HISTORY_BIND = {
|
|||
'school' : users.models.School,
|
||||
'listright' : users.models.ListRight,
|
||||
'serviceuser' : users.models.ServiceUser,
|
||||
'shell' : users.models.ListShell,
|
||||
},
|
||||
'preferences' : {
|
||||
'service' : preferences.models.Service,
|
||||
|
|
|
@ -41,8 +41,17 @@ from django.utils import timezone
|
|||
from django.contrib.auth.models import Group, Permission
|
||||
|
||||
from preferences.models import OptionalUser
|
||||
from .models import User, ServiceUser, School, ListRight, Whitelist
|
||||
from .models import Ban, Adherent, Club
|
||||
from .models import (
|
||||
User,
|
||||
ServiceUser,
|
||||
School,
|
||||
ListRight,
|
||||
Whitelist,
|
||||
ListShell,
|
||||
Ban,
|
||||
Adherent,
|
||||
Club
|
||||
)
|
||||
from re2o.utils import remove_user_room
|
||||
|
||||
from re2o.field_permissions import FieldPermissionFormMixin
|
||||
|
@ -460,6 +469,18 @@ class SchoolForm(ModelForm):
|
|||
self.fields['name'].label = 'Établissement'
|
||||
|
||||
|
||||
class ShellForm(ModelForm):
|
||||
"""Edition, creation d'un école"""
|
||||
class Meta:
|
||||
model = ListShell
|
||||
fields = ['shell']
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
||||
super(ShellForm, self).__init__(*args, prefix=prefix, **kwargs)
|
||||
self.fields['shell'].label = 'Nom du shell'
|
||||
|
||||
|
||||
class ListRightForm(ModelForm):
|
||||
"""Edition, d'un groupe , équivalent à un droit
|
||||
Ne peremet pas d'editer le gid, car il sert de primary key"""
|
||||
|
|
19
users/migrations/0070_auto_20180324_1906.py
Normal file
19
users/migrations/0070_auto_20180324_1906.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.7 on 2018-03-24 18:06
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('users', '0069_club_mailing'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='listshell',
|
||||
options={'permissions': (('view_listshell', "Peut voir un objet shell quelqu'il soit"),)},
|
||||
),
|
||||
]
|
|
@ -1248,10 +1248,67 @@ class ListShell(models.Model):
|
|||
|
||||
shell = models.CharField(max_length=255, unique=True)
|
||||
|
||||
class Meta:
|
||||
permissions = (
|
||||
("view_listshell", "Peut voir un objet shell quelqu'il soit"),
|
||||
)
|
||||
|
||||
def get_instance(shellid, *args, **kwargs):
|
||||
return ListShell.objects.get(pk=shellid)
|
||||
|
||||
def get_pretty_name(self):
|
||||
"""Return the canonical name of the shell"""
|
||||
return self.shell.split("/")[-1]
|
||||
|
||||
def can_create(user_request, *args, **kwargs):
|
||||
"""Check if an user can create a ListShell object.
|
||||
|
||||
:param user_request: The user who wants to create a user object.
|
||||
:return: a message and a boolean which is True if the user can create.
|
||||
"""
|
||||
return user_request.has_perm('users.add_listshell'), u"Vous n'avez pas le\
|
||||
droit de créer des shells"
|
||||
|
||||
def can_edit(self, user_request, *args, **kwargs):
|
||||
"""Check if an user can edit a ListShell object.
|
||||
|
||||
:param self: The Shell which is to be edited.
|
||||
:param user_request: The user who requests to edit self.
|
||||
:return: a message and a boolean which is True if edition is granted.
|
||||
"""
|
||||
return user_request.has_perm('users.change_listshell'), u"Vous n'avez pas le\
|
||||
droit d'éditer des shells"
|
||||
|
||||
def can_delete(self, user_request, *args, **kwargs):
|
||||
"""Check if an user can delete a ListShell object.
|
||||
|
||||
:param self: The Shell which is to be deleted.
|
||||
:param user_request: The user who requests deletion.
|
||||
:return: True if deletion is granted, and a message.
|
||||
"""
|
||||
return user_request.has_perm('users.delete_listshell'), u"Vous n'avez pas le\
|
||||
droit de supprimer des shells"
|
||||
|
||||
def can_view_all(user_request, *args, **kwargs):
|
||||
"""Check if an user can access to the list of every ListShell objects
|
||||
|
||||
:param user_request: The user who wants to view the list.
|
||||
:return: True if the user can view the list and an explanation message.
|
||||
"""
|
||||
return user_request.has_perm('users.view_listshell'), u"Vous n'avez pas le\
|
||||
droit de voir les shells"
|
||||
|
||||
def can_view(self, user_request, *args, **kwargs):
|
||||
"""Check if an user can view a ListShell object.
|
||||
|
||||
:param self: The targeted ListShell instance.
|
||||
:param user_request: The user who ask for viewing the target.
|
||||
:return: A boolean telling if the acces is granted and an explanation
|
||||
text
|
||||
"""
|
||||
return user_request.has_perm('users.view_listshell'), u"Vous n'avez pas le\
|
||||
droit de voir les shells"
|
||||
|
||||
def __str__(self):
|
||||
return self.shell
|
||||
|
||||
|
|
47
users/templates/users/aff_shell.html
Normal file
47
users/templates/users/aff_shell.html
Normal file
|
@ -0,0 +1,47 @@
|
|||
{% comment %}
|
||||
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
|
||||
se veut agnostique au réseau considéré, de manière à être installable en
|
||||
quelques clics.
|
||||
|
||||
Copyright © 2017 Gabriel Détraz
|
||||
Copyright © 2017 Goulven Kermarec
|
||||
Copyright © 2017 Augustin Lemesle
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
{% endcomment %}
|
||||
{% load acl %}
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Shell</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
{% for shell in shell_list %}
|
||||
<tr>
|
||||
<td>{{ shell.shell }}</td>
|
||||
<td class="text-right">
|
||||
{% can_delete shell %}
|
||||
{% include 'buttons/suppr.html' with href='users:del-shell' id=shell.id %}
|
||||
{% acl_end %}
|
||||
{% can_edit shell %}
|
||||
{% include 'buttons/edit.html' with href='users:edit-shell' id=shell.id %}
|
||||
{% acl_end %}
|
||||
{% include 'buttons/history.html' with href='users:history' name='shell' id=shell.id %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
41
users/templates/users/index_shell.html
Normal file
41
users/templates/users/index_shell.html
Normal file
|
@ -0,0 +1,41 @@
|
|||
{% extends "users/sidebar.html" %}
|
||||
{% comment %}
|
||||
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
|
||||
se veut agnostique au réseau considéré, de manière à être installable en
|
||||
quelques clics.
|
||||
|
||||
Copyright © 2017 Gabriel Détraz
|
||||
Copyright © 2017 Goulven Kermarec
|
||||
Copyright © 2017 Augustin Lemesle
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
{% endcomment %}
|
||||
|
||||
{% load bootstrap3 %}
|
||||
{% load acl %}
|
||||
|
||||
{% block title %}Utilisateurs{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2>Liste des Shells</h2>
|
||||
{% can_create ListShell %}
|
||||
<a class="btn btn-primary btn-sm" role="button" href="{% url 'users:add-shell' %}"><i class="fa fa-plus"></i> Ajouter un shell</a>
|
||||
{% acl_end %}
|
||||
{% include "users/aff_shell.html" with shell_list=shell_list %}
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
{% endblock %}
|
||||
|
|
@ -69,6 +69,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
Établissements
|
||||
</a>
|
||||
{% acl_end %}
|
||||
{% can_view_all ListShell %}
|
||||
<a class="list-group-item list-group-item-info" href="{% url "users:index-shell" %}">
|
||||
<i class="fa fa-list-ul"></i>
|
||||
Liste des shells
|
||||
</a>
|
||||
{% acl_end %}
|
||||
{% can_view_all ListRight %}
|
||||
<a class="list-group-item list-group-item-info" href="{% url "users:index-listright" %}">
|
||||
<i class="fa fa-list-ul"></i>
|
||||
|
|
|
@ -80,10 +80,22 @@ urlpatterns = [
|
|||
name='edit-listright'
|
||||
),
|
||||
url(r'^del_listright/$', views.del_listright, name='del-listright'),
|
||||
url(r'^add_shell/$', views.add_shell, name='add-shell'),
|
||||
url(
|
||||
r'^edit_shell/(?P<shellid>[0-9]+)$',
|
||||
views.edit_shell,
|
||||
name='edit-shell'
|
||||
),
|
||||
url(
|
||||
r'^del_shell/(?P<shellid>[0-9]+)$',
|
||||
views.del_shell,
|
||||
name='del-shell'
|
||||
),
|
||||
url(r'^profil/(?P<userid>[0-9]+)$', views.profil, name='profil'),
|
||||
url(r'^index_ban/$', views.index_ban, name='index-ban'),
|
||||
url(r'^index_white/$', views.index_white, name='index-white'),
|
||||
url(r'^index_school/$', views.index_school, name='index-school'),
|
||||
url(r'^index_shell/$', views.index_shell, name='index-shell'),
|
||||
url(r'^index_listright/$', views.index_listright, name='index-listright'),
|
||||
url(
|
||||
r'^index_serviceusers/$',
|
||||
|
|
|
@ -45,8 +45,10 @@ from django.db import IntegrityError
|
|||
from django.utils import timezone
|
||||
from django.db import transaction
|
||||
from django.http import HttpResponse
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
|
||||
from rest_framework.renderers import JSONRenderer
|
||||
|
||||
|
||||
|
@ -63,6 +65,7 @@ from users.models import (
|
|||
ServiceUser,
|
||||
Adherent,
|
||||
Club,
|
||||
ListShell,
|
||||
)
|
||||
from users.forms import (
|
||||
BanForm,
|
||||
|
@ -72,6 +75,7 @@ from users.forms import (
|
|||
NewListRightForm,
|
||||
StateForm,
|
||||
SchoolForm,
|
||||
ShellForm,
|
||||
EditServiceUserForm,
|
||||
ServiceUserForm,
|
||||
ListRightForm,
|
||||
|
@ -273,8 +277,10 @@ def del_group(request, user, userid, listrightid):
|
|||
with transaction.atomic(), reversion.create_revision():
|
||||
user.groups.remove(ListRight.objects.get(id=listrightid))
|
||||
user.save()
|
||||
reversion.set_user(request.user)
|
||||
reversion.set_comment("Suppression de droit")
|
||||
messages.success(request, "Droit supprimé à %s" % user)
|
||||
return redirect(reverse('users:index-listright'))
|
||||
return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
|
||||
|
||||
|
||||
@login_required
|
||||
|
@ -492,6 +498,57 @@ def del_school(request, instances):
|
|||
return form({'userform': school, 'action_name': 'Supprimer'}, 'users/user.html', request)
|
||||
|
||||
|
||||
@login_required
|
||||
@can_create(ListShell)
|
||||
def add_shell(request):
|
||||
""" Ajouter un établissement d'enseignement à la base de donnée,
|
||||
need cableur"""
|
||||
shell = ShellForm(request.POST or None)
|
||||
if shell.is_valid():
|
||||
with transaction.atomic(), reversion.create_revision():
|
||||
shell.save()
|
||||
reversion.set_user(request.user)
|
||||
reversion.set_comment("Création")
|
||||
messages.success(request, "Le shell a été ajouté")
|
||||
return redirect(reverse('users:index-shell'))
|
||||
return form({'userform': shell, 'action_name':'Ajouter'}, 'users/user.html', request)
|
||||
|
||||
|
||||
@login_required
|
||||
@can_edit(ListShell)
|
||||
def edit_shell(request, shell_instance, shellid):
|
||||
""" Editer un établissement d'enseignement à partir du shellid dans
|
||||
la base de donnée, need cableur"""
|
||||
shell = ShellForm(request.POST or None, instance=shell_instance)
|
||||
if shell.is_valid():
|
||||
with transaction.atomic(), reversion.create_revision():
|
||||
shell.save()
|
||||
reversion.set_user(request.user)
|
||||
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(
|
||||
field for field in shell.changed_data
|
||||
))
|
||||
messages.success(request, "Le shell a été modifié")
|
||||
return redirect(reverse('users:index-shell'))
|
||||
return form({'userform': shell, 'action_name':'Editer'}, 'users/user.html', request)
|
||||
|
||||
|
||||
@login_required
|
||||
@can_delete(ListShell)
|
||||
def del_shell(request, shell, shellid):
|
||||
"""Destruction d'un shell"""
|
||||
if request.method == "POST":
|
||||
with transaction.atomic(), reversion.create_revision():
|
||||
shell.delete()
|
||||
reversion.set_user(request.user)
|
||||
messages.success(request, "Le shell a été détruit")
|
||||
return redirect(reverse('users:index-shell'))
|
||||
return form(
|
||||
{'objet': shell, 'objet_name': 'shell'},
|
||||
'users/delete.html',
|
||||
request
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@can_create(ListRight)
|
||||
def add_listright(request):
|
||||
|
@ -690,7 +747,7 @@ def index_white(request):
|
|||
@login_required
|
||||
@can_view_all(School)
|
||||
def index_school(request):
|
||||
""" Affiche l'ensemble des établissement, need droit cableur """
|
||||
""" Affiche l'ensemble des établissement"""
|
||||
school_list = School.objects.order_by('name')
|
||||
return render(
|
||||
request,
|
||||
|
@ -699,10 +756,22 @@ def index_school(request):
|
|||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@can_view_all(ListShell)
|
||||
def index_shell(request):
|
||||
""" Affiche l'ensemble des shells"""
|
||||
shell_list = ListShell.objects.order_by('shell')
|
||||
return render(
|
||||
request,
|
||||
'users/index_shell.html',
|
||||
{'shell_list': shell_list}
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@can_view_all(ListRight)
|
||||
def index_listright(request):
|
||||
""" Affiche l'ensemble des droits , need droit cableur """
|
||||
""" Affiche l'ensemble des droits"""
|
||||
listright_list = ListRight.objects.order_by('unix_name')\
|
||||
.prefetch_related('permissions').prefetch_related('user_set')
|
||||
return render(
|
||||
|
|
Loading…
Reference in a new issue