Skip to content

Commit

Permalink
fix: update standalone url for slack reports (apache#18756)
Browse files Browse the repository at this point in the history
* update url for slack reports

* fix test

* update text to be dynamic

(cherry picked from commit 5d2e726)
  • Loading branch information
hughhhh authored and rosemarie-chiu committed Feb 18, 2022
1 parent 91e3fe8 commit 37de381
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion superset/reports/notifications/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from superset.models.reports import ReportRecipientType
from superset.reports.notifications.base import BaseNotification
from superset.reports.notifications.exceptions import NotificationError
from superset.utils.urls import modify_url_query

logger = logging.getLogger(__name__)

Expand All @@ -47,6 +48,11 @@ def _get_channel(self) -> str:
return json.loads(self._recipient.recipient_config_json)["target"]

def _message_template(self, table: str = "") -> str:
url = (
modify_url_query(self._content.url, standalone="0")
if self._content.url is not None
else ""
)
return __(
"""*%(name)s*
Expand All @@ -58,7 +64,7 @@ def _message_template(self, table: str = "") -> str:
""",
name=self._content.name,
description=self._content.description or "",
url=self._content.url,
url=url,
table=table,
)

Expand Down
5 changes: 5 additions & 0 deletions tests/integration_tests/reports/commands_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,7 @@ def test_slack_chart_report_schedule(
notification_targets = get_target_from_report_schedule(
create_report_slack_chart
)

assert file_upload_mock.call_args[1]["channels"] == notification_targets[0]
assert file_upload_mock.call_args[1]["file"] == SCREENSHOT_FILE

Expand Down Expand Up @@ -1118,6 +1119,10 @@ def test_slack_chart_report_schedule_with_text(
| 0 | c11 | c12 | c13 |
| 1 | c21 | c22 | c23 |"""
assert table_markdown in post_message_mock.call_args[1]["text"]
assert (
f"<http://0.0.0.0:8080/superset/explore/?form_data=%7B%22slice_id%22%3A%20{create_report_slack_chart_with_text.chart.id}%7D&standalone=0&force=false|Explore in Superset>"
in post_message_mock.call_args[1]["text"]
)

# Assert logs are correct
assert_log(ReportState.SUCCESS)
Expand Down

0 comments on commit 37de381

Please sign in to comment.