Skip to content

Commit

Permalink
feat: add descriptions to report emails (apache#13827)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
samtfm authored and Allan Caetano de Oliveira committed May 21, 2021
1 parent d30f17b commit 2b37aec
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
7 changes: 6 additions & 1 deletion superset/reports/commands/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,12 @@ def _get_notification_content(self) -> NotificationContent:
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:
"""
Expand Down
4 changes: 2 additions & 2 deletions superset/reports/notifications/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@


def create_notification(
recipient: ReportRecipients, screenshot_data: NotificationContent
recipient: ReportRecipients, notification_content: NotificationContent
) -> BaseNotification:
"""
Notification polymorphic factory
Returns the Notification class for the recipient type
"""
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")
1 change: 1 addition & 0 deletions superset/reports/notifications/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions superset/reports/notifications/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ def _get_content(self) -> EmailContent:
msgid = make_msgid(domain)[1:-1]
body = __(
"""
<p>%(description)s</p>
<b><a href="%(url)s">Explore in Superset</a></b><p></p>
<img src="cid:%(msgid)s">
""",
description=self._content.description or "",
url=self._content.url,
msgid=msgid,
)
Expand Down
10 changes: 8 additions & 2 deletions superset/reports/notifications/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,31 @@ def _get_channel(self) -> str:
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,
)

Expand Down

0 comments on commit 2b37aec

Please sign in to comment.