You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@superset.apache.org by GitBox <gi...@apache.org> on 2018/02/04 04:12:50 UTC

[GitHub] mistercrunch closed pull request #4241: [cli] permission cleanup on 'superset init'

mistercrunch closed pull request #4241: [cli] permission cleanup on 'superset init'
URL: https://github.com/apache/incubator-superset/pull/4241
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/superset/security.py b/superset/security.py
index a2e0d5ae1a..fa056c3987 100644
--- a/superset/security.py
+++ b/superset/security.py
@@ -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
@@ -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')
@@ -231,3 +249,4 @@ def sync_role_definitions():
 
     # commit role and view menu updates
     sm.get_session.commit()
+    clean_perms()


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services