Skip to content

Commit

Permalink
refactor: extract to method is_user_admin (#12570)
Browse files Browse the repository at this point in the history
  • Loading branch information
amitmiran137 authored Jan 18, 2021
1 parent 377f70b commit 0f243c6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 2 additions & 3 deletions superset/dashboards/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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")
Expand Down
8 changes: 6 additions & 2 deletions superset/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 0f243c6

Please sign in to comment.