From b4c3d3bee073075fba139c2b84bdc56bd7b6c430 Mon Sep 17 00:00:00 2001 From: Daniel Gaspar Date: Wed, 9 Nov 2022 16:07:03 +0000 Subject: [PATCH 1/3] chore: improve performance on bootstrap permissions --- requirements/base.txt | 2 +- setup.py | 2 +- superset/views/utils.py | 25 +++++++++++++------------ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/requirements/base.txt b/requirements/base.txt index 8387d380bc5ab..a7b64d9e0993b 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -76,7 +76,7 @@ flask==2.0.3 # flask-migrate # flask-sqlalchemy # flask-wtf -flask-appbuilder==4.1.4 +flask-appbuilder==4.1.6rc1 # via apache-superset flask-babel==1.0.0 # via flask-appbuilder diff --git a/setup.py b/setup.py index cad76a9572997..cd3561a73de10 100644 --- a/setup.py +++ b/setup.py @@ -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.6rc1, <5.0.0", "flask-caching>=1.10.0", "flask-compress", "flask-talisman", diff --git a/superset/views/utils.py b/superset/views/utils.py index 6b6d5a0fb8579..34daed7974363 100644 --- a/superset/views/utils.py +++ b/superset/views/utils.py @@ -101,25 +101,26 @@ def bootstrap_user_data(user: User, include_perms: bool = False) -> Dict[str, An return payload +# 019353721141815185 +# 00747002124786377 + + 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 role_name, 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( From af7e7c83cd7b9b9aa5c437ed5551bc9b6e609015 Mon Sep 17 00:00:00 2001 From: Daniel Gaspar Date: Wed, 9 Nov 2022 17:21:55 +0000 Subject: [PATCH 2/3] fix lint --- superset/views/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset/views/utils.py b/superset/views/utils.py index 34daed7974363..209e5fa6e913c 100644 --- a/superset/views/utils.py +++ b/superset/views/utils.py @@ -113,7 +113,7 @@ def get_permissions( data_permissions = defaultdict(set) roles_permissions = security_manager.get_user_roles_permissions(user) - for role_name, permissions in roles_permissions.items(): + for _, permissions in roles_permissions.items(): for permission in permissions: if permission[0] in ("datasource_access", "database_access"): data_permissions[permission[0]].add(permission[1]) From bf003149655e26c3d5ff9edeaedf946b15e04880 Mon Sep 17 00:00:00 2001 From: Daniel Gaspar Date: Thu, 10 Nov 2022 10:09:59 +0000 Subject: [PATCH 3/3] use final FAB release --- requirements/base.txt | 2 +- setup.py | 2 +- superset/views/utils.py | 4 ---- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/requirements/base.txt b/requirements/base.txt index a7b64d9e0993b..f3bd5512645ec 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -76,7 +76,7 @@ flask==2.0.3 # flask-migrate # flask-sqlalchemy # flask-wtf -flask-appbuilder==4.1.6rc1 +flask-appbuilder==4.1.6 # via apache-superset flask-babel==1.0.0 # via flask-appbuilder diff --git a/setup.py b/setup.py index cd3561a73de10..04e14a99b0b5b 100644 --- a/setup.py +++ b/setup.py @@ -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.6rc1, <5.0.0", + "flask-appbuilder>=4.1.6, <5.0.0", "flask-caching>=1.10.0", "flask-compress", "flask-talisman", diff --git a/superset/views/utils.py b/superset/views/utils.py index 209e5fa6e913c..835c8eda0d8d6 100644 --- a/superset/views/utils.py +++ b/superset/views/utils.py @@ -101,10 +101,6 @@ def bootstrap_user_data(user: User, include_perms: bool = False) -> Dict[str, An return payload -# 019353721141815185 -# 00747002124786377 - - def get_permissions( user: User, ) -> Tuple[Dict[str, List[Tuple[str]]], DefaultDict[str, List[str]]]: