本文整理汇总了Python中superset.connectors.connector_registry.ConnectorRegistry.query_datasources_by_permissions方法的典型用法代码示例。如果您正苦于以下问题:Python ConnectorRegistry.query_datasources_by_permissions方法的具体用法?Python ConnectorRegistry.query_datasources_by_permissions怎么用?Python ConnectorRegistry.query_datasources_by_permissions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类superset.connectors.connector_registry.ConnectorRegistry
的用法示例。
在下文中一共展示了ConnectorRegistry.query_datasources_by_permissions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: accessible_by_user
# 需要导入模块: from superset.connectors.connector_registry import ConnectorRegistry [as 别名]
# 或者: from superset.connectors.connector_registry.ConnectorRegistry import query_datasources_by_permissions [as 别名]
def accessible_by_user(self, database, datasource_names, schema=None):
if self.database_access(database) or self.all_datasource_access():
return datasource_names
if schema:
schema_perm = utils.get_schema_perm(database, schema)
if self.can_access('schema_access', schema_perm):
return datasource_names
user_perms = self.user_datasource_perms()
user_datasources = ConnectorRegistry.query_datasources_by_permissions(
db.session, database, user_perms)
if schema:
names = {
d.table_name
for d in user_datasources if d.schema == schema}
return [d for d in datasource_names if d in names]
else:
full_names = {d.full_name for d in user_datasources}
return [d for d in datasource_names if d in full_names]
示例2: accessible_by_user
# 需要导入模块: from superset.connectors.connector_registry import ConnectorRegistry [as 别名]
# 或者: from superset.connectors.connector_registry.ConnectorRegistry import query_datasources_by_permissions [as 别名]
def accessible_by_user(self, database, datasource_names, schema=None):
if self.database_access(database) or self.all_datasource_access():
return datasource_names
schema_perm = utils.get_schema_perm(database, schema)
if schema and utils.can_access(
sm, 'schema_access', schema_perm, g.user):
return datasource_names
role_ids = set([role.id for role in g.user.roles])
# TODO: cache user_perms or user_datasources
user_pvms = (
db.session.query(ab_models.PermissionView)
.join(ab_models.Permission)
.filter(ab_models.Permission.name == 'datasource_access')
.filter(ab_models.PermissionView.role.any(
ab_models.Role.id.in_(role_ids)))
.all()
)
user_perms = set([pvm.view_menu.name for pvm in user_pvms])
user_datasources = ConnectorRegistry.query_datasources_by_permissions(
db.session, database, user_perms)
full_names = set([d.full_name for d in user_datasources])
return [d for d in datasource_names if d in full_names]