sfirke commented on code in PR #35345:
URL: https://github.com/apache/superset/pull/35345#discussion_r2392646031
##########
superset/views/utils.py:
##########
@@ -58,6 +59,33 @@
REJECTED_FORM_DATA_KEYS = ["js_tooltip", "js_onclick_href",
"js_data_mutator"]
+def redirect_to_login(next_target: str | None = None) -> FlaskResponse:
+ """Return a redirect response to the login view, preserving target URL.
+
+ When ``next_target`` is ``None`` the current request path (including query
+ string) is used, provided a request context is available. The resulting URL
+ always remains relative, mirroring Flask-AppBuilder expectations.
+ """
+
+ login_url = appbuilder.get_url_for_login
+ parsed = parse.urlparse(login_url)
+ query = parse.parse_qs(parsed.query, keep_blank_values=True)
+
+ target = next_target
+ if target is None and has_request_context():
+ if request.query_string:
+ target = request.full_path.rstrip("?")
+ else:
+ target = request.path
+
+ if target:
+ query["next"] = [target]
+
+ encoded_query = parse.urlencode(query, doseq=True)
+ redirect_url = parse.urlunparse(parsed._replace(query=encoded_query))
Review Comment:
I think `_replace` is just the canonical, documented way to do this. E.g.,
search for `_replace` here to find examples:
https://docs.python.org/3/library/urllib.parse.html.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]