Ejemplo n.º 1
0
def _register_schedule_menus():
    appbuilder.add_separator('Manage')

    appbuilder.add_view(DashboardEmailScheduleView,
                        'Dashboard Email Schedules',
                        label=__('Dashboard Emails'),
                        category='Manage',
                        category_label=__('Manage'),
                        icon='fa-search')

    appbuilder.add_view(SliceEmailScheduleView,
                        'Chart Emails',
                        label=__('Chart Email Schedules'),
                        category='Manage',
                        category_label=__('Manage'),
                        icon='fa-search')
Ejemplo n.º 2
0
def _register_schedule_menus():
    appbuilder.add_separator('Manage')

    appbuilder.add_view(
        DashboardEmailScheduleView,
        'Dashboard Email Schedules',
        label=__('Dashboard Emails'),
        category='Manage',
        category_label=__('Manage'),
        icon='fa-search')

    appbuilder.add_view(
        SliceEmailScheduleView,
        'Chart Emails',
        label=__('Chart Email Schedules'),
        category='Manage',
        category_label=__('Manage'),
        icon='fa-search')
Ejemplo n.º 3
0
def _register_schedule_menus():
    appbuilder.add_separator("Manage")

    appbuilder.add_view(
        DashboardEmailScheduleView,
        "Dashboard Email Schedules",
        label=__("Dashboard Emails"),
        category="Manage",
        category_label=__("Manage"),
        icon="fa-search",
    )

    appbuilder.add_view(
        SliceEmailScheduleView,
        "Chart Emails",
        label=__("Chart Email Schedules"),
        category="Manage",
        category_label=__("Manage"),
        icon="fa-search",
    )
Ejemplo n.º 4
0
appbuilder.add_link(
    "Import Dashboards",
    label=__("Import Dashboards"),
    href="/superset/import_dashboards",
    icon="fa-cloud-upload",
    category="Manage",
    category_label=__("Manage"),
    category_icon="fa-wrench",
)

appbuilder.add_view(
    DatabaseView,
    "Databases",
    label=__("Databases"),
    icon="fa-database",
    category="Sources",
    category_label=__("Sources"),
    category_icon="fa-database",
)


class CsvToDatabaseView(SimpleFormView):
    form = CsvToDatabaseForm
    form_template = "superset/form_view/csv_to_database_view/edit.html"
    form_title = _("CSV to Database configuration")
    add_columns = ["database", "schema", "table_name"]

    def form_get(self, form):
        form.sep.data = ","
        form.header.data = 0
Ejemplo n.º 5
0
    def pre_add(self, cluster):
        security_manager.add_permission_view_menu("database_access",
                                                  cluster.perm)

    def pre_update(self, cluster):
        self.pre_add(cluster)

    def _delete(self, pk):
        DeleteMixin._delete(self, pk)


appbuilder.add_view(
    DruidClusterModelView,
    name="Druid Clusters",
    label=__("Druid Clusters"),
    icon="fa-cubes",
    category="Sources",
    category_label=__("Sources"),
    category_icon="fa-database",
)


class DruidDatasourceModelView(DatasourceModelView, DeleteMixin,
                               YamlExportMixin):
    datamodel = SQLAInterface(models.DruidDatasource)

    list_title = _("Druid Datasources")
    show_title = _("Show Druid Datasource")
    add_title = _("Add Druid Datasource")
    edit_title = _("Edit Druid Datasource")
Ejemplo n.º 6
0
        elif obj.end_dttm < obj.start_dttm:
            raise Exception('Annotation end time must be no earlier than start time.')

    def pre_update(self, obj):
        self.pre_add(obj)


class AnnotationLayerModelView(SupersetModelView, DeleteMixin):
    datamodel = SQLAInterface(AnnotationLayer)
    list_columns = ['id', 'name']
    edit_columns = ['name', 'descr']
    add_columns = edit_columns


