CUSTOM_SECURITY_MANAGER = "superset.security.CustomSecurityManager" CUSTOM_SECURITY_MANAGER_ALT = CUSTOM_SECURITY_MANAGER
CUSTOM_SENSITIVE_POST_FIELD_KEYS = ["sql"] CUSTOM_SENSITIVE_REQUEST_KEYS = ["sql", "changed_on", "rows", "start_time", "end_time", "client_id"]
from superset.security import SupersetSecurityManager class CustomSecurityManager(SupersetSecurityManager): def check_metric(self, metric: SqlMetric) -> bool: """ Check if user can access a given metric object.
:param metric: SqlMetric object
:return: bool
"""
dbs = set([col.table.database for col in metric.columns])
return self.appbuilder.sm.has_access(
"database_access", *dbs, appbuilder=self.appbuilder
)
示例:
在 Superset 中创建自定义 SQL 指标,选择一个存在的数据库和关联的表,并输入正确的 SQL 查询语句。
如果自定义 SQL 指标在此后仍无法正常工作,可以尝试重新启动应用程序或重新编译并安装 Apache Superset 以解决问题。