bmaquet commented on code in PR #32770:
URL: https://github.com/apache/superset/pull/32770#discussion_r2007082861
##########
superset/jinja_context.py:
##########
@@ -172,6 +174,20 @@ def current_user_email(self, add_to_cache_keys: bool =
True) -> Optional[str]:
return email_address
return None
+ def current_user_roles(self, add_to_cache_keys: bool = True) -> str | None:
+ """
+ Return the roles of the user who is currently logged in.
+
+ :param add_to_cache_keys: Whether the value should be included in the
cache key
+ :returns: List of role names as a JSON string
+ """
+
+ if user_roles := get_user_roles():
+ if add_to_cache_keys:
+ self.cache_key_wrapper(json.dumps(user_roles))
Review Comment:
Updated the function to use `json_dumps()` to store the list of roles as
string into the cache.
The function still returns a python list, it's just the key for the cache
that is now a string.
When the query is run again, it's correctly fetching the results from the
cache
<img width="1506" alt="Screenshot 2025-03-21 at 09 26 35"
src="https://github.com/user-attachments/assets/f8e26e46-d39b-42f8-beb8-2a1d6bbd2f43"
/>
<img width="1508" alt="Screenshot 2025-03-21 at 09 26 44"
src="https://github.com/user-attachments/assets/9ef5ca53-f453-4450-b90b-52788e46383e"
/>
--
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]