From 3f9d613c3da68e69afe5addf1aafc9c60265bd74 Mon Sep 17 00:00:00 2001 From: Hugo Levy-Falk Date: Mon, 9 Sep 2019 12:03:27 +0200 Subject: [PATCH] Fix #217 --- ...1_optionaluser_allow_archived_connexion.py | 20 +++++++++++++++++++ preferences/models.py | 4 ++++ .../preferences/display_preferences.html | 2 ++ users/models.py | 3 ++- 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 preferences/migrations/0061_optionaluser_allow_archived_connexion.py diff --git a/preferences/migrations/0061_optionaluser_allow_archived_connexion.py b/preferences/migrations/0061_optionaluser_allow_archived_connexion.py new file mode 100644 index 00000000..505f940b --- /dev/null +++ b/preferences/migrations/0061_optionaluser_allow_archived_connexion.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.23 on 2019-09-09 09:50 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('preferences', '0060_auto_20190712_1821'), + ] + + operations = [ + migrations.AddField( + model_name='optionaluser', + name='allow_archived_connexion', + field=models.BooleanField(default=False, help_text='If True, archived users are allowed to connect.'), + ), + ] diff --git a/preferences/models.py b/preferences/models.py index be8b8ec2..98374e77 100644 --- a/preferences/models.py +++ b/preferences/models.py @@ -123,6 +123,10 @@ class OptionalUser(AclMixin, PreferencesModel): help_text=_("If True, all new created and connected users are active." " If False, only when a valid registration has been paid.") ) + allow_archived_connexion = models.BooleanField( + default=False, + help_text=_("If True, archived users are allowed to connect.") + ) class Meta: permissions = ( diff --git a/preferences/templates/preferences/display_preferences.html b/preferences/templates/preferences/display_preferences.html index 3e71c817..626cb1a3 100644 --- a/preferences/templates/preferences/display_preferences.html +++ b/preferences/templates/preferences/display_preferences.html @@ -125,6 +125,8 @@ with this program; if not, write to the Free Software Foundation, Inc., {% trans "All users are active by default" %} {{ useroptions.all_users_active|tick }} + {% trans "Allow archived users to log-in" %} + {{ useroptions.allow_archived_connexion|tick }} diff --git a/users/models.py b/users/models.py index 68719e0f..6c19d873 100755 --- a/users/models.py +++ b/users/models.py @@ -333,7 +333,8 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, @property def is_active(self): """ Renvoie si l'user est à l'état actif""" - return self.state == self.STATE_ACTIVE or self.state == self.STATE_NOT_YET_ACTIVE + allow_archived = OptionalUser.get_cached_value('allow_archived_connexion') + return self.state == self.STATE_ACTIVE or self.state == self.STATE_NOT_YET_ACTIVE or (allow_archived and self.state in (self.STATE_ARCHIVE, self.STATE_FULL_ARCHIVE)) def set_active(self): """Enable this user if he subscribed successfully one time before