From ca46b9ee8c71ab04aff9c185821e23e9d66fd742 Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Wed, 11 Jun 2025 14:35:58 +0200 Subject: [PATCH] Improved coverage --- doc/upgrade.rst | 48 +++++++++++++++++++ .../commands/subcommands/_repair.py | 11 ----- modoboa/autoreply/api/v2/tests.py | 17 +++++++ modoboa/autoreply/models.py | 41 +++++++--------- 4 files changed, 83 insertions(+), 34 deletions(-) diff --git a/doc/upgrade.rst b/doc/upgrade.rst index d269ac512..385e13315 100644 --- a/doc/upgrade.rst +++ b/doc/upgrade.rst @@ -148,6 +148,54 @@ Rebuild Virtual Environment Specific instructions ********************* +Version 2.4.0 +============= + +Legacy web interface has been removed and all extensions have been +integrated to the core Modoboa package. + +Pre update +---------- + +- If you are using Postegresql (default option with the installer), + run as a root user: + + .. sourcecode:: bash + + > sudo -u postgres -i psql -d "modoboa" -c "UPDATE django_content_type SET app_label='autoreply' WHERE app_label='postfix_autoreply'" + > sudo -u postgres -i psql -d "modoboa" -c "UPDATE django_migrations SET app='autoreply' WHERE app='postfix_autoreply'" + +- If you are using Mysql, run as a root user: + + .. sourcecode:: bash + + > echo "UPDATE django_content_type SET app_label='autoreply' WHERE app_label='postfix_autoreply'" | mysql -u root -p modoboa + > echo "UPDATE django_migrations SET app='autoreply' WHERE app='postfix_autoreply'" | mysql -u root -p modoboa + +Required changes to :file:`settings.py` +--------------------------------------- + +- Remove ``AjaxLoginRedirect`` from ``MIDDLEWARE`` variable: + + .. sourcecode:: python + + MIDDLEWARE = ( + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.locale.LocaleMiddleware', + 'x_forwarded_for.middleware.XForwardedForMiddleware', + 'corsheaders.middleware.CorsMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'modoboa.core.middleware.LocalConfigMiddleware', + 'modoboa.lib.middleware.CommonExceptionCatcher', + 'modoboa.lib.middleware.RequestCatcherMiddleware', + ) + + + Version 2.3.3 ============= diff --git a/modoboa/admin/management/commands/subcommands/_repair.py b/modoboa/admin/management/commands/subcommands/_repair.py index 90c42b91d..f17a54a50 100644 --- a/modoboa/admin/management/commands/subcommands/_repair.py +++ b/modoboa/admin/management/commands/subcommands/_repair.py @@ -4,8 +4,6 @@ from django.conf import settings from django.core.management.base import BaseCommand from django.utils.encoding import smart_str -from django.contrib.auth.models import Permission -from django.contrib.contenttypes.models import ContentType from modoboa.admin import models from modoboa.core.models import User @@ -90,15 +88,6 @@ def sometimes_mailbox_have_no_alias(**options): ) -@known_problem -def postfix_autoreply_old_contenttypes(**options): - """Sometime old postfix autoreply contenttypes might be present.""" - for ct in ContentType.objects.filter(app_label="postfix_autoreply"): - result = Permission.objects.filter(content_type=ct).delete() - ct.delete() - log(f"Removed content type {ct.name} and {result[0]} associated permssions") - - class Repair(BaseCommand): """Command class.""" diff --git a/modoboa/autoreply/api/v2/tests.py b/modoboa/autoreply/api/v2/tests.py index 4a9fb292f..127d921eb 100644 --- a/modoboa/autoreply/api/v2/tests.py +++ b/modoboa/autoreply/api/v2/tests.py @@ -22,6 +22,23 @@ class ARMessageViewSetTestCase(PatcherMixin, ModoAPITestCase): cls.arm = factories.ARmessageFactory(mbox=cls.account.mailbox) cls.arm2 = factories.ARmessageFactory(mbox=cls.account2.mailbox) + def test_update_global_settings(self): + data = { + "tracking_period": 7, + "default_subject": "Je suis parti", + "default_content": "Je reviendrai peut-ĂȘtre", + } + url = reverse("v2:parameter-global-detail", args=["autoreply"]) + resp = self.client.put(url, data, format="json") + self.assertEqual(resp.status_code, 200) + + data["tracking_period"] = 0 + resp = self.client.put(url, data, format="json") + self.assertEqual(resp.status_code, 400) + self.assertEqual( + resp.json()["tracking_period"][0], "Value can't be less than 1 day" + ) + def test_retrieve_armessage(self): url = reverse("api:armessage-list") response = self.client.get(url) diff --git a/modoboa/autoreply/models.py b/modoboa/autoreply/models.py index 2bf45ff8a..8a77cd753 100644 --- a/modoboa/autoreply/models.py +++ b/modoboa/autoreply/models.py @@ -35,30 +35,25 @@ class ARmessage(models.Model): def update_sieve_rule(self, request, fset): context = {"name": self.mbox.user.fullname} - if not self.fromdate: - condition = [("Subject", ":matches", "*")] - else: - days = request.localconfig.parameters.get_value("tracking_period") - context["fromdate"] = localize(self.fromdate) - fromdate = self.fromdate.isoformat() - fromdate, tz = fromdate.split("+") - tz = f"+{tz.replace(':', '')}" - condition = [ - ("currentdate", ":zone", tz, ":value", "ge", "iso8601", fromdate) - ] - if self.untildate: - context["untildate"] = localize(self.untildate) - condition.append( - ( - "currentdate", - ":zone", - tz, - ":value", - "lt", - "iso8601", - self.untildate.isoformat().split("+")[0], - ) + days = request.localconfig.parameters.get_value("tracking_period") + context["fromdate"] = localize(self.fromdate) + fromdate = self.fromdate.isoformat() + fromdate, tz = fromdate.split("+") + tz = f"+{tz.replace(':', '')}" + condition = [("currentdate", ":zone", tz, ":value", "ge", "iso8601", fromdate)] + if self.untildate: + context["untildate"] = localize(self.untildate) + condition.append( + ( + "currentdate", + ":zone", + tz, + ":value", + "lt", + "iso8601", + self.untildate.isoformat().split("+")[0], ) + ) content = self.content % context name = "autoreply" action = [("vacation", ":subject", self.subject, ":days", days, content)]