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
This commit is contained in:
Sam Faber-Manning 2021-04-12 08:50:44 -07:00 committed by GitHub
parent bf22487e23
commit 778bb8e540
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 5 deletions

View File

@ -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:
"""

View File

@ -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")

View File

@ -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

View File

@ -68,9 +68,11 @@ class EmailNotification(BaseNotification): # pylint: disable=too-few-public-met
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,
)

View File

@ -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,
)