You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "Yash2412 (via GitHub)" <gi...@apache.org> on 2025/06/26 06:23:37 UTC

[I] Add a user_attributes field to the GuestTokenUser and GuestUser classes in Apache Superset. This enhancement will enable the use of user-specific attributes when embedding charts, allowing for more granular control and filtering of query results based on these attributes. [superset]

Yash2412 opened a new issue, #33919:
URL: https://github.com/apache/superset/issues/33919

   Add a user_attributes field to the GuestTokenUser and GuestUser classes in Apache Superset. This enhancement will enable the use of user-specific attributes when embedding charts, allowing for more granular control and filtering of query results based on these attributes.
   Currently, when embedding charts in Superset, the ability to filter data based on user-specific attributes is limited.Only through rls we can do that. By introducing a user_attributes field, we can leverage this information to dynamically adjust the query results according to the specific attributes of the user, enhancing the overall flexibility 
   Example:
   ```
   class GuestTokenUser(TypedDict, total=False):
       username: str
       first_name: str
       last_name: str
       user_attributes: Dict[str, Any]  # Adding the user attributes dictionary
   class GuestUser(AnonymousUserMixin):
       def __init__(self, token: GuestToken, roles: list[Role]):
           user = token["user"]
           self.guest_token = token
           self.username = user.get("username", "guest_user")
           self.first_name = user.get("first_name", "Guest")
           self.last_name = user.get("last_name", "User")
           self.user_attributes= user.get("user_attributes",{})
           self.roles = roles
           self.resources = token["resources"]
           self.rls = token.get("rls_rules", [])
   
   class UserSchema(PermissiveSchema):
       username = fields.String()
       first_name = fields.String()
       last_name = fields.String()
       user_attributes = fields.Dict(keys=fields.Str(), values=fields.Raw(), required=False)
   
   
   def get_territories():
       user = g.user
       if user is not None and hasattr(user, "user_attributes"): 
           return user.user_attributes['territaries']
       return []
   
   JINJA_CONTEXT_ADDONS = {
       'territories': get_territories
   }
   ```
   While generating guest_token we can pass user_attributes in user field and use them by adding JINJA ContextAdds ON
   
   In Query i can use territories or similar function which increases the flexibility with regarding roles and rights of parent application while embedding using iframe
   .
   
   _Originally posted by @saichandu3397 in https://github.com/apache/superset/discussions/29696_


-- 
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: notifications-unsubscribe@superset.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [I] feat: add `user_attributes` support to guest tokens for embedded dashboards [superset]

Posted by "Yash2412 (via GitHub)" <gi...@apache.org>.
Yash2412 closed issue #33919: feat: add `user_attributes` support to guest tokens for embedded dashboards
URL: https://github.com/apache/superset/issues/33919


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org