Skip to content

Commit

Permalink
fix: proper URL building (apache#31962)
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida authored Jan 23, 2025
1 parent 6d117ff commit 14f798a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
5 changes: 2 additions & 3 deletions superset/dashboards/permalink/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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))
Expand Down
5 changes: 2 additions & 3 deletions superset/explore/permalink/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions superset/sqllab/permalink/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down

0 comments on commit 14f798a

Please sign in to comment.