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

[bugfix] SQLA instance has been deleted #3159

Merged
merged 1 commit into from
Jul 19, 2017
Merged
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
27 changes: 10 additions & 17 deletions superset/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,14 @@ def is_granter_pvm(pvm):
'can_approve'}


def set_role(role_name, pvms, pvm_check):
def set_role(role_name, pvm_check):
logging.info("Syncing {} perms".format(role_name))
sesh = sm.get_session()
pvms = sesh.query(ab_models.PermissionView).all()
pvms = [p for p in pvms if p.permission and p.view_menu]
role = sm.add_role(role_name)
role_pvms = [p for p in pvms if pvm_check(p)]
role.permissions = role_pvms
sesh = sm.get_session()
sesh.merge(role)
sesh.commit()

Expand Down Expand Up @@ -200,24 +202,15 @@ def sync_role_definitions():
get_or_create_main_db()
create_custom_permissions()

pvms = db.session.query(ab_models.PermissionView).all()
pvms = [p for p in pvms if p.permission and p.view_menu]

# cleanup
pvms_to_delete = [p for p in pvms if not (p.permission and p.view_menu)]

for pvm_to_delete in pvms_to_delete:
sm.get_session.delete(pvm_to_delete)

# Creating default roles
set_role('Admin', pvms, is_admin_pvm)
set_role('Alpha', pvms, is_alpha_pvm)
set_role('Gamma', pvms, is_gamma_pvm)
set_role('granter', pvms, is_granter_pvm)
set_role('sql_lab', pvms, is_sql_lab_pvm)
set_role('Admin', is_admin_pvm)
set_role('Alpha', is_alpha_pvm)
set_role('Gamma', is_gamma_pvm)
set_role('granter', is_granter_pvm)
set_role('sql_lab', is_sql_lab_pvm)

if conf.get('PUBLIC_ROLE_LIKE_GAMMA', False):
set_role('Public', pvms, is_gamma_pvm)
set_role('Public', is_gamma_pvm)

create_missing_perms()

Expand Down