From 9ec349cf666a73f9d8f32cd86995291da98f817a Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Fri, 19 Jul 2024 10:13:42 +0200 Subject: [PATCH] Fixed deploy command --- modoboa/core/checks.py | 34 +++++++++++++++++++++++--- modoboa/core/checks/__init__.py | 2 -- modoboa/core/checks/settings_checks.py | 26 -------------------- modoboa/core/utils.py | 3 ++- 4 files changed, 33 insertions(+), 32 deletions(-) delete mode 100644 modoboa/core/checks/__init__.py delete mode 100644 modoboa/core/checks/settings_checks.py diff --git a/modoboa/core/checks.py b/modoboa/core/checks.py index a4f0f5bf6..60237af77 100644 --- a/modoboa/core/checks.py +++ b/modoboa/core/checks.py @@ -1,10 +1,38 @@ -from django.core.checks import register, Info +from django.core.checks import register, Info, Warning from django.conf import settings +from django.utils.translation import gettext as _ from modoboa.core.utils import generate_rsa_private_key +W001 = Warning( + _( + "You have USE_TZ set to False, this may result in issues during " + "transitions between summer/winter time (ie the same local time occuring " + "twice due to clock change)." + ), + hint=_("Set `USE_TZ = True` in settings.py"), + id="modoboa.W001", +) + + @register(deploy=True) -def generate_rsa_private_key_check(app_configs, **kwargs): +def check_use_tz_enabled(app_configs, **kwargs): + """Ensure USE_TZ is enabled in settings.py + + When USE_TZ is enabled all date/times are stored in UTC. + Fixes #1086 - https://github.com/modoboa/modoboa/issues/1086 + """ + errors = [] + if not settings.USE_TZ: + errors.append(W001) + return errors + + +@register(deploy=True) +def check_rsa_private_key_exists(app_configs, **kwargs): + """ + Ensure an RSA private key exists to enable OIDC. + """ if generate_rsa_private_key(settings.BASE_DIR): - return Info("Generated the RSA key for OIDC.") + return Info("An RSA private key has been generated for OIDC.") diff --git a/modoboa/core/checks/__init__.py b/modoboa/core/checks/__init__.py deleted file mode 100644 index 9b716b17c..000000000 --- a/modoboa/core/checks/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -# Import these to force registration of checks -from . import settings_checks # NOQA:F401 diff --git a/modoboa/core/checks/settings_checks.py b/modoboa/core/checks/settings_checks.py deleted file mode 100644 index f72969226..000000000 --- a/modoboa/core/checks/settings_checks.py +++ /dev/null @@ -1,26 +0,0 @@ -from django.conf import settings -from django.core.checks import Warning, register -from django.utils.translation import gettext as _ - -W001 = Warning( - _( - "You have USE_TZ set to False, this may result in issues during " - "transitions between summer/winter time (ie the same local time occuring " - "twice due to clock change)." - ), - hint=_("Set `USE_TZ = True` in settings.py"), - id="modoboa.W001", -) - - -@register(deploy=True) -def check_use_tz_enabled(app_configs, **kwargs): - """Ensure USE_TZ is enabled in settings.py - - When USE_TZ is enabled all date/times are stored in UTC. - Fixes #1086 - https://github.com/modoboa/modoboa/issues/1086 - """ - errors = [] - if not settings.USE_TZ: - errors.append(W001) - return errors diff --git a/modoboa/core/utils.py b/modoboa/core/utils.py index 22e0371a3..f096b3d63 100644 --- a/modoboa/core/utils.py +++ b/modoboa/core/utils.py @@ -11,7 +11,6 @@ from django.utils.translation import gettext as _ from modoboa.core.extensions import exts_pool from modoboa.lib.api_client import ModoAPIClient -from . import models def parse_map_file(path): @@ -28,6 +27,8 @@ def parse_map_file(path): def check_for_updates(): """Check if a new version of Modoboa is available.""" + from . import models + local_config = models.LocalConfig.objects.first() client = ModoAPIClient() extensions = exts_pool.list_all()