appbuilder.add_view(
    AnnotationLayerModelView,
    'Annotation Layers',
    label=__('Annotation Layers'),
    icon='fa-comment',
    category='Manage',
    category_label=__('Manage'),
    category_icon='')
appbuilder.add_view(
    AnnotationModelView,
    'Annotations',
    label=__('Annotations'),
    icon='fa-comments',
    category='Manage',
    category_label=__('Manage'),
    category_icon='')
Ejemplo n.º 7
0
            security.merge_perm(sm, 'schema_access', table.schema_perm)

        if flash_message:
            flash(_(
                "The table was created. "
                "As part of this two phase configuration "
                "process, you should now click the edit button by "
                "the new table to configure it."), "info")

    def post_update(self, table):
        self.post_add(table, flash_message=False)

    @expose('/edit/<pk>', methods=['GET', 'POST'])
    @has_access
    def edit(self, pk):
        """Simple hack to redirect to explore view after saving"""
        resp = super(TableModelView, self).edit(pk)
        if isinstance(resp, basestring):
            return resp
        return redirect('/superset/explore/table/{}/'.format(pk))

appbuilder.add_view(
    TableModelView,
    "Tables",
    label=__("Tables"),
    category="Sources",
    category_label=__("Sources"),
    icon='fa-table',)

appbuilder.add_separator("Sources")
Ejemplo n.º 8
0
class QueryView(SupersetModelView):
    datamodel = SQLAInterface(Query)
    list_columns = ['user', 'database', 'status', 'start_time', 'end_time']
    label_columns = {
        'user': _('User'),
        'database': _('Database'),
        'status': _('Status'),
        'start_time': _('Start Time'),
        'end_time': _('End Time'),
    }


appbuilder.add_view(
    QueryView,
    'Queries',
    label=__('Queries'),
    category='Manage',
    category_label=__('Manage'),
    icon='fa-search')


class SavedQueryView(SupersetModelView, DeleteMixin):
    datamodel = SQLAInterface(SavedQuery)

    list_title = _('List Saved Query')
    show_title = _('Show Saved Query')
    add_title = _('Add Saved Query')
    edit_title = _('Edit Saved Query')

    list_columns = [
        'label', 'user', 'database', 'schema', 'description',
Ejemplo n.º 9
0
            obj.end_dttm = obj.start_dttm
        elif obj.end_dttm < obj.start_dttm:
            raise Exception(
                "Annotation end time must be no earlier than start time.")

    def pre_update(self, obj):
        self.pre_add(obj)


class AnnotationLayerModelView(SupersetModelView, DeleteMixin):
    datamodel = SQLAInterface(AnnotationLayer)
    list_columns = ['id', 'name']
    edit_columns = ['name', 'descr']
    add_columns = edit_columns


appbuilder.add_view(AnnotationLayerModelView,
                    "Annotation Layers",
                    label=__("Annotation Layers"),
                    icon="fa-comment",
                    category="Manage",
                    category_label=__("Manage"),
                    category_icon='')
appbuilder.add_view(AnnotationModelView,
                    "Annotations",
                    label=__("Annotations"),
                    icon="fa-comments",
                    category="Manage",
                    category_label=__("Manage"),
                    category_icon='')
Ejemplo n.º 10
0
    def api(self, path):
        """ Proxy frontend request to bblfsh-web server """
        resp = requests.request(
            method=request.method,
            url="%s/api/%s" % (BBLFSH_WEB_ADDRESS, path),
            headers={key: value for (key, value) in request.headers if key != "Host"},
            data=request.get_data(),
            cookies=request.cookies,
            allow_redirects=False,
        )

        excluded_headers = [
            "content-encoding",
            "content-length",
            "transfer-encoding",
            "connection",
        ]
        headers = [
            (name, value)
            for (name, value) in resp.raw.headers.items()
            if name.lower() not in excluded_headers
        ]

        response = Response(resp.content, resp.status_code, headers)
        return response


appbuilder.add_view(
    Bblfsh, "UAST", label=_("UAST"), category_icon="fa-tree", icon="fa-tree"
)
Ejemplo n.º 11
0
    }

    def pre_add(self, cluster):
        security_manager.merge_perm('database_access', cluster.perm)

    def pre_update(self, cluster):
        self.pre_add(cluster)

    def _delete(self, pk):
        DeleteMixin._delete(self, pk)


