diff --git a/modoboa/core/app_settings.py b/modoboa/core/app_settings.py index 7b4aaeee1..656b0ffbd 100644 --- a/modoboa/core/app_settings.py +++ b/modoboa/core/app_settings.py @@ -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", { diff --git a/modoboa/core/management/commands/clean_inactive_accounts.py b/modoboa/core/management/commands/clean_inactive_accounts.py index eb5e58778..23cd06e3a 100644 --- a/modoboa/core/management/commands/clean_inactive_accounts.py +++ b/modoboa/core/management/commands/clean_inactive_accounts.py @@ -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() - diff --git a/modoboa/core/tests/test_core.py b/modoboa/core/tests/test_core.py index b0b476bc2..a738918d5 100644 --- a/modoboa/core/tests/test_core.py +++ b/modoboa/core/tests/test_core.py @@ -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) diff --git a/modoboa/lib/tests/__init__.py b/modoboa/lib/tests/__init__.py index 608197a41..06cc1862f 100644 --- a/modoboa/lib/tests/__init__.py +++ b/modoboa/lib/tests/__init__.py @@ -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."""