diff --git a/modoboa/core/apps.py b/modoboa/core/apps.py index d676eb44a..a11d1d5c3 100644 --- a/modoboa/core/apps.py +++ b/modoboa/core/apps.py @@ -29,6 +29,8 @@ class CoreConfig(AppConfig): def ready(self): load_core_settings() + # Import these to force registration of checks and signals + from . import checks # noqa:F401 from . import handlers signals.post_migrate.connect(handlers.create_local_config, sender=self) diff --git a/modoboa/core/checks/__init__.py b/modoboa/core/checks/__init__.py new file mode 100644 index 000000000..95e25bed1 --- /dev/null +++ b/modoboa/core/checks/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +# 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 new file mode 100644 index 000000000..797b96538 --- /dev/null +++ b/modoboa/core/checks/settings_checks.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- + +from __future__ import unicode_literals + +from django.conf import settings +from django.core.checks import Warning, register +from django.utils.translation import ugettext 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/tests/test_checks.py b/modoboa/core/tests/test_checks.py new file mode 100644 index 000000000..124cf3930 --- /dev/null +++ b/modoboa/core/tests/test_checks.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- + +from __future__ import unicode_literals + +from django.test import SimpleTestCase +from django.test.utils import override_settings + +from ..checks import settings_checks + + +class CheckSessionCookieSecureTest(SimpleTestCase): + @override_settings(USE_TZ=False) + def test_use_tz_false(self): + """If USE_TZ is off provide one warning.""" + self.assertEqual( + settings_checks.check_use_tz_enabled(None), + [settings_checks.W001] + ) + + @override_settings(USE_TZ=True) + def test_use_tz_true(self): + """If USE_TZ is on, there's no warning about it.""" + self.assertEqual(settings_checks.check_use_tz_enabled(None), [])