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

fix: bootstrap data permissions #14348

Merged
merged 2 commits into from
Apr 30, 2021
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 @@ -66,7 +66,7 @@ dnspython==2.0.0
# via email-validator
email-validator==1.1.1
# via flask-appbuilder
flask-appbuilder==3.2.1
flask-appbuilder==3.2.3
# 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 @@ -75,7 +75,7 @@ def get_git_sha():
"cron-descriptor",
"cryptography>=3.2.1",
"flask>=1.1.0, <2.0.0",
"flask-appbuilder>=3.2.1, <4.0.0",
"flask-appbuilder>=3.2.3, <4.0.0",
"flask-caching",
"flask-compress",
"flask-talisman",
Expand Down
21 changes: 8 additions & 13 deletions superset/views/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
SupersetException,
SupersetSecurityException,
)
from superset.extensions import cache_manager
from superset.extensions import cache_manager, security_manager
from superset.legacy import update_time_range
from superset.models.core import Database
from superset.models.dashboard import Dashboard
Expand Down Expand Up @@ -87,20 +87,15 @@ def get_permissions(
if not user.roles:
raise AttributeError("User object does not have roles")

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

for role in user.roles:
perms = set()
for perm in role.permissions:
if perm.permission and perm.view_menu:
perms.add((perm.permission.name, perm.view_menu.name))
if perm.permission.name in ("datasource_access", "database_access"):
permissions[perm.permission.name].add(perm.view_menu.name)
roles[role.name] = [
[perm.permission.name, perm.view_menu.name]
for perm in role.permissions
if perm.permission and perm.view_menu
]
permissions_ = security_manager.get_role_permissions(role)
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]])

return roles, permissions

Expand Down