mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-27 07:02:26 +00:00
Ajoute une fonction pour l'archivage de masse
This commit is contained in:
parent
8ce74665d6
commit
3fc6c725bc
6 changed files with 97 additions and 2 deletions
|
@ -26,6 +26,7 @@
|
|||
from django import forms
|
||||
from django.contrib.auth.forms import ReadOnlyPasswordHashField
|
||||
from django.core.validators import MinLengthValidator
|
||||
from django.utils import timezone
|
||||
|
||||
from .models import User, ServiceUser, get_admin_right
|
||||
|
||||
|
@ -137,3 +138,13 @@ class ServiceUserChangeForm(forms.ModelForm):
|
|||
class ResetPasswordForm(forms.Form):
|
||||
pseudo = forms.CharField(label=u'Pseudo', max_length=255)
|
||||
email = forms.EmailField(max_length=255)
|
||||
|
||||
class MassArchiveForm(forms.Form):
|
||||
date = forms.DateTimeField(help_text='%d/%m/%y')
|
||||
|
||||
def clean(self):
|
||||
cleaned_data=super(MassArchiveForm, self).clean()
|
||||
date = cleaned_data.get("date")
|
||||
if date:
|
||||
if date>timezone.now():
|
||||
raise forms.ValidationError("Impossible d'archiver des utilisateurs dont la fin d'accès se situe dans le futur !")
|
||||
|
|
|
@ -223,7 +223,7 @@ class User(AbstractBaseUser):
|
|||
return date_max
|
||||
|
||||
def end_whitelist(self):
|
||||
""" Renvoie la date de fin de ban d'un user, False sinon """
|
||||
""" Renvoie la date de fin de whitelist d'un user, False sinon """
|
||||
date_max = Whitelist.objects.filter(user=self).aggregate(models.Max('date_end'))['date_end__max']
|
||||
return date_max
|
||||
|
||||
|
@ -252,6 +252,19 @@ class User(AbstractBaseUser):
|
|||
return self.state == User.STATE_ACTIVE \
|
||||
and not self.is_ban() and (self.is_adherent() or self.is_whitelisted())
|
||||
|
||||
def end_access(self):
|
||||
""" Renvoie la date de fin normale d'accès (adhésion ou whiteliste)"""
|
||||
if not self.end_adhesion():
|
||||
if not self.end_whitelist():
|
||||
return None
|
||||
else:
|
||||
return self.end_whitelist()
|
||||
else:
|
||||
if not self.end_whitelist():
|
||||
return self.end_adhesion()
|
||||
else:
|
||||
return max(self.end_adhesion(), self.end_whitelist())
|
||||
|
||||
def user_interfaces(self):
|
||||
return Interface.objects.filter(machine__in=Machine.objects.filter(user=self, active=True))
|
||||
|
||||
|
|
46
users/templates/users/mass_archive.html
Normal file
46
users/templates/users/mass_archive.html
Normal file
|
@ -0,0 +1,46 @@
|
|||
{% 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 %} Utilisateurs à archiver{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<form class="form" method="post">
|
||||
{% csrf_token %}
|
||||
{% bootstrap_form userform %}
|
||||
<input type="submit" name="chercher" value="Chercher" class="btn btn-primary" id="submit-id-submit">
|
||||
<input type="submit" name="valider" value="Valider définitivement" class="btn btn-primary" id="submit-id-submit">
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
<h3>Les utilisateurs suivant seront archivés ({{ to_archive_list|length }}):</h3>
|
||||
{% include "users/aff_users.html" with users_list=to_archive_list %}
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
{% endblock %}
|
||||
|
|
@ -55,6 +55,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<i class="glyphicon glyphicon-trash"></i>
|
||||
Retirer un droit
|
||||
</a>
|
||||
<a class="list-group-item list-group-item-danger" href="{% url "users:mass-archive" %}">
|
||||
<i class="glyphicon glyphicon-book"></i>
|
||||
Archiver en masse
|
||||
</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -49,6 +49,7 @@ urlpatterns = [
|
|||
url(r'^mon_profil/$', views.mon_profil, name='mon-profil'),
|
||||
url(r'^process/(?P<token>[a-z0-9]{32})/$', views.process, name='process'),
|
||||
url(r'^reset_password/$', views.reset_password, name='reset-password'),
|
||||
url(r'^mass_archive/$', views.mass_archive, name='mass-archive'),
|
||||
url(r'^history/(?P<object>user)/(?P<id>[0-9]+)$', views.history, name='history'),
|
||||
url(r'^history/(?P<object>ban)/(?P<id>[0-9]+)$', views.history, name='history'),
|
||||
url(r'^history/(?P<object>whitelist)/(?P<id>[0-9]+)$', views.history, name='history'),
|
||||
|
|
|
@ -43,7 +43,7 @@ from users.models import DelRightForm, BanForm, WhitelistForm, DelSchoolForm, De
|
|||
from users.models import EditInfoForm, InfoForm, BaseInfoForm, StateForm, RightForm, SchoolForm, ListRightForm
|
||||
from cotisations.models import Facture
|
||||
from machines.models import Machine, Interface
|
||||
from users.forms import PassForm, ResetPasswordForm
|
||||
from users.forms import MassArchiveForm, PassForm, ResetPasswordForm
|
||||
from machines.views import unassign_ips, assign_ips
|
||||
|
||||
from re2o.login import hashNT
|
||||
|
@ -455,6 +455,26 @@ def del_listright(request):
|
|||
return redirect("/users/index_listright/")
|
||||
return form({'userform': listright}, 'users/user.html', request)
|
||||
|
||||
@login_required
|
||||
@permission_required('bureau')
|
||||
def mass_archive(request):
|
||||
""" Permet l'archivage massif"""
|
||||
to_archive_date = MassArchiveForm(request.POST or None)
|
||||
to_archive_list = []
|
||||
if to_archive_date.is_valid():
|
||||
date = to_archive_date.cleaned_data['date']
|
||||
to_archive_list = [user for user in User.objects.exclude(state=User.STATE_ARCHIVE) if not user.end_access() or user.end_access() < date]
|
||||
if "valider" in request.POST:
|
||||
for user in to_archive_list:
|
||||
archive(user)
|
||||
with transaction.atomic(), reversion.create_revision():
|
||||
user.state=User.STATE_ARCHIVE
|
||||
user.save()
|
||||
reversion.set_comment("Archivage")
|
||||
messages.success(request, "%s users ont été archivés" % len(to_archive_list))
|
||||
return redirect("/users/")
|
||||
return form({'userform': to_archive_date, 'to_archive_list': to_archive_list}, 'users/mass_archive.html', request)
|
||||
|
||||
@login_required
|
||||
@permission_required('cableur')
|
||||
def index(request):
|
||||
|
|
Loading…
Reference in a new issue