You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2021/02/10 09:42:00 UTC

[GitHub] [superset] amitmiran137 commented on a change in pull request #13035: feat(dashboard_rbac): add support for related roles

amitmiran137 commented on a change in pull request #13035:
URL: https://github.com/apache/superset/pull/13035#discussion_r573581033



##########
File path: superset/dashboards/filters.py
##########
@@ -138,3 +140,22 @@ def apply(self, query: Query, value: Any) -> Query:
         )
 
         return query
+
+
+class FilterRelatedRoles(BaseFilter):
+    """
+    A filter to allow searching for related roles of a resource.
+
+    Use in the api by adding something like:
+    related_field_filters = {
+      "roles": RelatedFieldFilter("name", FilterRelatedRoles),
+    }
+    """
+
+    name = _("Role")
+    arg_name = "roles"
+
+    def apply(self, query: Query, value: Optional[Any]) -> Query:
+        role_model = security_manager.role_model
+        like_value = "%" + cast(str, value) + "%"
+        return query.filter((role_model.name).ilike(like_value),)

Review comment:
       sure 
   adding tests also




----------------------------------------------------------------
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.

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