From 14f798afec47c75ac6129d87cbfa04787261143b Mon Sep 17 00:00:00 2001 From: Beto Dealmeida Date: Thu, 23 Jan 2025 15:59:45 -0500 Subject: [PATCH] fix: proper URL building (#31962) --- superset/dashboards/permalink/api.py | 5 ++--- superset/explore/permalink/api.py | 5 ++--- superset/sqllab/permalink/api.py | 9 ++++----- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/superset/dashboards/permalink/api.py b/superset/dashboards/permalink/api.py index a6ae2910f42a1..208cda2a1f2e9 100644 --- a/superset/dashboards/permalink/api.py +++ b/superset/dashboards/permalink/api.py @@ -16,7 +16,7 @@ # under the License. import logging -from flask import request, Response +from flask import request, Response, url_for from flask_appbuilder.api import expose, protect, safe from marshmallow import ValidationError @@ -98,8 +98,7 @@ def post(self, pk: str) -> Response: dashboard_id=pk, state=state, ).run() - http_origin = request.headers.environ.get("HTTP_ORIGIN") - url = f"{http_origin}/superset/dashboard/p/{key}/" + url = url_for("Superset.dashboard_permalink", key=key, _external=True) return self.response(201, key=key, url=url) except (ValidationError, DashboardPermalinkInvalidStateError) as ex: return self.response(400, message=str(ex)) diff --git a/superset/explore/permalink/api.py b/superset/explore/permalink/api.py index bc9bd1cf67a21..a554225719580 100644 --- a/superset/explore/permalink/api.py +++ b/superset/explore/permalink/api.py @@ -16,7 +16,7 @@ # under the License. import logging -from flask import request, Response +from flask import request, Response, url_for from flask_appbuilder.api import expose, protect, safe from marshmallow import ValidationError @@ -95,8 +95,7 @@ def post(self) -> Response: try: state = self.add_model_schema.load(request.json) key = CreateExplorePermalinkCommand(state=state).run() - http_origin = request.headers.environ.get("HTTP_ORIGIN") - url = f"{http_origin}/superset/explore/p/{key}/" + url = url_for("ExplorePermalinkView.permalink", key=key, _external=True) return self.response(201, key=key, url=url) except ValidationError as ex: return self.response(400, message=ex.messages) diff --git a/superset/sqllab/permalink/api.py b/superset/sqllab/permalink/api.py index c86fb99a5edb3..35eae9f9062f1 100644 --- a/superset/sqllab/permalink/api.py +++ b/superset/sqllab/permalink/api.py @@ -16,7 +16,7 @@ # under the License. import logging -from flask import request, Response +from flask import request, Response, url_for from flask_appbuilder.api import expose, protect, safe from marshmallow import ValidationError @@ -87,8 +87,7 @@ def post(self) -> Response: try: state = self.add_model_schema.load(request.json) key = CreateSqlLabPermalinkCommand(state=state).run() - http_origin = request.headers.environ.get("HTTP_ORIGIN") - url = f"{http_origin}/sqllab/p/{key}" + url = url_for("SqllabView.root", key=key, _external=True) return self.response(201, key=key, url=url) except ValidationError as ex: return self.response(400, message=ex.messages) @@ -104,10 +103,10 @@ def post(self) -> Response: log_to_statsd=False, ) def get(self, key: str) -> Response: - """Get chart's permanent link state. + """Get permanent link state for SQLLab editor. --- get: - summary: Get chart's permanent link state + summary: Get permanent link state for SQLLab editor. parameters: - in: path schema: