rusackas commented on code in PR #44857:
URL: https://github.com/apache/superset/pull/44857#discussion_r4172303861


##########
superset/security/password_change.py:
##########
@@ -170,6 +171,55 @@ def _is_exempt_endpoint(endpoint: Optional[str]) -> bool:
     return view_class in _EXEMPT_VIEW_CLASSES
 
 
+def _profile_page_reachable(security_manager: Any) -> bool:
+    """Return whether the current user can reach ``UserInfoView.list``.
+
+    It requires ``can_read`` on ``user``, which ``sync_role_definitions`` only
+    grants to the built-in Admin/Alpha/Gamma roles -- a custom role is never
+    guaranteed to hold it. A user without it who gets redirected there hits
+    FAB's own access-denied redirect (to login), which, since they're already
+    authenticated, bounces straight back to the index -- which re-runs this
+    hook and redirects to the profile page again, looping forever.
+    """
+    return security_manager is not None and bool(
+        security_manager.has_access("can_read", "user")
+    )
+
+
+def _logout_fallback_candidates(security_manager: Any) -> list[str]:
+    """Build the ordered list of logout endpoints to try as a last resort."""
+    candidates = []
+    auth_view = getattr(security_manager, "auth_view", None)
+    # Only redirect to the registered auth view's logout if that view is
+    # itself exempt from this hook; otherwise the redirect would loop.
+    if (
+        auth_view is not None
+        and getattr(auth_view, "endpoint", None) in _EXEMPT_VIEW_CLASSES
+    ):
+        candidates.append(f"{auth_view.endpoint}.logout")
+    candidates.append("AuthDBView.logout")
+    return candidates
+
+
+def _flash_no_profile_access() -> Optional[tuple[str, int]]:
+    """Explain that the user's role cannot reach the profile page.
+
+    Under ``AUTH_REMOTE_USER`` a logout redirect cannot help: the unchanged
+    REMOTE_USER header re-authenticates the user immediately and the request
+    loops. In that case return a terminal ``(body, status)`` response for the
+    caller to return; otherwise flash the message and return ``None``.
+    """
+    message = __(
+        "Your role does not have access to the profile page "
+        "needed to change your password. Contact an "
+        "administrator."
+    )
+    if current_app.config.get("AUTH_TYPE") == AUTH_REMOTE_USER:

Review Comment:
   Good catch. The "must change your password" flash is now only queued when 
the profile page is reachable, so the no-access case flashes just the 
explanatory message. Pushed in e0f280ce35.



-- 
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]

Reply via email to