Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve performance on bootstrap permissions #22083

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ flask==2.0.3
# flask-migrate
# flask-sqlalchemy
# flask-wtf
flask-appbuilder==4.1.4
flask-appbuilder==4.1.6
# via apache-superset
flask-babel==1.0.0
# via flask-appbuilder
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def get_git_sha() -> str:
"cryptography>=3.3.2",
"deprecation>=2.1.0, <2.2.0",
"flask>=2.0.0, <3.0.0",
"flask-appbuilder>=4.1.4, <5.0.0",
"flask-appbuilder>=4.1.6, <5.0.0",
"flask-caching>=1.10.0",
"flask-compress",
"flask-talisman",
Expand Down
21 changes: 9 additions & 12 deletions superset/views/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,20 @@ def bootstrap_user_data(user: User, include_perms: bool = False) -> Dict[str, An

def get_permissions(
user: User,
) -> Tuple[Dict[str, List[List[str]]], DefaultDict[str, List[str]]]:
) -> Tuple[Dict[str, List[Tuple[str]]], DefaultDict[str, List[str]]]:
if not user.roles:
raise AttributeError("User object does not have roles")

roles = defaultdict(list)
permissions = defaultdict(set)

for role in user.roles:
permissions_ = security_manager.get_role_permissions(role)
for permission in permissions_:
data_permissions = defaultdict(set)
roles_permissions = security_manager.get_user_roles_permissions(user)
for _, permissions in roles_permissions.items():
for permission in permissions:
if permission[0] in ("datasource_access", "database_access"):
permissions[permission[0]].add(permission[1])
roles[role.name].append([permission[0], permission[1]])
data_permissions[permission[0]].add(permission[1])
transformed_permissions = defaultdict(list)
for perm in permissions:
transformed_permissions[perm] = list(permissions[perm])
return roles, transformed_permissions
for perm in data_permissions:
transformed_permissions[perm] = list(data_permissions[perm])
return roles_permissions, transformed_permissions


def get_viz(
Expand Down