betodealmeida commented on a change in pull request #15184:
URL: https://github.com/apache/superset/pull/15184#discussion_r657585115



##########
File path: superset/connectors/connector_registry.py
##########
@@ -99,6 +100,41 @@ def get_datasource_by_id(  # pylint: 
disable=too-many-arguments
                 pass
         raise NoResultFound(_("Datasource id not found: %(id)s", 
id=datasource_id))
 
+    @classmethod
+    def get_user_datasources(cls, session: Session) -> List["BaseDatasource"]:
+        from superset import security_manager
+
+        # collect datasources which the user has explicit permissions to
+        user_perms = security_manager.user_view_menu_names("datasource_access")
+        schema_perms = security_manager.user_view_menu_names("schema_access")
+        user_datasources = set()
+        for datasource_class in ConnectorRegistry.sources.values():
+            user_datasources.update(
+                session.query(datasource_class)

Review comment:
       @john-bodley, `get_datasources_accessible_by_user` calls 
`ConnectorRegistry.query_datasources_by_permissions`, which uses the same logic 
I'm using here.
   
   Since we're getting `user_perms` and `schema_perms` from the security 
manager (lines 108, 109) doesn't it means this works with custom security 
managers?




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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to