mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-18 05:51:26 +02:00
Added ability to disable inactive accounts
This commit is contained in:
@@ -462,7 +462,7 @@ class GeneralParametersForm(param_forms.AdminParametersForm):
|
||||
initial=30,
|
||||
help_text=_(
|
||||
"An account with a last login date greater than this threshold "
|
||||
"(in days) will be considered as inactive"
|
||||
"(in days) will be considered as inactive. Disabled if the number is negative."
|
||||
),
|
||||
)
|
||||
|
||||
@@ -1076,7 +1076,8 @@ GLOBAL_PARAMETERS_STRUCT = collections.OrderedDict([
|
||||
"label": ugettext_lazy("Inactive account threshold"),
|
||||
"help_text": ugettext_lazy(
|
||||
"An account with a last login date greater than this "
|
||||
"threshold (in days) will be considered as inactive"
|
||||
"threshold (in days) will be considered as inactive. "
|
||||
"Disabled if the number is negative."
|
||||
)
|
||||
}),
|
||||
("top_notifications_check_interval", {
|
||||
|
||||
@@ -45,6 +45,8 @@ class Command(BaseCommand):
|
||||
"""Command entry point."""
|
||||
inactive_account_threshold = param_tools.get_global_parameter(
|
||||
"inactive_account_threshold")
|
||||
if inactive_account_threshold < 0:
|
||||
return
|
||||
qset = models.User.objects.filter(
|
||||
is_active=True, is_superuser=False,
|
||||
last_login__lt=timezone.now() -
|
||||
|
||||
@@ -11,7 +11,7 @@ from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
|
||||
from modoboa.lib.tests import ModoTestCase
|
||||
from modoboa.lib.tests import ModoTestCase, SimpleModoTestCase
|
||||
from .. import factories, mocks, models
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ class AuthenticationTestCase(ModoTestCase):
|
||||
self.assertTrue(response.url.endswith(reverse("core:dashboard")))
|
||||
|
||||
|
||||
class ManagementCommandsTestCase(TestCase):
|
||||
class ManagementCommandsTestCase(SimpleModoTestCase):
|
||||
"""Test management commands."""
|
||||
|
||||
def test_change_default_admin(self):
|
||||
@@ -84,6 +84,14 @@ class ManagementCommandsTestCase(TestCase):
|
||||
"clean_inactive_accounts", "--verbose", "--dry-run", stdout=out)
|
||||
self.assertIn("user1@domain.test", out.getvalue())
|
||||
|
||||
# Set a negative number (means disabled)
|
||||
self.set_global_parameter("inactive_account_threshold", -1)
|
||||
out = StringIO()
|
||||
management.call_command(
|
||||
"clean_inactive_accounts", "--verbose", "--dry-run", stdout=out)
|
||||
self.assertEqual("", out.getvalue())
|
||||
|
||||
self.set_global_parameter("inactive_account_threshold", 30)
|
||||
management.call_command("clean_inactive_accounts", "--silent")
|
||||
account.refresh_from_db()
|
||||
self.assertFalse(account.is_active)
|
||||
|
||||
@@ -51,6 +51,9 @@ class ParametersMixin(object):
|
||||
self.localconfig.parameters.set_values(parameters, app=app)
|
||||
self.localconfig.save()
|
||||
|
||||
class SimpleModoTestCase(ParametersMixin, TestCase):
|
||||
"""Simple class to add parameters editing."""
|
||||
|
||||
|
||||
class ModoTestCase(ParametersMixin, TestCase):
|
||||
"""All test cases must inherit from this one."""
|
||||
|
||||
Reference in New Issue
Block a user