appbuilder.add_view(
    ElasticClusterModelView,
    name='Elastic Clusters',
    label=__('Elastic Clusters'),
    icon='fa-cubes',
    category='Sources',
    category_label=__('Sources'),
    category_icon='fa-database')


class ElasticDatasourceModelView(SupersetModelView, DeleteMixin):  # noqa
    datamodel = SQLAInterface(models.ElasticDatasource)
    list_widget = ListWidgetWithCheckboxes
    list_columns = [
        'datasource_link', 'cluster', 'changed_by_', 'modified']
    order_columns = [
        'datasource_link', 'changed_on_', 'offset']
    related_views = [ElasticColumnInlineView, ElasticMetricInlineView]
    edit_columns = [
        'datasource_name', 'cluster', 'slices', 'description', 'owner',
Ejemplo n.º 12
0
class QueryView(SupersetModelView):
    datamodel = SQLAInterface(Query)
    list_columns = ['user', 'database', 'status', 'start_time', 'end_time']
    label_columns = {
        'user': _('User'),
        'database': _('Database'),
        'status': _('Status'),
        'start_time': _('Start Time'),
        'end_time': _('End Time'),
    }

appbuilder.add_view(
    QueryView,
    "Queries",
    label=__("Queries"),
    category="Manage",
    category_label=__("Manage"),
    icon="fa-search")


class SavedQueryView(SupersetModelView, DeleteMixin):
    datamodel = SQLAInterface(SavedQuery)

    list_title = _('List Saved Query')
    show_title = _('Show Saved Query')
    add_title = _('Add Saved Query')
    edit_title = _('Edit Saved Query')

    list_columns = [
        'label', 'user', 'database', 'schema', 'description',
Ejemplo n.º 13
0
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from flask_appbuilder import BaseView, expose

from superset import appbuilder


class EChartsView(BaseView):
    default_view = 'sample'

    @expose('/sample/')
    def sample(self):
        return self.render_template('superset/echarts/echarts_index.html')

    @expose('/message/<string:msg>')
    def message(self, msg):
        msg = 'Hello %s' % (msg)
        return msg

    @expose('/welcome/<string:msg>')
    def welcome(self, msg):
        msg = 'Hello %s' % (msg)
        return self.render_template('index.html',msg = msg)

appbuilder.add_view(EChartsView, "Sample", category='EChart')
appbuilder.add_link("Message", href='/myview/message/john', category='EChart')
appbuilder.add_link("Welcome", href='/myview/welcome/student', category='EChart')
Ejemplo n.º 14
0
                      EXISTING_ACCESS_TOKEN=obj.access_token,
                  )

        if lat_uri:
            h = httplib2.Http(".cache")
            (resp, content) = h.request(lat_uri,
                                        'GET',
                                        headers={'cache-control': 'no-cache'})
            if 'access_token' in content:
                json_content = json.loads(content)
                if 'access_token' in json_content:
                    logging.info(json_content['access_token'])
                    obj.access_token = json_content['access_token']

    # actions
    @action('sync_ad_accounts', 'Sync AdAccounts for this connector',
            'Sync AdAccounts for this connector', 'fa-rocket')
    def sync_ad_accounts(self, item):
        """Call sync_ad_accounts."""
        item[0].sync_ad_accounts()

        return redirect('adaccountview/list/')


# Register FacebookConnector Model View
appbuilder.add_view(FacebookConnectorView,
                    'FacebookAds',
                    icon='fa-facebook',
                    category='Connectors',
                    category_icon='fa-facebook',
                    category_label=__('Connectors'))
Ejemplo n.º 15
0
# flask_appbuilder
from flask_appbuilder.models.sqla.interface import SQLAInterface
from flask_appbuilder.actions import action

# flask_babel
from flask_babel import gettext as __

# superset
from superset import appbuilder
from superset.views.base import SupersetModelView, DeleteMixin


# local
from .. models.google_drive_storage import GoogleDriveStorage

class GoogleDriveStorageView(SupersetModelView, DeleteMixin):
    """View For Facebook FacebookConnector Model."""

    datamodel = SQLAInterface(GoogleDriveStorage)


# Register GoogleDriveStorageView Model View
appbuilder.add_view(
    GoogleDriveStorageView,
    'GoogleDriveStorage',
    icon='fa-google',
    category='Connectors',
    category_icon='fa-google',
    category_label=__('Connectors')
)
Ejemplo n.º 16
0
        obj.sync_next_time = obj.get_next_sync()

    def pre_delete(self, obj):
        logging.info('pre_delete')

        if obj.exist_table():
            obj.delete_table()

    # def _delete(self, pk):
    #     DeleteMixin._delete(self, pk)


# Register EtlTableView Model View
appbuilder.add_view(EtlTableView,
                    'Tables',
                    icon='fa-table',
                    category='ETL',
                    category_icon='fa-refresh',
                    category_label=__('ETL'))
# for show all Reports in system


class PostgreSQLAInterface(SQLAInterface):
    def is_text(self, col_name):
        try:
            return (isinstance(self.list_columns[col_name].type,
                               sa.types.String)
                    or isinstance(self.list_columns[col_name].type, HSTORE))
        except Exception:
            return False

Ejemplo n.º 17
0
    datamodel = SQLAInterface(Connector)

    list_columns = [
        'name', 'connector_info', 'admin_data_sources'
        # 'admin_data_sources'
    ]

    add_columns = []


# Register ConnectorView Model View
appbuilder.add_view(
    ConnectorView,
    'Connections',
    # href='/connections',
    icon='fa-random',
    category='Connectors',
    category_icon='fa-random',
    category_label=__('Connectors'))
#
# class MyView(BaseSupersetView):
#
#     default_view = 'method1'
#
#     @expose('/method1/')
#     @has_access
#     def method1(self):
#         # do something with param1
#         # and return to previous page or index
#         return self.render_template('bit/table_preview.html')
#
Ejemplo n.º 18
0
                  'As part of this two phase configuration '
                  'process, you should now click the edit button by '
                  'the new datasource to configure it.'), 'info')

    def post_update(self, datasource):
        self.post_add(datasource, flash_message=False)

    def _delete(self, pk):
        DeleteMixin._delete(self, pk)

    @expose('/edit/<pk>', methods=['GET', 'POST'])
    @has_access
    def edit(self, pk):
        """Simple hack to redirect to explore view after saving"""
        resp = super(PandasDatasourceModelView, self).edit(pk)
        if isinstance(resp, basestring):
            return resp
        return redirect(url_for('Superset.explore') + 'pandas/{}/'.format(pk))


