mirror of
https://github.com/apache/superset.git
synced 2026-04-21 17:14:57 +00:00
refactor: Move raise_for_dashboard_access to security manager (#13235)
raise_for_dashboard_access is part of dashboard and cannot be overridden by a security manager.
This commit is contained in:
@@ -55,6 +55,7 @@ if TYPE_CHECKING:
|
||||
from superset.common.query_context import QueryContext
|
||||
from superset.connectors.base.models import BaseDatasource
|
||||
from superset.connectors.druid.models import DruidCluster
|
||||
from superset.models.dashboard import Dashboard
|
||||
from superset.models.core import Database
|
||||
from superset.models.sql_lab import Query
|
||||
from superset.sql_parse import Table
|
||||
@@ -1097,3 +1098,30 @@ class SupersetSecurityManager( # pylint: disable=too-many-public-methods
|
||||
ids = [f.id for f in self.get_rls_filters(table)]
|
||||
ids.sort() # Combinations rather than permutations
|
||||
return ids
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
def raise_for_dashboard_access(self, dashboard: "Dashboard") -> None:
|
||||
"""
|
||||
Raise an exception if the user cannot access the dashboard.
|
||||
|
||||
:param dashboard: Dashboard the user wants access to
|
||||
:raises DashboardAccessDeniedError: If the user cannot access the resource
|
||||
"""
|
||||
from superset.dashboards.commands.exceptions import DashboardAccessDeniedError
|
||||
from superset.views.base import get_user_roles, is_user_admin
|
||||
from superset.views.utils import is_owner
|
||||
from superset import is_feature_enabled
|
||||
|
||||
if is_feature_enabled("DASHBOARD_RBAC"):
|
||||
has_rbac_access = any(
|
||||
dashboard_role.id in [user_role.id for user_role in get_user_roles()]
|
||||
for dashboard_role in dashboard.roles
|
||||
)
|
||||
can_access = (
|
||||
is_user_admin()
|
||||
or is_owner(dashboard, g.user)
|
||||
or (dashboard.published and has_rbac_access)
|
||||
)
|
||||
|
||||
if not can_access:
|
||||
raise DashboardAccessDeniedError()
|
||||
|
||||
Reference in New Issue
Block a user