mistercrunch commented on code in PR #33924:
URL: https://github.com/apache/superset/pull/33924#discussion_r2180559875
##########
superset/jinja_context.py:
##########
@@ -284,6 +285,56 @@ def url_param(
self.cache_key_wrapper(result)
return result
+ def get_guest_user_attribute(
+ self,
+ attribute_name: str,
+ default: str | None = None,
+ add_to_cache_keys: bool = True,
+ ) -> str | None:
+ """
+ Get a specific user attribute from guest user.
+
+ Args:
+ attribute_name: Name of the attribute to retrieve
+ default: Default value if attribute not found
+ add_to_cache_keys: Whether the value should be included in the
cache key
+
+ Returns:
+ Attribute value or default
+ """
+
+ # Check if we have a request context and user
+ if not has_request_context():
+ return default
+
+ if not hasattr(g, "user") or g.user is None:
+ return default
+
+ user = g.user
+
+ # Check if current user is a guest user
+ if not (hasattr(user, "is_guest_user") and user.is_guest_user):
+ return default
+
+ # Get attributes from guest token
+ if hasattr(user, "guest_token") and user.guest_token:
+ token = user.guest_token
+ token_user = token.get("user", {})
+ user_attributes = token_user.get("attributes") or {}
+
+ # Only add to cache key if the variable actually exists in guest
token
+ if attribute_name in user_attributes:
+ result = user_attributes[attribute_name]
+ if add_to_cache_keys and result is not None:
+ self.cache_key_wrapper(
Review Comment:
just noting that I'm not familiar with `self.cache_key_wrapper` here, but
assuming it's session-scoped and called only once / properly flushed. Would be
great to confirm that there's nothing funky happening here if/when this macro
is called multiple times and such, and confirm it's cleaned between calls.
--
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]