diff --git a/users/forms.py b/users/forms.py index 2934ffed..1d39fad0 100644 --- a/users/forms.py +++ b/users/forms.py @@ -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 !") diff --git a/users/models.py b/users/models.py index 5069ac30..6b5f4082 100644 --- a/users/models.py +++ b/users/models.py @@ -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)) diff --git a/users/templates/users/mass_archive.html b/users/templates/users/mass_archive.html new file mode 100644 index 00000000..fad77631 --- /dev/null +++ b/users/templates/users/mass_archive.html @@ -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 %} +
+ + + +