From b1d15769647dc22a70ee582f52c4e59ba953e5a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sun, 19 Aug 2018 14:55:03 +0200 Subject: [PATCH] multitenant: include tenant domain in logging emails (#25715) --- debian/debian_config_common.py | 2 +- hobo/multitenant/log.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 hobo/multitenant/log.py diff --git a/debian/debian_config_common.py b/debian/debian_config_common.py index 27fcfd6..8c84003 100644 --- a/debian/debian_config_common.py +++ b/debian/debian_config_common.py @@ -69,7 +69,7 @@ LOGGING = { }, 'mail_admins': { 'level': 'ERROR', - 'class': 'django.utils.log.AdminEmailHandler', + 'class': 'hobo.multitenant.log.AdminEmailHandler', 'include_html': True, }, 'sentry': { diff --git a/hobo/multitenant/log.py b/hobo/multitenant/log.py new file mode 100644 index 0000000..0bead33 --- /dev/null +++ b/hobo/multitenant/log.py @@ -0,0 +1,29 @@ +# hobo - portal to configure and deploy applications +# Copyright (C) 2015-2018 Entr'ouvert +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from django.db import connection +import django.utils.log + + +class AdminEmailHandler(django.utils.log.AdminEmailHandler): + def format_subject(self, subject): + from .models import Tenant + subject = super(AdminEmailHandler, self).format_subject(subject) + try: + subject = '[%s] %s' % (connection.get_tenant().domain_url, subject) + except AttributeError: + pass + return subject -- 2.18.0