From 8365058b0e9e32ab95e5b6c28dd4204ff2c0608b Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Wed, 10 Sep 2025 17:22:53 +0200 Subject: [PATCH] Fixed deployment when amavis is enabled --- doc/conf.py | 8 ++----- modoboa/core/commands/deploy.py | 3 +++ .../core/commands/templates/settings.py.tpl | 23 ++++++++++--------- test_project/test_project/settings.py | 2 +- tests.py | 1 - 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index daba668f3..95faaa883 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -61,9 +61,9 @@ copyright = "2025, Antoine Nguyen" # NOQA:A001 # built documents. # # The short X.Y version. -version = "2.4.0" +version = "2.5.0" # The full version, including alpha/beta/rc tags. -release = "2.4.0" +release = "2.5.0" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -224,7 +224,3 @@ latex_documents = [ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [("index", "modoboa", "Modoboa Documentation", ["Antoine Nguyen"], 1)] - -intersphinx_mapping = { - "amavis": ("http://modoboa-amavis.readthedocs.org/en/latest/", None) -} diff --git a/modoboa/core/commands/deploy.py b/modoboa/core/commands/deploy.py index 97e49a0a3..57b662214 100644 --- a/modoboa/core/commands/deploy.py +++ b/modoboa/core/commands/deploy.py @@ -218,6 +218,7 @@ class DeployCommand(Command): allowed_host = "localhost" extra_settings = [] extensions = parsed_args.extensions + amavis_enabled = False if extensions: if "all" in extensions: extensions = self._get_extension_list() @@ -233,6 +234,7 @@ class DeployCommand(Command): exec_cmd(cmd, capture_output=False) extra_settings = self.find_extra_settings(extensions) extensions = [extension[1] for extension in extensions] + amavis_enabled = "modoboa.amavis" in extensions mod = __import__(parsed_args.name, globals(), locals(), [smart_str("settings")]) tpl = self._render_template( @@ -247,6 +249,7 @@ class DeployCommand(Command): "devmode": parsed_args.devel, "extensions": extensions, "extra_settings": extra_settings, + "amavis_enabled": amavis_enabled, }, ) with open(f"{path}/settings.py", "w") as fp: diff --git a/modoboa/core/commands/templates/settings.py.tpl b/modoboa/core/commands/templates/settings.py.tpl index 0f57978d4..84f5cf847 100644 --- a/modoboa/core/commands/templates/settings.py.tpl +++ b/modoboa/core/commands/templates/settings.py.tpl @@ -2,10 +2,10 @@ Django settings for {{ name }} project. For more information on this file, see -https://docs.djangoproject.com/en/4.2/topics/settings/ +https://docs.djangoproject.com/en/dev/topics/settings/ For the full list of settings and their values, see -https://docs.djangoproject.com/en/2.2/ref/settings/ +https://docs.djangoproject.com/en/dev/ref/settings/ """ from logging.handlers import SysLogHandler @@ -17,9 +17,6 @@ env = environ.Env() BASE_DIR = os.path.realpath(os.path.dirname(os.path.dirname(__file__))) environ.Env.read_env(os.path.join(BASE_DIR, '.env')) -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ - # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = '{{ secret_key }}' @@ -157,14 +154,14 @@ WSGI_APPLICATION = '{{ name }}.wsgi.application' # Database -# https://docs.djangoproject.com/en/4.2/ref/settings/#databases +# https://docs.djangoproject.com/en/dev/ref/settings/#databases DATABASES = { {% for conn in db_connections.values %}{{ conn|safe }}{% endfor %} } # Internationalization -# https://docs.djangoproject.com/en/4.2/topics/i18n/ +# https://docs.djangoproject.com/en/dev/topics/i18n/ LANGUAGE_CODE = '{{ lang }}' @@ -177,12 +174,12 @@ USE_L10N = True USE_TZ = True # Default primary key field type -# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field +# https://docs.djangoproject.com/en/dev/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.AutoField' # Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/2.2/howto/static-files/ +# https://docs.djangoproject.com/en/dev/howto/static-files/ STATIC_URL = '/sitestatic/' STATIC_ROOT = os.path.join(BASE_DIR, 'sitestatic') @@ -295,7 +292,7 @@ CACHES = { # Password validation -# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators +# https://docs.djangoproject.com/en/dev/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { @@ -384,7 +381,11 @@ SILENCED_SYSTEM_CHECKS = [ ] PHONENUMBER_DB_FORMAT = 'INTERNATIONAL' - +{% if amavis_enabled %} +# Amavis settings +DATABASE_ROUTERS = ["modoboa.amavis.dbrouter.AmavisRouter"] +AMAVIS_DEFAULT_DATABASE_ENCODING = "LATIN1" # or any value matching your database config +{% endif %} # Load settings from extensions {% for extension in extra_settings %} try: diff --git a/test_project/test_project/settings.py b/test_project/test_project/settings.py index 24d83cd5b..96087f2e4 100644 --- a/test_project/test_project/settings.py +++ b/test_project/test_project/settings.py @@ -104,7 +104,7 @@ MODOBOA_APPS = ( "modoboa.contacts", "modoboa.calendars", "modoboa.webmail", - "modoboa.amavis", + # "modoboa.amavis", ) try: diff --git a/tests.py b/tests.py index 3d10f317c..36a9512bb 100644 --- a/tests.py +++ b/tests.py @@ -31,7 +31,6 @@ class DeployTest(unittest.TestCase): f"--dburl {dburl} --domain localhost --admin-username admin {self.projname}" ) code, output = exec_cmd(cmd, cwd=self.workdir) - print(output) self.assertEqual(code, 0)