appbuilder.add_view(
    PandasDatasourceModelView,
    'File Datasources',
    label=__('File Datasources'),
    category='Sources',
    category_label=__('Sources'),
    icon='fa-file',
)

appbuilder.add_separator('Sources')
Ejemplo n.º 19
0
# flask_babel
from flask_babel import gettext as __

# superset
from superset import appbuilder
from superset.views.base import SupersetModelView, DeleteMixin

# local
from ..models.connector import AdWordsConnector
from ..models.campaign import CampaignPerformanceReport


class CampaignPerformanceReportView(SupersetModelView, DeleteMixin):
    """View For AdWords CampaignPerformanceReport Model."""

    datamodel = SQLAInterface(CampaignPerformanceReport)

    list_columns = [
        'campaign_name', 'date', 'conversions', 'cost', 'clicks',
        'impression_device', 'impressions'
    ]


# Register AdWordsConnector Model View
appbuilder.add_view(CampaignPerformanceReportView,
                    'CampaignPerformanceReport',
                    icon='fa-google',
                    category='Reports',
                    category_icon='fa-google',
                    category_label=__('Reports'))
Ejemplo n.º 20
0
from ..models.connector import AppsFlyerConnector


# for show all Connectors in system
class AppsFlyerConnectorView(SupersetModelView, DeleteMixin):
    """View For Connector Model."""

    datamodel = SQLAInterface(AppsFlyerConnector)

    list_columns = ['name', 'app_id', 'admin_data_sources']

    add_columns = ['name', 'app_id', 'api_token', 'url_pat']

    edit_columns = add_columns

    @action('web_test', 'web_test', 'web_test', 'fa-rocket')
    def web_test(self, items):
        if not isinstance(items, list):
            items = [items]
        items[0].web_test()
        return redirect('appsflyerconnectorview/list/')


