Show scheduled queries (#7545)

* Show scheduled queries

* Remove column

* Secure views

* Add import

* Fix unit tests

* Reuse existing db connection from view

* Remove unnecessary import
This commit is contained in:
Beto Dealmeida
2019-05-17 17:31:02 -07:00
committed by GitHub
parent f0f719cb8d
commit dcafabd183
6 changed files with 118 additions and 8 deletions

View File

@@ -0,0 +1,43 @@
/**
* 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.
*/
import React from 'react';
import ReactDom from 'react-dom';
import Form from 'react-jsonschema-form';
const scheduleInfoContainer = document.getElementById('schedule-info');
const bootstrapData = JSON.parse(scheduleInfoContainer.getAttribute('data-bootstrap'));
const schemas = bootstrapData.common.feature_flags.SCHEDULED_QUERIES;
const scheduleInfo = bootstrapData.common.extra_json.schedule_info;
if (scheduleInfo && schemas) {
// hide instructions when showing schedule info
schemas.JSONSCHEMA.description = '';
ReactDom.render(
<Form
schema={schemas.JSONSCHEMA}
uiSchema={schemas.UISCHEMA}
formData={scheduleInfo}
disabled
>
<br />
</Form>,
scheduleInfoContainer,
);
}

View File

@@ -119,6 +119,7 @@ const config = {
sqllab: addPreamble('/src/SqlLab/index.jsx'),
welcome: addPreamble('/src/welcome/index.jsx'),
profile: addPreamble('/src/profile/index.jsx'),
showSavedQuery: [path.join(APP_DIR, '/src/showSavedQuery/index.jsx')],
},
output,
optimization: {

View File

@@ -0,0 +1,35 @@
{#
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/model/show.html" %}
{% block show_form %}
{{ super() }}
<div
id="schedule-info"
style="padding: 0 10px;"
data-bootstrap="{{ bootstrap_data }}"
></div>
{% endblock %}
{% block tail_js %}
{{ super() }}
{% with filename="showSavedQuery" %}
{% include "superset/partials/_script_tag.html" %}
{% endwith %}
{% endblock %}

View File

@@ -153,7 +153,7 @@ class BaseSupersetView(BaseView):
status=status,
mimetype='application/json')
def common_bootsrap_payload(self):
def common_bootstrap_payload(self):
"""Common data always sent to the client"""
messages = get_flashed_messages(with_categories=True)
locale = str(get_locale())

View File

@@ -1372,7 +1372,7 @@ class Superset(BaseSupersetView):
'standalone': standalone,
'user_id': user_id,
'forced_height': request.args.get('height'),
'common': self.common_bootsrap_payload(),
'common': self.common_bootstrap_payload(),
}
table_name = datasource.table_name \
if datasource_type == 'table' \
@@ -2231,7 +2231,7 @@ class Superset(BaseSupersetView):
'user_id': g.user.get_id(),
'dashboard_data': dashboard_data,
'datasources': {ds.uid: ds.data for ds in datasources},
'common': self.common_bootsrap_payload(),
'common': self.common_bootstrap_payload(),
'editMode': edit_mode,
}
@@ -2919,7 +2919,7 @@ class Superset(BaseSupersetView):
payload = {
'user': bootstrap_user_data(),
'common': self.common_bootsrap_payload(),
'common': self.common_bootstrap_payload(),
}
return self.render_template(
@@ -2938,7 +2938,7 @@ class Superset(BaseSupersetView):
payload = {
'user': bootstrap_user_data(username, include_perms=True),
'common': self.common_bootsrap_payload(),
'common': self.common_bootstrap_payload(),
}
return self.render_template(
@@ -2954,7 +2954,7 @@ class Superset(BaseSupersetView):
"""SQL Editor"""
d = {
'defaultDbId': config.get('SQLLAB_DEFAULT_DBID'),
'common': self.common_bootsrap_payload(),
'common': self.common_bootstrap_payload(),
}
return self.render_template(
'superset/basic.html',

View File

@@ -20,13 +20,15 @@ from typing import Callable
from flask import g, redirect
from flask_appbuilder import expose
from flask_appbuilder.models.sqla.interface import SQLAInterface
from flask_appbuilder.security.decorators import has_access
from flask_appbuilder.security.decorators import has_access, has_access_api
from flask_babel import gettext as __
from flask_babel import lazy_gettext as _
from flask_sqlalchemy import BaseQuery
import simplejson as json
from superset import appbuilder, security_manager
from superset import appbuilder, get_feature_flags, security_manager
from superset.models.sql_lab import Query, SavedQuery
from superset.utils import core as utils
from .base import BaseSupersetView, DeleteMixin, SupersetFilter, SupersetModelView
@@ -107,12 +109,36 @@ class SavedQueryView(SupersetModelView, DeleteMixin):
'changed_on': _('Changed on'),
}
show_template = 'superset/models/savedquery/show.html'
def pre_add(self, obj):
obj.user = g.user
def pre_update(self, obj):
self.pre_add(obj)
@has_access
@expose('show/<pk>')
def show(self, pk):
pk = self._deserialize_pk_if_composite(pk)
widgets = self._show(pk)
extra_json = self.datamodel.get(pk).extra_json
payload = {
'common': {
'feature_flags': get_feature_flags(),
'extra_json': json.loads(extra_json),
},
}
return self.render_template(
self.show_template,
pk=pk,
title=self.show_title,
widgets=widgets,
related_views=self._related_views,
bootstrap_data=json.dumps(payload, default=utils.json_iso_dttm_ser),
)
class SavedQueryViewApi(SavedQueryView):
list_columns = [
@@ -123,6 +149,11 @@ class SavedQueryViewApi(SavedQueryView):
add_columns = show_columns
edit_columns = add_columns
@has_access_api
@expose('show/<pk>')
def show(self, pk):
return super().show(pk)
appbuilder.add_view_no_menu(SavedQueryViewApi)
appbuilder.add_view_no_menu(SavedQueryView)