diff --git a/superset/dashboards/filters.py b/superset/dashboards/filters.py index 589d98fb26700..a2421ab007ba6 100644 --- a/superset/dashboards/filters.py +++ b/superset/dashboards/filters.py @@ -24,7 +24,7 @@ from superset.models.core import FavStar from superset.models.dashboard import Dashboard from superset.models.slice import Slice -from superset.views.base import BaseFilter, get_user_roles +from superset.views.base import BaseFilter, is_user_admin from superset.views.base_api import BaseFavoriteFilter @@ -69,8 +69,7 @@ class DashboardFilter(BaseFilter): # pylint: disable=too-few-public-methods """ def apply(self, query: Query, value: Any) -> Query: - user_roles = [role.name.lower() for role in list(get_user_roles())] - if "admin" in user_roles: + if is_user_admin(): return query datasource_perms = security_manager.user_view_menu_names("datasource_access") diff --git a/superset/views/base.py b/superset/views/base.py index f88a7fcf21c49..1f06731b98fa9 100644 --- a/superset/views/base.py +++ b/superset/views/base.py @@ -246,6 +246,11 @@ def get_user_roles() -> List[Role]: return g.user.roles +def is_user_admin() -> bool: + user_roles = [role.name.lower() for role in list(get_user_roles())] + return "admin" in user_roles + + class BaseSupersetView(BaseView): @staticmethod def json_response( @@ -500,8 +505,7 @@ def check_ownership(obj: Any, raise_if_false: bool = True) -> bool: if raise_if_false: raise security_exception return False - roles = [r.name for r in get_user_roles()] - if "Admin" in roles: + if is_user_admin(): return True scoped_session = db.create_scoped_session() orig_obj = scoped_session.query(obj.__class__).filter_by(id=obj.id).first()