From d4380f866f6ef5344ba6bef3e9c861edf64113b1 Mon Sep 17 00:00:00 2001 From: Jean-Romain Garnier Date: Thu, 16 Apr 2020 23:14:19 +0200 Subject: [PATCH] Add option to select number of days before disabling users --- preferences/models.py | 6 ++++++ .../templates/preferences/display_preferences.html | 10 ++++++---- .../commands/disable_emailnotyetconfirmed.py | 9 +++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/preferences/models.py b/preferences/models.py index 8570e79b..e470303d 100644 --- a/preferences/models.py +++ b/preferences/models.py @@ -107,6 +107,12 @@ class OptionalUser(AclMixin, PreferencesModel): "Not yet active users will be deleted after this number of days." ), ) + disable_emailnotyetconfirmed = models.IntegerField( + default=2, + help_text=_( + "Users with an email address not yet confirmed will be disabled after this number of days." + ), + ) self_adhesion = models.BooleanField( default=False, help_text=_("A new user can create their account on Re2o.") ) diff --git a/preferences/templates/preferences/display_preferences.html b/preferences/templates/preferences/display_preferences.html index 89858ddc..6d7c656a 100644 --- a/preferences/templates/preferences/display_preferences.html +++ b/preferences/templates/preferences/display_preferences.html @@ -125,13 +125,15 @@ 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 directly entering a password during account creation" %} - {{ useroptions.allow_set_password_during_user_creation|tick }} - - {% trans "Allow archived users to log in" %} {{ useroptions.allow_archived_connexion|tick }} + + {% trans "Allow directly entering a password during account creation" %} + {{ useroptions.allow_set_password_during_user_creation|tick }} + {% trans "Disable email not yet confirmed users after" %} + {% blocktrans with disable_emailnotyetconfirmed=useroptions.disable_emailnotyetconfirmed %}{{ disable_emailnotyetconfirmed }} days{% endblocktrans %} +

{% trans "Users general permissions" %}

diff --git a/users/management/commands/disable_emailnotyetconfirmed.py b/users/management/commands/disable_emailnotyetconfirmed.py index 7c01f3fb..404b5004 100644 --- a/users/management/commands/disable_emailnotyetconfirmed.py +++ b/users/management/commands/disable_emailnotyetconfirmed.py @@ -27,16 +27,17 @@ from django.utils import timezone class Command(BaseCommand): - help = "Delete non members users (not yet active)." + help = "Disable users who haven't confirmed their email." def handle(self, *args, **options): """First deleting invalid invoices, and then deleting the users""" - days = OptionalUser.get_cached_value("delete_notyetactive") + days = OptionalUser.get_cached_value("disable_emailnotyetconfirmed") users_to_disable = ( User.objects.filter(state=User.STATE_EMAIL_NOT_YET_CONFIRMED) .filter(registered__lte=timezone.now() - timedelta(days=days)) .distinct() ) print("Disabling " + str(users_to_disable.count()) + " users.") - - users_to_disable.delete() + + for user in users_to_disable: + self.state = User.STATE_DISABLED