diff --git a/re2o/templatetags/acl.py b/re2o/templatetags/acl.py
index c14fcbd6..c2d3ba24 100644
--- a/re2o/templatetags/acl.py
+++ b/re2o/templatetags/acl.py
@@ -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,
}
diff --git a/re2o/views.py b/re2o/views.py
index bfb2e6c5..3220e386 100644
--- a/re2o/views.py
+++ b/re2o/views.py
@@ -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,
diff --git a/users/forms.py b/users/forms.py
index 20121540..81f1e343 100644
--- a/users/forms.py
+++ b/users/forms.py
@@ -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"""
diff --git a/users/migrations/0070_auto_20180324_1906.py b/users/migrations/0070_auto_20180324_1906.py
new file mode 100644
index 00000000..fe6ae790
--- /dev/null
+++ b/users/migrations/0070_auto_20180324_1906.py
@@ -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"),)},
+ ),
+ ]
diff --git a/users/models.py b/users/models.py
index ed62edbb..5c6b5568 100644
--- a/users/models.py
+++ b/users/models.py
@@ -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
diff --git a/users/templates/users/aff_shell.html b/users/templates/users/aff_shell.html
new file mode 100644
index 00000000..ad325ddf
--- /dev/null
+++ b/users/templates/users/aff_shell.html
@@ -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 %}
+
+
+
+ Shell |
+ |
+
+
+ {% for shell in shell_list %}
+
+ {{ shell.shell }} |
+
+ {% 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 %}
+ |
+
+ {% endfor %}
+
+
diff --git a/users/templates/users/index_shell.html b/users/templates/users/index_shell.html
new file mode 100644
index 00000000..51fbb551
--- /dev/null
+++ b/users/templates/users/index_shell.html
@@ -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 %}
+ Liste des Shells
+ {% can_create ListShell %}
+ Ajouter un shell
+ {% acl_end %}
+ {% include "users/aff_shell.html" with shell_list=shell_list %}
+
+
+
+{% endblock %}
+
diff --git a/users/templates/users/sidebar.html b/users/templates/users/sidebar.html
index 4b561b49..0b21afa7 100644
--- a/users/templates/users/sidebar.html
+++ b/users/templates/users/sidebar.html
@@ -69,6 +69,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Établissements
{% acl_end %}
+ {% can_view_all ListShell %}
+
+
+ Liste des shells
+
+ {% acl_end %}
{% can_view_all ListRight %}
diff --git a/users/urls.py b/users/urls.py
index f15208d5..756498aa 100644
--- a/users/urls.py
+++ b/users/urls.py
@@ -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[0-9]+)$',
+ views.edit_shell,
+ name='edit-shell'
+ ),
+ url(
+ r'^del_shell/(?P[0-9]+)$',
+ views.del_shell,
+ name='del-shell'
+ ),
url(r'^profil/(?P[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/$',
diff --git a/users/views.py b/users/views.py
index 5d0e31a6..a6a28ed0 100644
--- a/users/views.py
+++ b/users/views.py
@@ -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(