# Register ConnectorView Model View
appbuilder.add_view(AppsFlyerConnectorView,
                    'AppsFlyer',
                    icon='fa-random',
                    category='Connectors',
                    category_icon='fa-rocket',
                    category_label=__('Connectors'))
Ejemplo n.º 21
0
    def pre_add(self, cluster):
        security_manager.merge_perm('database_access', cluster.perm)

    def pre_update(self, cluster):
        self.pre_add(cluster)

    def _delete(self, pk):
        DeleteMixin._delete(self, pk)


appbuilder.add_view(
    DruidClusterModelView,
    name='Druid Clusters',
    label=__('Druid Clusters'),
    icon='fa-cubes',
    category='Sources',
    category_label=__('Sources'),
    category_icon='fa-database',
)


class DruidDatasourceModelView(DatasourceModelView, DeleteMixin, YamlExportMixin):  # noqa
    datamodel = SQLAInterface(models.DruidDatasource)

    list_title = _('List Druid Datasource')
    show_title = _('Show Druid Datasource')
    add_title = _('Add Druid Datasource')
    edit_title = _('Edit Druid Datasource')

    list_columns = [
Ejemplo n.º 22
0
            obj.end_dttm = obj.start_dttm
        elif obj.end_dttm < obj.start_dttm:
            raise Exception(
                'Annotation end time must be no earlier than start time.')

    def pre_update(self, obj):
        self.pre_add(obj)


class AnnotationLayerModelView(SupersetModelView, DeleteMixin):
    datamodel = SQLAInterface(AnnotationLayer)
    list_columns = ['id', 'name']
    edit_columns = ['name', 'descr']
    add_columns = edit_columns


appbuilder.add_view(AnnotationLayerModelView,
                    'Annotation Layers',
                    label=__('Annotation Layers'),
                    icon='fa-comment',
                    category='Manage',
                    category_label=__('Manage'),
                    category_icon='')
appbuilder.add_view(AnnotationModelView,
                    'Annotations',
                    label=__('Annotations'),
                    icon='fa-comments',
                    category='Manage',
                    category_label=__('Manage'),
                    category_icon='')
Ejemplo n.º 23
0
    @expose('/api/<path>', methods=['GET', 'POST'])
    def api(self, path):
        """ Proxy frontend request to bblfsh-web server """
        resp = requests.request(method=request.method,
                                url='%s/api/%s' % (BBLFSH_WEB_ADDRESS, path),
                                headers={
                                    key: value
                                    for (key, value) in request.headers
                                    if key != 'Host'
                                },
                                data=request.get_data(),
                                cookies=request.cookies,
                                allow_redirects=False)

        excluded_headers = [
            'content-encoding', 'content-length', 'transfer-encoding',
            'connection'
        ]
        headers = [(name, value) for (name, value) in resp.raw.headers.items()
                   if name.lower() not in excluded_headers]

        response = Response(resp.content, resp.status_code, headers)
        return response


appbuilder.add_view(Bblfsh,
                    "UAST",
                    label=_('UAST'),
                    category_icon='fa-steam',
                    icon='fa-steam')
Ejemplo n.º 24
0
        'broker_endpoint': _("Broker Endpoint"),
    }

    def pre_add(self, cluster):
        security.merge_perm(sm, 'database_access', cluster.perm)

    def pre_update(self, cluster):
        self.pre_add(cluster)

    def _delete(self, pk):
        DeleteMixin._delete(self, pk)

