mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
Handle disabling by a flag
This commit is contained in:
@@ -133,6 +133,7 @@ export default {
|
||||
return params.filter(param => this.display(param))
|
||||
},
|
||||
save () {
|
||||
this.formErrors = {}
|
||||
parameters.saveApplication(this.$route.params.app, this.parameters).then(() => {
|
||||
bus.$emit('notification', { msg: this.$gettext('Parameters updated') })
|
||||
}).catch(error => {
|
||||
|
||||
@@ -159,6 +159,7 @@ class CoreGlobalParametersSerializer(serializers.Serializer):
|
||||
send_statistics = serializers.BooleanField(default=True)
|
||||
|
||||
# Misc settings
|
||||
enable_inactive_accounts = serializers.BooleanField(default=True)
|
||||
inactive_account_threshold = serializers.IntegerField(default=30)
|
||||
top_notifications_check_interval = serializers.IntegerField(default=30)
|
||||
log_maximum_age = serializers.IntegerField(default=365)
|
||||
|
||||
@@ -59,6 +59,7 @@ CORE_SETTINGS = {
|
||||
"send_new_versions_email": False,
|
||||
"new_versions_email_rcpt": "postmaster@yourdomain.test",
|
||||
"send_statistics": True,
|
||||
"enable_inactive_accounts": True,
|
||||
"inactive_account_threshold": 30,
|
||||
"top_notifications_check_interval": 30,
|
||||
"log_maximum_age": 365,
|
||||
|
||||
@@ -457,12 +457,19 @@ class GeneralParametersForm(param_forms.AdminParametersForm):
|
||||
|
||||
sep3 = SeparatorField(label=ugettext_lazy("Miscellaneous"))
|
||||
|
||||
enable_inactive_accounts = YesNoField(
|
||||
label=_("Enable inactive account tracking"),
|
||||
initial=True,
|
||||
help_text=_("Allow the administrator to set a threshold beyond which "
|
||||
"an account is considered inactive if the user hasn't logged.")
|
||||
)
|
||||
|
||||
inactive_account_threshold = forms.IntegerField(
|
||||
label=_("Inactive account threshold"),
|
||||
initial=30,
|
||||
help_text=_(
|
||||
"An account with a last login date greater than this threshold "
|
||||
"(in days) will be considered as inactive. Disabled if the number is negative."
|
||||
"(in days) will be considered as inactive."
|
||||
),
|
||||
)
|
||||
|
||||
@@ -520,6 +527,7 @@ class GeneralParametersForm(param_forms.AdminParametersForm):
|
||||
"send_new_versions_email": "check_new_versions=True",
|
||||
"new_versions_email_rcpt": "check_new_versions=True",
|
||||
"sms_provider": "sms_password_recovery=True",
|
||||
"inactive_account_threshold": "enable_inactive_accounts=True"
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
@@ -1072,12 +1080,19 @@ GLOBAL_PARAMETERS_STRUCT = collections.OrderedDict([
|
||||
("misc", {
|
||||
"label": ugettext_lazy("Miscellaneous"),
|
||||
"params": collections.OrderedDict([
|
||||
("enable_inactive_accounts", {
|
||||
"label": ugettext_lazy("Enable inactive account tracking"),
|
||||
"help_text": ugettext_lazy(
|
||||
"Allow the administrator to set a threshold beyond which "
|
||||
"an account is considered inactive if the user hasn't logged."
|
||||
),
|
||||
}),
|
||||
("inactive_account_threshold", {
|
||||
"label": ugettext_lazy("Inactive account threshold"),
|
||||
"display": "enable_inactive_accounts=true",
|
||||
"help_text": ugettext_lazy(
|
||||
"An account with a last login date greater than this "
|
||||
"threshold (in days) will be considered as inactive. "
|
||||
"Disabled if the number is negative."
|
||||
)
|
||||
}),
|
||||
("top_notifications_check_interval", {
|
||||
|
||||
@@ -43,10 +43,14 @@ class Command(BaseCommand):
|
||||
|
||||
def handle(self, *args, **options):
|
||||
"""Command entry point."""
|
||||
if not param_tools.get_global_parameter(
|
||||
"enable_inactive_accounts"):
|
||||
if options["verbose"]:
|
||||
print("Inactive accounts detection is disabled.",
|
||||
file=self.stdout)
|
||||
return
|
||||
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() -
|
||||
|
||||
@@ -84,14 +84,15 @@ class ManagementCommandsTestCase(SimpleModoTestCase):
|
||||
"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)
|
||||
# Disable account account threshold
|
||||
self.set_global_parameter("enable_inactive_accounts", False)
|
||||
out = StringIO()
|
||||
management.call_command(
|
||||
"clean_inactive_accounts", "--verbose", "--dry-run", stdout=out)
|
||||
self.assertEqual("", out.getvalue())
|
||||
"clean_inactive_accounts", "--verbose", stdout=out)
|
||||
self.assertIn("Inactive accounts detection is disabled.",
|
||||
out.getvalue())
|
||||
|
||||
self.set_global_parameter("inactive_account_threshold", 30)
|
||||
self.set_global_parameter("enable_inactive_accounts", True)
|
||||
management.call_command("clean_inactive_accounts", "--silent")
|
||||
account.refresh_from_db()
|
||||
self.assertFalse(account.is_active)
|
||||
|
||||
@@ -63,7 +63,7 @@ class Registry(object):
|
||||
result = [{"name": key, "label": value["label"]}
|
||||
for key, value in self._registry2[level].items()]
|
||||
return result
|
||||
|
||||
|
||||
def get_label(self, level, app):
|
||||
return self._registry2[level][app]["label"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user