1
0
mirror of https://gitlab.crans.org/mediatek/med.git synced 2024-12-24 17:42:23 +00:00

Gestion des clefs

This commit is contained in:
Med 2017-07-03 20:06:21 +02:00
parent b2a653dd97
commit 0738b143b7
11 changed files with 275 additions and 3 deletions

View File

@ -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)

View File

@ -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)),
],
),
]

View File

@ -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),
),
]

View File

@ -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),
),
]

View File

@ -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)

View File

@ -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 %}
<table class="table table-striped">
<thead>
<tr>
<th>Clef</th>
<th>Propriétaire</th>
<th>Commentaire</th>
<th></th>
</tr>
</thead>
{% for clef in clef_list %}
<tr>
<td>{{ clef.nom }}</td>
<td>{{ clef.proprio }}</td>
<td>{{ clef.commentaire }}</td>
<td class="text-right">
{% 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 %}
</td>
</tr>
{% endfor %}
</table>

View File

@ -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 %}
<form class="form" method="post">
{% csrf_token %}
<h4>Attention, voulez-vous vraiment supprimer cet objet {{ objet_name }} ( {{ objet }} ) ?</h4>
{% bootstrap_button "Confirmer" button_type="submit" icon="trash" %}
</form>
<br />
<br />
<br />
{% endblock %}

View File

@ -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 %}
<h2>Liste des clef</h2>
{% if is_perm %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'users:add-clef' %}"><i class="glyphicon glyphicon-plus"></i> Ajouter une clef</a>
{% endif %}
{% include "users/aff_clef.html" with clef_list=clef_list %}
<br />
<br />
<br />
{% endblock %}

View File

@ -38,6 +38,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<i class="glyphicon glyphicon-list"></i>
Droits
</a>
<a class="list-group-item list-group-item-info" href="{% url "users:index-clef" %}">
<i class="glyphicon glyphicon-list"></i>
Clef
</a>
{% endif %}
{% if is_bureau %}
<a class="list-group-item list-group-item-danger" href="{% url "users:del-right" %}">

View File

@ -36,6 +36,11 @@ urlpatterns = [
url(r'^edit_listright/(?P<listrightid>[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<clefid>[0-9]+)$', views.edit_clef, name='edit-clef'),
url(r'^del_clef/(?P<clefid>[0-9]+)$', views.del_clef, name='del-clef'),
url(r'^index_clef/$', views.index_clef, name='index-clef'),
url(r'^history/(?P<object>clef)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^add_right/(?P<userid>[0-9]+)$', views.add_right, name='add-right'),
url(r'^del_right/$', views.del_right, name='del-right'),
url(r'^process/(?P<token>[a-z0-9]{32})/$', views.process, name='process'),

View File

@ -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)