From d13d442bbf474441306d3d3cdb269f82d5e0bd6c 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 | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 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..2fd8098 --- /dev/null +++ b/hobo/multitenant/log.py @@ -0,0 +1,28 @@ +# 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) + tenant = connection.get_tenant() + if isinstance(tenant, Tenant): + subject = '[%s] %s' % (tenant.domain_url, subject) + return subject -- 2.18.0