From 033d874b7b80a0bd0e632885d024e190c0b8ce28 Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Tue, 31 Jan 2023 10:33:51 +0100 Subject: [PATCH 1/4] Updated documentation --- doc/upgrade.rst | 24 +++++++++++++++++-- .../core/commands/templates/settings.py.tpl | 3 ++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/doc/upgrade.rst b/doc/upgrade.rst index 6433b3b80..4762e58fe 100644 --- a/doc/upgrade.rst +++ b/doc/upgrade.rst @@ -94,6 +94,8 @@ Specific instructions 2.0.4 ===== +The following modifications must be applied to the :file:`settings.py` file: + * Add ``'modoboa.core.context_processors.new_admin_url',`` at the end of `context_processors` list: .. sourcecode:: python @@ -121,9 +123,27 @@ Specific instructions }, ] +* Add the following variable:: -* You now have the possibility to customize the url of the new-admin interface. -To do so please head up to :ref:`the custom configuration chapter ` (advanced user). +.. sourcecode:: python + + PID_FILE_STORAGE_PATH = '/var/run' + +* Update ``LOGGING`` variable to define an address for ``syslog-auth`` handler:: + +.. sourcecode:: python + + 'syslog-auth': { + 'class': 'logging.handlers.SysLogHandler', + 'facility': SysLogHandler.LOG_AUTH, + 'formatter': 'syslog', + 'address': '/dev/log' + }, + + +You now have the possibility to customize the url of the new-admin +interface. To do so please head up to :ref:`the custom configuration +chapter ` (advanced user). 2.0.3 diff --git a/modoboa/core/commands/templates/settings.py.tpl b/modoboa/core/commands/templates/settings.py.tpl index d9455bcbf..23ec4f89b 100644 --- a/modoboa/core/commands/templates/settings.py.tpl +++ b/modoboa/core/commands/templates/settings.py.tpl @@ -320,7 +320,8 @@ LOGGING = { 'syslog-auth': { 'class': 'logging.handlers.SysLogHandler', 'facility': SysLogHandler.LOG_AUTH, - 'formatter': 'syslog' + 'formatter': 'syslog', + 'address': '/dev/log' }, 'syslog-mail': { 'class': 'logging.handlers.SysLogHandler', From ba8f3c5ec6280c0ea3cacedbb5245438a2810904 Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Wed, 1 Feb 2023 13:53:17 +0100 Subject: [PATCH 2/4] fixed typo. fix #2765 --- modoboa/admin/static/admin/js/admin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modoboa/admin/static/admin/js/admin.js b/modoboa/admin/static/admin/js/admin.js index c18f78299..7791688a9 100644 --- a/modoboa/admin/static/admin/js/admin.js +++ b/modoboa/admin/static/admin/js/admin.js @@ -172,7 +172,7 @@ Domains.prototype = { if (this.navobj.getbaseurl() === "list") { args.objtype = "domain"; this.options.eor_message = gettext("No more domain to show"); - } else if (this.navobj.getbaseurl() === "quota") { + } else if (this.navobj.getbaseurl() === "quotas") { args.objtype = "quota"; this.options.eor_message = gettext("No more quota to show"); } else { From cdcfb8e9791a629de92d64e2e5e891a64b796a01 Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Wed, 1 Feb 2023 15:45:15 +0100 Subject: [PATCH 3/4] Improved error messages see #2772 --- modoboa/admin/models/domain.py | 16 ++++++++-------- modoboa/admin/models/mailbox.py | 4 +++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/modoboa/admin/models/domain.py b/modoboa/admin/models/domain.py index 66bb412a5..8b8fc0a1b 100644 --- a/modoboa/admin/models/domain.py +++ b/modoboa/admin/models/domain.py @@ -74,7 +74,7 @@ class Domain(mixins.MessageLimitMixin, AdminObject): def __init__(self, *args, **kwargs): """Save name for further use.""" - super(Domain, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self.old_mail_homes = None self.oldname = self.name self.old_dkim_key_length = self.dkim_key_length @@ -320,7 +320,7 @@ class Domain(mixins.MessageLimitMixin, AdminObject): if self.old_dkim_key_length != self.dkim_key_length: self.dkim_public_key = "" self.dkim_private_key_path = "" - super(Domain, self).save(*args, **kwargs) + super().save(*args, **kwargs) def delete(self, fromuser, keepdir=False): """Custom delete method.""" @@ -336,7 +336,7 @@ class Domain(mixins.MessageLimitMixin, AdminObject): elif self.mailbox_set.count(): Quota.objects.filter(username__contains="@%s" % self.name).delete() ungrant_access_to_objects(self.mailbox_set.all()) - super(Domain, self).delete() + super().delete() def __str__(self): return smart_text(self.name) @@ -364,27 +364,27 @@ class Domain(mixins.MessageLimitMixin, AdminObject): if domains_must_have_authorized_mx and not user.is_superuser: if not lib.domain_has_authorized_mx(self.name): raise BadRequest( - _("No authorized MX record found for domain {}") + _("{}: no authorized MX record found for domain") .format(self.name) ) try: self.quota = int(row[2].strip()) except ValueError: raise BadRequest( - _("Invalid quota value for domain '{}'") + _("{}: invalid quota value for domain") .format(self.name) ) try: self.default_mailbox_quota = int(row[3].strip()) except ValueError: raise BadRequest( - _("Invalid default mailbox quota value for domain '{}'") + _("{}: invalid default mailbox quota value for domain") .format(self.name) ) if self.quota != 0 and self.default_mailbox_quota > self.quota: raise BadRequest( - _("Default mailbox quota cannot be greater than domain " - "quota") + _("{}: default mailbox quota cannot be greater than domain " + "quota").format(self.name) ) self.enabled = (row[4].strip().lower() in ["true", "1", "yes", "y"]) core_signals.can_create_object.send( diff --git a/modoboa/admin/models/mailbox.py b/modoboa/admin/models/mailbox.py index 0eda0fef9..4f0021429 100644 --- a/modoboa/admin/models/mailbox.py +++ b/modoboa/admin/models/mailbox.py @@ -257,7 +257,9 @@ class Mailbox(mixins.MessageLimitMixin, AdminObject): if old_quota: quota_usage -= old_quota if quota_usage + self.quota > self.domain.quota: - raise lib_exceptions.BadRequest(_("Domain quota exceeded")) + raise lib_exceptions.BadRequest( + _("{}: domain quota exceeded").format(self.domain.name) + ) def get_quota(self): """Get quota limit. From f7d3439e60bf130c8825c260bf6914c4f29ac750 Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Wed, 1 Feb 2023 18:51:30 +0100 Subject: [PATCH 4/4] Fixed tests --- modoboa/admin/tests/test_import_.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/modoboa/admin/tests/test_import_.py b/modoboa/admin/tests/test_import_.py index 6c4ab117e..3494f5a86 100644 --- a/modoboa/admin/tests/test_import_.py +++ b/modoboa/admin/tests/test_import_.py @@ -66,17 +66,18 @@ domainalias; domalias1.com; domain1.com; True f = ContentFile("domain; domain1.com; XX; 100; True", name="domains.csv") response = self.client.post(url, {"sourcefile": f}) - self.assertContains(response, "Invalid quota value") + self.assertContains(response, "domain1.com: invalid quota value") f = ContentFile("domain; domain1.com; 100; XX; True", name="domains.csv") response = self.client.post(url, {"sourcefile": f}) - self.assertContains(response, "Invalid default mailbox quota") + self.assertContains( + response, "domain1.com: invalid default mailbox quota") f = ContentFile("domain; domain1.com; 10; 100; True", name="domains.csv") response = self.client.post(url, {"sourcefile": f}) self.assertContains( response, - "Default mailbox quota cannot be greater than domain quota") + "domain1.com: default mailbox quota cannot be greater than domain quota") @mock.patch.object(dns.resolver.Resolver, "resolve") @mock.patch("socket.getaddrinfo") @@ -97,7 +98,8 @@ domainalias; domalias1.com; domain1.com; True "sourcefile": f } ) - self.assertContains(resp, "No authorized MX record found for domain") + self.assertContains( + resp, "test3.com: no authorized MX record found for domain") mock_getaddrinfo.side_effect = utils.mock_ip_query_result f = ContentFile( @@ -253,7 +255,7 @@ account; user1@test.com; toto; User; One; True; SimpleUsers; user1@test.com; 40 reverse("admin:identity_import"), {"sourcefile": f, "crypt_password": True} ) - self.assertIn("Domain quota exceeded", resp.content.decode()) + self.assertIn("test.com: domain quota exceeded", resp.content.decode()) def test_import_missing_quota(self): f = ContentFile(b"""