diff --git a/users/admin.py b/users/admin.py index dfa1a61..3281d87 100644 --- a/users/admin.py +++ b/users/admin.py @@ -25,7 +25,7 @@ from django.contrib.auth.models import Group from django.contrib.auth.admin import UserAdmin as BaseUserAdmin from reversion.admin import VersionAdmin -from .models import User, Right, ListRight, Request +from .models import User, Right, ListRight, Clef, Request from .forms import UserChangeForm, UserCreationForm @@ -45,6 +45,9 @@ class RequestAdmin(admin.ModelAdmin): class RightAdmin(VersionAdmin): list_display = ('user', 'right') +class ClefAdmin(VersionAdmin): + list_display = ('proprio', 'nom') + class ListRightAdmin(VersionAdmin): list_display = ('listright',) @@ -79,6 +82,7 @@ admin.site.register(User, UserAdmin) admin.site.register(Request, RequestAdmin) admin.site.register(ListRight, ListRightAdmin) admin.site.register(Right, RightAdmin) +admin.site.register(Clef, ClefAdmin) # Now register the new UserAdmin... admin.site.unregister(User) admin.site.register(User, UserAdmin) diff --git a/users/migrations/0004_clef.py b/users/migrations/0004_clef.py new file mode 100644 index 0000000..f45afce --- /dev/null +++ b/users/migrations/0004_clef.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.2 on 2017-07-03 16:44 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0003_auto_20170629_2156'), + ] + + operations = [ + migrations.CreateModel( + name='Clef', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('nom', models.CharField(max_length=255, unique=True)), + ('proprio', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/users/migrations/0005_auto_20170703_1940.py b/users/migrations/0005_auto_20170703_1940.py new file mode 100644 index 0000000..a6bcd54 --- /dev/null +++ b/users/migrations/0005_auto_20170703_1940.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.2 on 2017-07-03 17:40 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0004_clef'), + ] + + operations = [ + migrations.AlterField( + model_name='clef', + name='proprio', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/users/migrations/0006_clef_commentaire.py b/users/migrations/0006_clef_commentaire.py new file mode 100644 index 0000000..e1c0b95 --- /dev/null +++ b/users/migrations/0006_clef_commentaire.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.2 on 2017-07-03 17:41 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0005_auto_20170703_1940'), + ] + + operations = [ + migrations.AddField( + model_name='clef', + name='commentaire', + field=models.CharField(blank=True, max_length=255, null=True), + ), + ] diff --git a/users/models.py b/users/models.py index f87d4b1..ad1d267 100644 --- a/users/models.py +++ b/users/models.py @@ -208,6 +208,11 @@ class ListRight(models.Model): def __str__(self): return self.listright +class Clef(models.Model): + nom = models.CharField(max_length=255, unique=True) + proprio = models.ForeignKey('User', on_delete=models.PROTECT, blank=True, null=True) + commentaire = models.CharField(max_length=255, null=True, blank=True) + class BaseInfoForm(ModelForm): def __init__(self, *args, **kwargs): super(BaseInfoForm, self).__init__(*args, **kwargs) @@ -249,6 +254,11 @@ class StateForm(ModelForm): model = User fields = ['state'] +class ClefForm(ModelForm): + class Meta: + model = Clef + fields = '__all__' + class RightForm(ModelForm): def __init__(self, *args, **kwargs): super(RightForm, self).__init__(*args, **kwargs) diff --git a/users/templates/users/aff_clef.html b/users/templates/users/aff_clef.html new file mode 100644 index 0000000..aed3c6d --- /dev/null +++ b/users/templates/users/aff_clef.html @@ -0,0 +1,46 @@ +{% 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 %} + + + + + + + + + + + {% for clef in clef_list %} + + + + + + + {% endfor %} +
ClefPropriétaireCommentaire
{{ clef.nom }}{{ clef.proprio }}{{ clef.commentaire }} + {% include 'buttons/edit.html' with href='users:edit-clef' id=clef.id %} + {% include 'buttons/suppr.html' with href='users:del-clef' id=clef.id %} + {% include 'buttons/history.html' with href='users:history' name='clef' id=clef.id %} +
diff --git a/users/templates/users/delete.html b/users/templates/users/delete.html new file mode 100644 index 0000000..1ca4061 --- /dev/null +++ b/users/templates/users/delete.html @@ -0,0 +1,40 @@ +{% extends "media/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 %} + +{% block title %}Création et modification de media{% endblock %} + +{% block content %} + +
+ {% csrf_token %} +

Attention, voulez-vous vraiment supprimer cet objet {{ objet_name }} ( {{ objet }} ) ?

+ {% bootstrap_button "Confirmer" button_type="submit" icon="trash" %} +
+
+
+
+{% endblock %} diff --git a/users/templates/users/index_clef.html b/users/templates/users/index_clef.html new file mode 100644 index 0000000..1ae3d42 --- /dev/null +++ b/users/templates/users/index_clef.html @@ -0,0 +1,39 @@ +{% 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 %} + +{% block title %}Clef{% endblock %} + +{% block content %} +

Liste des clef

+ {% if is_perm %} + Ajouter une clef + {% endif %} + {% include "users/aff_clef.html" with clef_list=clef_list %} +
+
+
+{% endblock %} diff --git a/users/templates/users/sidebar.html b/users/templates/users/sidebar.html index 9edc510..4ffb63f 100644 --- a/users/templates/users/sidebar.html +++ b/users/templates/users/sidebar.html @@ -38,6 +38,10 @@ with this program; if not, write to the Free Software Foundation, Inc., Droits + + + Clef + {% endif %} {% if is_bureau %} diff --git a/users/urls.py b/users/urls.py index 85eb569..b47f14a 100644 --- a/users/urls.py +++ b/users/urls.py @@ -36,6 +36,11 @@ urlpatterns = [ url(r'^edit_listright/(?P[0-9]+)$', views.edit_listright, name='edit-listright'), url(r'^del_listright/$', views.del_listright, name='del-listright'), url(r'^index_listright/$', views.index_listright, name='index-listright'), + url(r'^add_clef/$', views.add_clef, name='add-clef'), + url(r'^edit_clef/(?P[0-9]+)$', views.edit_clef, name='edit-clef'), + url(r'^del_clef/(?P[0-9]+)$', views.del_clef, name='del-clef'), + url(r'^index_clef/$', views.index_clef, name='index-clef'), + url(r'^history/(?Pclef)/(?P[0-9]+)$', views.history, name='history'), url(r'^add_right/(?P[0-9]+)$', views.add_right, name='add-right'), url(r'^del_right/$', views.del_right, name='del-right'), url(r'^process/(?P[a-z0-9]{32})/$', views.process, name='process'), diff --git a/users/views.py b/users/views.py index 79ecea4..8b9b9b3 100644 --- a/users/views.py +++ b/users/views.py @@ -40,7 +40,7 @@ from django.db import transaction from reversion.models import Version from reversion import revisions as reversion from users.models import User, Request, ListRight, Right, DelListRightForm, NewListRightForm, ListRightForm, RightForm, DelRightForm -from users.models import InfoForm, BaseInfoForm, StateForm +from users.models import InfoForm, BaseInfoForm, StateForm, Clef, ClefForm from users.forms import PassForm, ResetPasswordForm from media.models import Emprunt @@ -100,7 +100,6 @@ def new_user(request): req.save() reset_passwd_mail(req, request) messages.success(request, "L'utilisateur %s a été crée, un mail pour l'initialisation du mot de passe a été envoyé" % user.pseudo) - capture_mac(request, user) return redirect("/users/profil/" + str(user.id)) return form({'userform': user}, 'users/user.html', request) @@ -266,6 +265,58 @@ def index_listright(request): listright_list = ListRight.objects.order_by('listright') return render(request, 'users/index_listright.html', {'listright_list':listright_list}) +@login_required +@permission_required('perm') +def add_clef(request): + clef = ClefForm(request.POST or None) + if clef.is_valid(): + with transaction.atomic(), reversion.create_revision(): + clef.save() + reversion.set_user(request.user) + reversion.set_comment("Création") + messages.success(request, "La clef a été ajouté") + return redirect("/users/index_clef/") + return form({'userform': clef}, 'users/user.html', request) + +@login_required +@permission_required('perm') +def edit_clef(request, clefid): + try: + clef_instance = Clef.objects.get(pk=clefid) + except Clef.DoesNotExist: + messages.error(request, u"Entrée inexistante" ) + return redirect("/users/index_clef/") + clef = ClefForm(request.POST or None, instance=clef_instance) + if clef.is_valid(): + with transaction.atomic(), reversion.create_revision(): + clef.save() + reversion.set_user(request.user) + reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in clef.changed_data)) + messages.success(request, "Clef modifié") + return redirect("/users/index_clef/") + return form({'userform': clef}, 'users/user.html', request) + +@login_required +@permission_required('perm') +def del_clef(request, clefid): + try: + clef_instance = Clef.objects.get(pk=clefid) + except Clef.DoesNotExist: + messages.error(request, u"Entrée inexistante" ) + return redirect("/users/index_clef/") + if request.method == "POST": + with transaction.atomic(), reversion.create_revision(): + clef_instance.delete() + reversion.set_user(request.user) + messages.success(request, "La clef a été détruit") + return redirect("/users/index_clef") + return form({'objet': clef_instance, 'objet_name': 'clef'}, 'users/delete.html', request) + +@login_required +def index_clef(request): + clef_list = Clef.objects.all().order_by('nom') + return render(request, 'users/index_clef.html', {'clef_list':clef_list}) + @login_required @permission_required('perm') def index(request): @@ -296,6 +347,12 @@ def history(request, object, id): if not request.user.has_perms(('perm',)) and object_instance != request.user: messages.error(request, "Vous ne pouvez pas afficher l'historique d'un autre user que vous sans droit admin") return redirect("/users/profil/" + str(request.user.id)) + elif object == 'clef': + try: + object_instance = Clef.objects.get(pk=id) + except Clef.DoesNotExist: + messages.error(request, "Utilisateur inexistant") + return redirect("/users/") elif object == 'listright' and request.user.has_perms(('perm',)): try: object_instance = ListRight.objects.get(pk=id)