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 2020/01/10 20:58:21 UTC

[GitHub] [incubator-superset] villebro commented on a change in pull request #8699: [SIP-29] Add support for row-level security

villebro commented on a change in pull request #8699: [SIP-29] Add support for row-level security
URL: https://github.com/apache/incubator-superset/pull/8699#discussion_r365427526
 
 

 ##########
 File path: superset/security/manager.py
 ##########
 @@ -877,3 +878,39 @@ def assert_viz_permission(self, viz: "BaseViz") -> None:
         """
 
         self.assert_datasource_permission(viz.datasource)
+
+    def get_rls_filters(self, table):
+        """
+        Retrieves the appropriate row level security filters for the current user and the passed table.
+
+        :param table: The table to check against
+        :returns: A list of clause strings.
+        """
+        try:
+            roles = [role.id for role in g.user.roles]
+            return [
+                f.clause
+                for f in table.row_level_security_filters
+                if any(r.id in roles for r in f.roles)
+            ]
+        except AttributeError:
+            return []
+
+    def get_rls_ids(self, table) -> List[int]:
+        """
+        Retrieves the appropriate row level security filters IDs for the current user and the passed table.
+
+        :param table: The table to check against
+        :returns: A list of IDs.
+        """
+        try:
+            roles = [role.id for role in g.user.roles]
+            ids = [
+                f.id
+                for f in table.row_level_security_filters
+                if any(r.id in roles for r in f.roles)
+            ]
+            ids.sort()  # Combinations rather than permutations
+            return ids
+        except AttributeError:
 
 Review comment:
   I agree with @serenajiang here; best to be explicit about the attribute we`re after.

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


With regards,
Apache Git Services

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