[security] [ui] Make security views use superset's list widget (#7724)

This commit is contained in:
Daniel Vaz Gaspar 2019-06-21 22:25:48 +01:00 committed by Maxime Beauchemin
parent f09c916879
commit 90d156f186
2 changed files with 53 additions and 1 deletions

View File

@ -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',

View File

@ -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 %}
<div class="table-responsive">
<table class="table table-hover">
{% endblock %}