appbuilder.add_view(
    DruidClusterModelView,
    name="Druid Clusters",
    label=__("Druid Clusters"),
    icon="fa-cubes",
    category="Sources",
    category_label=__("Sources"),
    category_icon='fa-database',)


class DruidDatasourceModelView(DatasourceModelView, DeleteMixin):  # noqa
    datamodel = SQLAInterface(models.DruidDatasource)

    list_title = _('List Druid Datasource')
    show_title = _('Show Druid Datasource')
    add_title = _('Add Druid Datasource')
    edit_title = _('Edit Druid Datasource')

    list_widget = ListWidgetWithCheckboxes
    list_columns = [
Ejemplo n.º 25
0
    add_title = _('Add Query')
    edit_title = _('Edit Query')

    list_columns = ['user', 'database', 'status', 'start_time', 'end_time']
    label_columns = {
        'user': _('User'),
        'database': _('Database'),
        'status': _('Status'),
        'start_time': _('Start Time'),
        'end_time': _('End Time'),
    }


appbuilder.add_view(QueryView,
                    'Queries',
                    label=__('Queries'),
                    category='Manage',
                    category_label=__('Manage'),
                    icon='fa-search')


class SavedQueryView(SupersetModelView, DeleteMixin):
    datamodel = SQLAInterface(SavedQuery)

    list_title = _('List Saved Query')
    show_title = _('Show Saved Query')
    add_title = _('Add Saved Query')
    edit_title = _('Edit Saved Query')

    list_columns = [
        'label', 'user', 'database', 'schema', 'description', 'modified',
        'pop_tab_link'
Ejemplo n.º 26
0
            conn.close()
        except Exception as e:
            message = text_type(e)
            flash(
                message,
                'danger')
            return redirect('/loadsql/form')

        # Go back to welcome page / splash screen
        message = _(f'SQL file "{sql_filename}" uploaded database "{form.db_name.data}"')
        flash(message, 'info')
        return redirect('/tablemodelview/list/')


appbuilder.add_view(LoadSQL, 'LoadSQL',
                    category='Sources',
                    icon='fa-upload',)

# Reorganize Sources.
# Move UploadCSV to the end
menu = appbuilder.menu.menu[2]
i = [x.name for x in menu.childs].index('Upload a CSV')
csv = appbuilder.menu.menu[2].childs.pop(i)
appbuilder.menu.menu[2].childs.append(csv)
# Remove double hyphen
for i in range(1, len(menu.childs)):
    if menu.childs[i-1].name == '-' and menu.childs[i].name == '-':
        menu.childs.pop(i-1)
        menu.childs.pop(i-1)
        break
# Change table icon
Ejemplo n.º 27
0
        """Simple hack to redirect to explore view after saving"""
        resp = super(TableModelView, self).edit(pk)
        if isinstance(resp, basestring):
            return resp
        return redirect('/superset/explore/table/{}/'.format(pk))

    @action(
        'refresh',
        __('Refresh Metadata'),
        __('Refresh column metadata'),
        'fa-refresh')
    def refresh(self, tables):
        for t in tables:
            t.fetch_metadata()
        msg = _(
            'Metadata refreshed for the following table(s): %(tables)s',
            tables=', '.join([t.table_name for t in tables]))
        flash(msg, 'info')
        return redirect('/tablemodelview/list/')


appbuilder.add_view(
    TableModelView,
    'Tables',
    label=__('Tables'),
    category='Sources',
    category_label=__('Sources'),
    icon='fa-table',)

appbuilder.add_separator('Sources')
Ejemplo n.º 28
0
    list_columns = [
        'ad.name',
        'date_stop',
        'impression_device',
        'mobile_app_installs',
        'cost_per_mobile_app_installs',
        'mobile_app_purchases',
        'cost_per_mobile_app_purchases',
        'cost',
    ]


# Register AdAccount Model View
appbuilder.add_view(AdAccountView,
                    'AdAccounts',
                    icon='fa-facebook',
                    category='Reports',
                    category_icon='fa-table',
                    category_label=__('Reports'))

# Register AdCampaign Model View
appbuilder.add_view(AdCampaignView,
                    'AdCampaigns',
                    icon='fa-facebook',
                    category='Reports',
                    category_icon='fa-table',
                    category_label=__('Reports'))

# Register AdSet Model View
appbuilder.add_view(AdSetView,
                    'AdSets',
                    icon='fa-facebook',
Ejemplo n.º 29
0
    order_columns = ["status", "start_time", "end_time"]
    base_filters = [["id", QueryFilter, lambda: []]]
    label_columns = {
        "user": _("User"),
        "username": _("User"),
        "database_name": _("Database"),
        "status": _("Status"),
        "start_time": _("Start Time"),
        "end_time": _("End Time"),
    }


appbuilder.add_view(
    QueryView,
    "Queries",
    label=__("Queries"),
    category="Manage",
    category_label=__("Manage"),
    icon="fa-search",
)


class SavedQueryView(SupersetModelView, DeleteMixin):
    datamodel = SQLAInterface(SavedQuery)

    list_title = _("List Saved Query")
    show_title = _("Show Saved Query")
    add_title = _("Add Saved Query")
    edit_title = _("Edit Saved Query")

    list_columns = [
        "label",
Ejemplo n.º 30
0
        widget = super()._add()
        if widget and widget.get('add', {}) and widget['add'].template_args:
            form = widget['add'].template_args['form']
            form.roles._get_object_list()
            form.roles._object_list = [
                i for i in form.roles._object_list if i[1].name == 'Viewer'
            ]
        return widget

    def _edit(self, pk):
        item = self.datamodel.get(pk, self._base_filters)
        if not item:
            abort(404)

        if 'Viewer' not in [i.name for i in item.roles]:
            abort(404)

        # We're limiting the restriction to the UI to avoid editors from assigning bad permissions.
        # Editors should be trusted not to maliciously send bad arguments for roles.
        widget = super()._edit(pk)
        if widget and widget.get('edit', {}) and widget['edit'].template_args:
            form = widget['edit'].template_args['form']
            form.roles._get_object_list()
            form.roles._object_list = [
                i for i in form.roles._object_list if i[1].name == 'Viewer'
            ]
        return widget


appbuilder.add_view(EditorUserView, _('Manage Viewers'), icon='fa-user')
Ejemplo n.º 31
0
    def edit(self, pk):
        """Simple hack to redirect to explore view after saving"""
        resp = super(TableModelView, self).edit(pk)
        if isinstance(resp, basestring):
            return resp
        return redirect('/superset/explore/table/{}/'.format(pk))

    @action('refresh', __('Refresh Metadata'), __('Refresh column metadata'),
            'fa-refresh')
    def refresh(self, tables):
        if not isinstance(tables, list):
            tables = [tables]
        for t in tables:
            t.fetch_metadata()
        msg = _('Metadata refreshed for the following table(s): %(tables)s',
                tables=', '.join([t.table_name for t in tables]))
        flash(msg, 'info')
        return redirect('/tablemodelview/list/')


appbuilder.add_view(
    TableModelView,
    'Tables',
    label=__('Tables'),
    category='Sources',
    category_label=__('Sources'),
    icon='fa-table',
)

appbuilder.add_separator('Sources')
Ejemplo n.º 32
0
# 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.
# pylint: disable=C,R,W
from flask_appbuilder.models.sqla.interface import SQLAInterface
from flask_babel import gettext as __

import superset.models.core as models
from superset import app, appbuilder
from superset.views.base import SupersetModelView

from . import LogMixin


class LogModelView(LogMixin, SupersetModelView):
    datamodel = SQLAInterface(models.Log)


if (not app.config.get("FAB_ADD_SECURITY_VIEWS") is False
        or app.config.get("SUPERSET_LOG_VIEW") is False):
    appbuilder.add_view(
        LogModelView,
        "Action Log",
        label=__("Action Log"),
        category="Security",
        category_label=__("Security"),
        icon="fa-list-ol",
    )
Ejemplo n.º 33
0
    def pre_add(self, cluster):
        security_manager.merge_perm('database_access', cluster.perm)

    def pre_update(self, cluster):
        self.pre_add(cluster)

    def _delete(self, pk):
        DeleteMixin._delete(self, pk)


appbuilder.add_view(
    DruidClusterModelView,
    name='Druid Clusters',
    label=__('Druid Clusters'),
    icon='fa-cubes',
    category='Sources',
    category_label=__('Sources'),
    category_icon='fa-database',
)


class DruidDatasourceModelView(DatasourceModelView, DeleteMixin,
                               YamlExportMixin):  # noqa
    datamodel = SQLAInterface(models.DruidDatasource)

    list_title = _('List Druid Datasource')
    show_title = _('Show Druid Datasource')
    add_title = _('Add Druid Datasource')
    edit_title = _('Edit Druid Datasource')
Ejemplo n.º 34
0
        return self.render_template(
            'superset/basic.html',
            entry='uast',
            bootstrap_data=json.dumps(d),
        )

    @has_access
    @expose('/api/<path>', methods=['GET', 'POST'])
    def api(self, path):
        """ Proxy frontend request to bblfsh-web server """
        resp = requests.request(
            method=request.method,
            url='%s/api/%s' % (BBLFSH_WEB_ADDRESS, path),
            headers={key: value for (key, value)
                     in request.headers if key != 'Host'},
            data=request.get_data(),
            cookies=request.cookies,
            allow_redirects=False)

        excluded_headers = ['content-encoding',
                            'content-length', 'transfer-encoding', 'connection']
        headers = [(name, value) for (name, value) in resp.raw.headers.items()
                   if name.lower() not in excluded_headers]

        response = Response(resp.content, resp.status_code, headers)
        return response


appbuilder.add_view(Bblfsh, 'UAST', label=_('UAST'),
                    category_icon='fa-tree', icon='fa-tree')
Ejemplo n.º 35
0
                  "As part of this two phase configuration "
                  "process, you should now click the edit button by "
                  "the new table to configure it."), "info")

    def post_update(self, table):
        self.post_add(table, flash_message=False)

    def _delete(self, pk):
        DeleteMixin._delete(self, pk)

    @expose('/edit/<pk>', methods=['GET', 'POST'])
    @has_access
    def edit(self, pk):
        """Simple hack to redirect to explore view after saving"""
        resp = super(TableModelView, self).edit(pk)
        if isinstance(resp, basestring):
            return resp
        return redirect('/superset/explore/table/{}/'.format(pk))


appbuilder.add_view(
    TableModelView,
    "Tables",
    label=__("Tables"),
    category="Sources",
    category_label=__("Sources"),
    icon='fa-table',
)

appbuilder.add_separator("Sources")
Ejemplo n.º 36
0
# flask_appbuilder
from flask_appbuilder.models.sqla.interface import SQLAInterface

# flask_babel
from flask_babel import gettext as __

# superset
from superset import appbuilder
from superset.views.base import SupersetModelView
from superset.views.base import DeleteMixin

# locale
from bit.models import Identify


class IdentifyView(SupersetModelView, DeleteMixin):
    """View For Analytics Identify Model."""

    datamodel = SQLAInterface(Identify)


# Register ConnectorView Model View
appbuilder.add_view(
    IdentifyView,
    'identifys',
    # href='/connections',
    icon='fa-random',
    category='Identify',
    category_icon='fa-random',
    category_label=__('Identify'))