mirror of
https://github.com/apache/superset.git
synced 2026-04-26 03:24:53 +00:00
refactor: Cleanup user get_id/get_user_id (#20492)
Co-authored-by: John Bodley <john.bodley@airbnb.com>
This commit is contained in:
@@ -1422,13 +1422,36 @@ def split_adhoc_filters_into_base_filters( # pylint: disable=invalid-name
|
||||
|
||||
|
||||
def get_username() -> Optional[str]:
|
||||
"""Get username if within the flask context, otherwise return noffin'"""
|
||||
"""
|
||||
Get username (if defined) associated with the current user.
|
||||
|
||||
:returns: The username
|
||||
"""
|
||||
|
||||
try:
|
||||
return g.user.username
|
||||
except Exception: # pylint: disable=broad-except
|
||||
return None
|
||||
|
||||
|
||||
def get_user_id() -> Optional[int]:
|
||||
"""
|
||||
Get the user identifier (if defined) associated with the current user.
|
||||
|
||||
Though the Flask-AppBuilder `User` and Flask-Login `AnonymousUserMixin` and
|
||||
`UserMixin` models provide a convenience `get_id` method, for generality, the
|
||||
identifier is encoded as a `str` whereas in Superset all identifiers are encoded as
|
||||
an `int`.
|
||||
|
||||
returns: The user identifier
|
||||
"""
|
||||
|
||||
try:
|
||||
return g.user.id
|
||||
except Exception: # pylint: disable=broad-except
|
||||
return None
|
||||
|
||||
|
||||
@contextmanager
|
||||
def override_user(user: Optional[User]) -> Iterator[Any]:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user