mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-26 08:53:46 +00:00
Change le mode de retrait des droits(en tableau)
This commit is contained in:
parent
c205775434
commit
0b43d82dda
4 changed files with 79 additions and 13 deletions
|
@ -258,7 +258,7 @@ class NewListRightForm(ListRightForm):
|
||||||
self.fields['gid'].label = 'Gid, attention, cet attribut ne doit pas être modifié après création'
|
self.fields['gid'].label = 'Gid, attention, cet attribut ne doit pas être modifié après création'
|
||||||
|
|
||||||
class DelListRightForm(ModelForm):
|
class DelListRightForm(ModelForm):
|
||||||
listrights = forms.ModelMultipleChoiceField(queryset=ListRight.objects.all().select_related('user'), label="Droits actuels", widget=forms.CheckboxSelectMultiple)
|
listrights = forms.ModelMultipleChoiceField(queryset=ListRight.objects.all().select_related('user'), label="Droits actuels", widget=forms.CheckboxSelectMultiple)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
exclude = ['listright','gid']
|
exclude = ['listright','gid']
|
||||||
|
@ -284,7 +284,12 @@ class RightForm(ModelForm):
|
||||||
|
|
||||||
|
|
||||||
class DelRightForm(ModelForm):
|
class DelRightForm(ModelForm):
|
||||||
rights = forms.ModelMultipleChoiceField(queryset=Right.objects.all(), label="Droits actuels", widget=forms.CheckboxSelectMultiple)
|
rights = forms.ModelMultipleChoiceField(queryset=Right.objects.all(), widget=forms.CheckboxSelectMultiple)
|
||||||
|
|
||||||
|
def __init__(self, right, *args, **kwargs):
|
||||||
|
super(DelRightForm, self).__init__(*args, **kwargs)
|
||||||
|
self.fields['rights'].queryset = Right.objects.filter(right=right)
|
||||||
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Right
|
model = Right
|
||||||
|
|
|
@ -461,7 +461,7 @@ class Right(models.Model):
|
||||||
unique_together = ("user", "right")
|
unique_together = ("user", "right")
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.user) + " - " + str(self.right)
|
return str(self.user)
|
||||||
|
|
||||||
@receiver(post_save, sender=Right)
|
@receiver(post_save, sender=Right)
|
||||||
def right_post_save(sender, **kwargs):
|
def right_post_save(sender, **kwargs):
|
||||||
|
|
58
users/templates/users/del_right.html
Normal file
58
users/templates/users/del_right.html
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
{% 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 %}Création et modification d'utilisateur{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<h1>Gestion des droits</h1>
|
||||||
|
|
||||||
|
<form class="form" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
{% for key, values in userform.items %}
|
||||||
|
<th>{{ key }}</th>
|
||||||
|
{% endfor %}
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tr>
|
||||||
|
{% for key, values in userform.items %}
|
||||||
|
{% bootstrap_form_errors values %}
|
||||||
|
<th>{{ values.rights }}</th>
|
||||||
|
{% endfor %}
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
{% bootstrap_button "Modifier" button_type="submit" icon="star" %}
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
{% endblock %}
|
|
@ -297,16 +297,19 @@ def add_right(request, userid):
|
||||||
@permission_required('bureau')
|
@permission_required('bureau')
|
||||||
def del_right(request):
|
def del_right(request):
|
||||||
""" Supprimer un droit à un user, need droit bureau """
|
""" Supprimer un droit à un user, need droit bureau """
|
||||||
user_right_list = DelRightForm(request.POST or None)
|
user_right_list = dict()
|
||||||
if user_right_list.is_valid():
|
for right in ListRight.objects.all():
|
||||||
right_del = user_right_list.cleaned_data['rights']
|
user_right_list[right]= DelRightForm(right, request.POST or None)
|
||||||
with transaction.atomic(), reversion.create_revision():
|
for keys, right_item in user_right_list.items():
|
||||||
reversion.set_user(request.user)
|
if right_item.is_valid():
|
||||||
reversion.set_comment("Retrait des droit %s" % ','.join(str(deleted_right) for deleted_right in right_del))
|
right_del = right_item.cleaned_data['rights']
|
||||||
right_del.delete()
|
with transaction.atomic(), reversion.create_revision():
|
||||||
messages.success(request, "Droit retiré avec succès")
|
reversion.set_user(request.user)
|
||||||
return redirect("/users/")
|
reversion.set_comment("Retrait des droit %s" % ','.join(str(deleted_right) for deleted_right in right_del))
|
||||||
return form({'userform': user_right_list}, 'users/user.html', request)
|
right_del.delete()
|
||||||
|
messages.success(request, "Droit retiré avec succès")
|
||||||
|
return redirect("/users/")
|
||||||
|
return form({'userform': user_right_list}, 'users/del_right.html', request)
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('bofh')
|
@permission_required('bofh')
|
||||||
|
|
Loading…
Reference in a new issue