From 778bb8e5404b3041cf3c6dfdefed6d206e10e0d7 Mon Sep 17 00:00:00 2001 From: Sam Faber-Manning Date: Mon, 12 Apr 2021 08:50:44 -0700 Subject: [PATCH] feat: add descriptions to report emails (#13827) * add description to report email * add report description to slack notification * fix issues caught by linter * fix long line * remove extra line * handle missing descriptions * run python black * properly run python black --- superset/reports/commands/execute.py | 7 ++++++- superset/reports/notifications/__init__.py | 4 ++-- superset/reports/notifications/base.py | 1 + superset/reports/notifications/email.py | 2 ++ superset/reports/notifications/slack.py | 10 ++++++++-- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/superset/reports/commands/execute.py b/superset/reports/commands/execute.py index 1e16c41880..8712532738 100644 --- a/superset/reports/commands/execute.py +++ b/superset/reports/commands/execute.py @@ -219,7 +219,12 @@ class BaseReportState: f"{self._report_schedule.name}: " f"{self._report_schedule.dashboard.dashboard_title}" ) - return NotificationContent(name=name, url=url, screenshot=screenshot_data) + return NotificationContent( + name=name, + url=url, + screenshot=screenshot_data, + description=self._report_schedule.description, + ) def _send(self, notification_content: NotificationContent) -> None: """ diff --git a/superset/reports/notifications/__init__.py b/superset/reports/notifications/__init__.py index 2553053131..dae43d64c7 100644 --- a/superset/reports/notifications/__init__.py +++ b/superset/reports/notifications/__init__.py @@ -22,7 +22,7 @@ from superset.reports.notifications.slack import SlackNotification def create_notification( - recipient: ReportRecipients, screenshot_data: NotificationContent + recipient: ReportRecipients, notification_content: NotificationContent ) -> BaseNotification: """ Notification polymorphic factory @@ -30,5 +30,5 @@ def create_notification( """ for plugin in BaseNotification.plugins: if plugin.type == recipient.type: - return plugin(recipient, screenshot_data) + return plugin(recipient, notification_content) raise Exception("Recipient type not supported") diff --git a/superset/reports/notifications/base.py b/superset/reports/notifications/base.py index 0cd8dba86a..60f5f0a0eb 100644 --- a/superset/reports/notifications/base.py +++ b/superset/reports/notifications/base.py @@ -27,6 +27,7 @@ class NotificationContent: url: Optional[str] = None # url to chart/dashboard for this screenshot screenshot: Optional[bytes] = None # bytes for the screenshot text: Optional[str] = None + description: Optional[str] = "" class BaseNotification: # pylint: disable=too-few-public-methods diff --git a/superset/reports/notifications/email.py b/superset/reports/notifications/email.py index a3adfbc7f4..09023f92d9 100644 --- a/superset/reports/notifications/email.py +++ b/superset/reports/notifications/email.py @@ -68,9 +68,11 @@ class EmailNotification(BaseNotification): # pylint: disable=too-few-public-met msgid = make_msgid(domain)[1:-1] body = __( """ +

%(description)s

Explore in Superset

""", + description=self._content.description or "", url=self._content.url, msgid=msgid, ) diff --git a/superset/reports/notifications/slack.py b/superset/reports/notifications/slack.py index ba857916da..97333dd773 100644 --- a/superset/reports/notifications/slack.py +++ b/superset/reports/notifications/slack.py @@ -44,25 +44,31 @@ class SlackNotification(BaseNotification): # pylint: disable=too-few-public-met return json.loads(self._recipient.recipient_config_json)["target"] @staticmethod - def _error_template(name: str, text: str) -> str: + def _error_template(name: str, description: str, text: str) -> str: return __( """ *%(name)s*\n + %(description)s\n Error: %(text)s """, name=name, + description=description, text=text, ) def _get_body(self) -> str: if self._content.text: - return self._error_template(self._content.name, self._content.text) + return self._error_template( + self._content.name, self._content.description or "", self._content.text + ) return __( """ *%(name)s*\n + %(description)s\n <%(url)s|Explore in Superset> """, name=self._content.name, + description=self._content.description or "", url=self._content.url, )