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: [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]

Reply via email to