bmaquet commented on code in PR #32770:
URL: https://github.com/apache/superset/pull/32770#discussion_r2006503865
##########
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:
I see your point now.
I believe we also could leverage jinja's `|tojson` to render the list as a
json (this would remove the need for another `json_dump()` macro).
To re-use your example, this would work:
<img width="658" alt="Screenshot 2025-03-20 at 22 42 25"
src="https://github.com/user-attachments/assets/958fd362-e614-4411-b652-f9132d28d977"
/>
The issue I'm struggling with now though, is that a python list can't be
used as a key for a python dict, so this line
`self.cache_key_wrapper(user_roles)` wouldn't work.
--
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]