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

[cli] permission cleanup on 'superset init' #4241

Merged
merged 2 commits into from
Feb 4, 2018
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
19 changes: 19 additions & 0 deletions superset/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging

from flask_appbuilder.security.sqla import models as ab_models
from sqlalchemy import or_

from superset import conf, db, sm
from superset.connectors.connector_registry import ConnectorRegistry
Expand Down Expand Up @@ -210,6 +211,23 @@ def merge_pv(view_menu, perm):
merge_pv('metric_access', metric.perm)


def clean_perms():
"""FAB leaves faulty permissions that need to be cleaned up"""
logging.info('Cleaning faulty perms')
sesh = sm.get_session()
pvms = (
sesh.query(ab_models.PermissionView)
.filter(or_(
ab_models.PermissionView.permission == None, # NOQA
ab_models.PermissionView.view_menu == None, # NOQA
))
)
deleted_count = pvms.delete()
sesh.commit()
if deleted_count:
logging.info('Deleted {} faulty permissions'.format(deleted_count))


def sync_role_definitions():
"""Inits the Superset application with security roles and such"""
logging.info('Syncing role definition')
Expand All @@ -231,3 +249,4 @@ def sync_role_definitions():

# commit role and view menu updates
sm.get_session.commit()
clean_perms()