Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make SQL-based alert email links user friendly #10519

Merged
merged 2 commits into from
Aug 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions superset/tasks/schedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,13 +580,15 @@ def deliver_alert(alert_id: int, recipients: Optional[str] = None) -> None:
"Superset.slice", slice_id=alert.slice.id, standalone="true"
)
screenshot = ChartScreenshot(chart_url, alert.slice.digest)
cache_key = screenshot.cache_key()
image_url = get_url_path(
Copy link
Contributor Author

@JasonD28 JasonD28 Aug 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"ChartRestApi.screenshot", pk=alert.slice.id, digest=cache_key
image_url = _get_url_path(
"Superset.slice",
user_friendly=True,
slice_id=alert.slice.id,
standalone="true",
)
standalone_index = chart_url.find("/?standalone=true")
standalone_index = image_url.find("/?standalone=true")
if standalone_index != -1:
image_url = chart_url[:standalone_index]
image_url = image_url[:standalone_index]

user = security_manager.find_user(current_app.config["THUMBNAIL_SELENIUM_USER"])
img_data = screenshot.compute_and_cache(
Expand All @@ -605,7 +607,7 @@ def deliver_alert(alert_id: int, recipients: Optional[str] = None) -> None:
images = {"screenshot": img_data}
body = render_template(
"email/alert.txt",
alert_url=get_url_path("AlertModelView.show", pk=alert.id),
alert_url=_get_url_path("AlertModelView.show", user_friendly=True, pk=alert.id),
label=alert.label,
sql=alert.sql,
image_url=image_url,
Expand Down