From 90d156f1866c21991017ca3b061609888539206a Mon Sep 17 00:00:00 2001 From: Daniel Vaz Gaspar Date: Fri, 21 Jun 2019 22:25:48 +0100 Subject: [PATCH] [security] [ui] Make security views use superset's list widget (#7724) --- superset/security.py | 30 ++++++++++++++++++- .../superset/fab_overrides/list_role.html | 24 +++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 superset/templates/superset/fab_overrides/list_role.html diff --git a/superset/security.py b/superset/security.py index 5129e3687f..ffaeb1c15f 100644 --- a/superset/security.py +++ b/superset/security.py @@ -19,9 +19,12 @@ import logging from typing import List -from flask import g +from flask import current_app, g from flask_appbuilder.security.sqla import models as ab_models from flask_appbuilder.security.sqla.manager import SecurityManager +from flask_appbuilder.security.views import ( + PermissionModelView, PermissionViewModelView, RoleModelView, UserModelView) +from flask_appbuilder.widgets import ListWidget from sqlalchemy import or_ from superset import sql_parse @@ -30,6 +33,31 @@ from superset.exceptions import SupersetSecurityException from superset.utils.core import DatasourceName +class SupersetSecurityListWidget(ListWidget): + """ + Redeclaring to avoid circular imports + """ + template = 'superset/fab_overrides/list.html' + + +class SupersetRoleListWidget(ListWidget): + """ + Role model view from FAB already uses a custom list widget override + So we override the override + """ + template = 'superset/fab_overrides/list_role.html' + + def __init__(self, **kwargs): + kwargs['appbuilder'] = current_app.appbuilder + super().__init__(**kwargs) + + +UserModelView.list_widget = SupersetSecurityListWidget +RoleModelView.list_widget = SupersetRoleListWidget +PermissionViewModelView.list_widget = SupersetSecurityListWidget +PermissionModelView.list_widget = SupersetSecurityListWidget + + class SupersetSecurityManager(SecurityManager): READ_ONLY_MODEL_VIEWS = { 'DatabaseAsync', diff --git a/superset/templates/superset/fab_overrides/list_role.html b/superset/templates/superset/fab_overrides/list_role.html new file mode 100644 index 0000000000..95847f9110 --- /dev/null +++ b/superset/templates/superset/fab_overrides/list_role.html @@ -0,0 +1,24 @@ +{# + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +#} +{% extends 'appbuilder/general/widgets/roles/list.html' %} + +{% block begin_content scoped %} +
+ +{% endblock %}