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 2019/09/14 04:51:45 UTC

[GitHub] [incubator-superset] bkyryliuk commented on a change in pull request #8219: [WIP] Build better support for schema permissions

bkyryliuk commented on a change in pull request #8219: [WIP] Build better support for schema permissions
URL: https://github.com/apache/incubator-superset/pull/8219#discussion_r324412268
 
 

 ##########
 File path: superset/security.py
 ##########
 @@ -736,47 +771,67 @@ def set_perm(
         :param target: The mapped instance being persisted
         """
 
+        link_table = target.__table__
         if target.perm != target.get_perm():
-            link_table = target.__table__
             connection.execute(
                 link_table.update()
                 .where(link_table.c.id == target.id)
                 .values(perm=target.get_perm())
             )
 
-        # add to view menu if not already exists
-        permission_name = "datasource_access"
-        view_menu_name = target.get_perm()
-        permission = self.find_permission(permission_name)
-        view_menu = self.find_view_menu(view_menu_name)
-        pv = None
-
-        if not permission:
-            permission_table = (
-                self.permission_model.__table__  # pylint: disable=no-member
+        if (
+            hasattr(target, "schema_perm")
+            and target.schema_perm != target.get_schema_perm()
+        ):
+            connection.execute(
+                link_table.update()
+                .where(link_table.c.id == target.id)
+                .values(schema_perm=target.get_schema_perm())
             )
-            connection.execute(permission_table.insert().values(name=permission_name))
+
+        pvm_names = []
+        if target.__tablename__ in {"dbs", "clusters"}:
+            pvm_names.append(("database_access", target.get_perm()))
+        else:
+            pvm_names.append(("datasource_access", target.get_perm()))
+            if target.schema:
+                pvm_names.append(("schema_access", target.get_schema_perm()))
+
+        for permission_name, view_menu_name in pvm_names:
 
 Review comment:
   code is the same in the for loop, changes are only above:
   1. support database permissions
   2. support schema permissions

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