8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 11:23:10 +00:00

Add option to select number of days before disabling users

This commit is contained in:
Jean-Romain Garnier 2020-04-16 23:14:19 +02:00 committed by Jean-Romain Garnier
parent 91edc7ed31
commit d4380f866f
3 changed files with 17 additions and 8 deletions

View file

@ -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.")
)

View file

@ -125,13 +125,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<tr>
<th>{% trans "All users are active by default" %}</th>
<td>{{ useroptions.all_users_active|tick }}</td>
<th>{% trans "Allow directly entering a password during account creation" %}</th>
<td>{{ useroptions.allow_set_password_during_user_creation|tick }}</td>
</tr>
<tr>
<th>{% trans "Allow archived users to log in" %}</th>
<td>{{ useroptions.allow_archived_connexion|tick }}</td>
</tr>
<tr>
<th>{% trans "Allow directly entering a password during account creation" %}</th>
<td>{{ useroptions.allow_set_password_during_user_creation|tick }}</td>
<th>{% trans "Disable email not yet confirmed users after" %}</th>
<td>{% blocktrans with disable_emailnotyetconfirmed=useroptions.disable_emailnotyetconfirmed %}{{ disable_emailnotyetconfirmed }} days{% endblocktrans %}</td>
</tr>
</table>
<h4 id="users">{% trans "Users general permissions" %}</h4>

View file

@ -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