mirror of
https://github.com/apache/superset.git
synced 2026-04-19 16:14:52 +00:00
* Sparkline dates aren't formatting in Time Series Table (#6976) * Exclude venv for python linter to ignore * Fix NaN error * Fix the white background shown in SQL editor on drag (#7021) This PR sets the background-color css property on `.ace_scroller` instead of `.ace_content` to prevent the white background shown during resizing of the SQL editor before drag ends. * Show tooltip with time frame (#6979) * Fix time filter control (#6978) * Enhancement of query context and object. (#6962) * added more functionalities for query context and object. * fixed cache logic * added default value for groupby * updated comments and removed print (cherry picked from commitd5b9795f87) * [fix] /superset/slice/id url is too long (#6989) (cherry picked from commit6a4d507ab6) * [WIP] fix user specified JSON metadata not updating dashboard on refresh (#7027) (cherry picked from commitcc58f0e661) * feat: add ability to change font size in big number (#7003) * Add ability to change font sizes in Big Number * rename big number to header * Add comment to clarify font size values * Allow LIMIT to be specified in parameters (#7052) * [fix] Cursor jumping when editing chart and dashboard titles (#7038) (cherry picked from commitfc1770f7b7) * Changing time table viz to pass formatTime a date (#7020) (cherry picked from commit7f3c145b1f) * [db-engine-spec] Aligning Hive/Presto partition logic (#7007) (cherry picked from commit05be866117) * [fix] explore chart from dashboard missed slice title (#7046) (cherry picked from commita6d48d4052) * fix inaccurate data calculation with adata rolling and contribution (#7035) (cherry picked from commit0782e831cd) * Adding warning message for sqllab save query (#7028) (cherry picked from commitead3d48133) * [datasource] Ensuring consistent behavior of datasource editing/saving. (#7037) * Update datasource.py * Update datasource.py (cherry picked from commitc771625f10) * [csv-upload] Fixing message encoding (#6971) (cherry picked from commit48431ab5b9) * [sql-parse] Fixing LIMIT exceptions (#6963) (cherry picked from commit3e076cb60b) * Adding custom control overrides (#6956) * Adding extraOverrides to line chart * Updating extraOverrides to fit with more cases * Moving extraOverrides to index.js * Removing webpack-merge in package.json * Fixing metrics control clearing metric (cherry picked from commite6194051f4) * [sqlparse] Fixing table name extraction for ill-defined query (#7029) (cherry picked from commit07c340cf82) * [missing values] Removing replacing missing values (#4905) (cherry picked from commit61add606ca) * [SQL Lab] Improved query and results tabs rendering reliability (#7082) closes #7080 (cherry picked from commit9b58e9f492) * Fix filter_box migration PR #6523 (#7066) * Fix filter_box migration PR #6523 * Fix druid-related bug (cherry picked from commitb210742ad2) * SQL editor layout makeover (#7102) This PR includes the following layout and css tweaks: - Using flex to layout the north and south sub panes of query pane so resizing works properly in both Chrome and Firefox - Removal of necessary wrapper divs and tweaking of css in sql lab so we can scroll to the bottom of both the table list and the results pane - Make sql lab's content not overflow vertically and layout the query result area to eliminate double scroll bars - css tweaks on the basic.html page so the loading animation appears in the center of the page across the board (cherry picked from commit71f1bbd2ec) * [forms] Fix handling of NULLs (cherry picked from commite83a07d3df) * handle null column_name in sqla and druid models (cherry picked from commit2ff721ae07) * Use metric name instead of metric in filter box (#7106) (cherry picked from commit003364e74e) * Bump python lib croniter to an existing version (#7132) Package maintainers should really never delete packages, but it appears this happened with croniter and resulted in breaking our builds. This PR bumps to a more recent existing version of the library (cherry picked from commit215ed392a1) * Revert PR #6933 (#7162) * Add decorator for etag cache * Fetch charts with GET * Small fixes * Fix typo * Compute correct cache key; fix logging * Check perms on cached response * Revert change * If perms fail, return naked response * Fix lint * Compute cache key from all form data * Pass extra_filters in GET request * Fix pylint * Fix flake8 * Use ETags even if no cache is set * Handle adhoc filters * Raise in debug mode * Rename actions * Fix integration tests * Do POST request on new charts * Set extra/adhoc filters only in GET requests * Raise if check_perms fails * Refactor auth * Fix flake8 * Fix js unit tests * Fix js unit tests that fail in lyftga * Fix js * Sparkline dates aren't formatting in Time Series Table (#6976) * Exclude venv for python linter to ignore * Fix NaN error * Changing time table viz to pass formatTime a date (#7020) (cherry picked from commit7f3c145b1f) * SQL editor layout makeover (#7102) This PR includes the following layout and css tweaks: - Using flex to layout the north and south sub panes of query pane so resizing works properly in both Chrome and Firefox - Removal of necessary wrapper divs and tweaking of css in sql lab so we can scroll to the bottom of both the table list and the results pane - Make sql lab's content not overflow vertically and layout the query result area to eliminate double scroll bars - css tweaks on the basic.html page so the loading animation appears in the center of the page across the board (cherry picked from commit71f1bbd2ec) * Add decorator for etag cache * Fetch charts with GET * Small fixes * Fix typo * Compute correct cache key; fix logging * Check perms on cached response * Revert change * If perms fail, return naked response * Fix lint * Compute cache key from all form data * Pass extra_filters in GET request * Fix pylint * Fix flake8 * Use ETags even if no cache is set * Handle adhoc filters * Raise in debug mode * Rename actions * Fix integration tests * Do POST request on new charts * Set extra/adhoc filters only in GET requests * Raise if check_perms fails * Refactor auth * Fix flake8 * Fix js unit tests * Fix js unit tests that fail in lyftga * Fix js * Fix bad merge * Use far future when max_age=0
191 lines
6.2 KiB
Python
191 lines
6.2 KiB
Python
# 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.
|
|
# pylint: disable=C,R,W
|
|
from collections import defaultdict
|
|
from urllib import parse
|
|
|
|
from flask import g, request
|
|
from flask_appbuilder.security.sqla import models as ab_models
|
|
import simplejson as json
|
|
|
|
from superset import app, db, viz
|
|
from superset.connectors.connector_registry import ConnectorRegistry
|
|
from superset.legacy import cast_form_data, update_time_range
|
|
import superset.models.core as models
|
|
|
|
|
|
FORM_DATA_KEY_BLACKLIST = []
|
|
if not app.config.get('ENABLE_JAVASCRIPT_CONTROLS'):
|
|
FORM_DATA_KEY_BLACKLIST = [
|
|
'js_tooltip',
|
|
'js_onclick_href',
|
|
'js_data_mutator',
|
|
]
|
|
|
|
|
|
def bootstrap_user_data(username=None, include_perms=False):
|
|
if not username:
|
|
username = g.user.username
|
|
|
|
user = (
|
|
db.session.query(ab_models.User)
|
|
.filter_by(username=username)
|
|
.one()
|
|
)
|
|
|
|
payload = {
|
|
'username': user.username,
|
|
'firstName': user.first_name,
|
|
'lastName': user.last_name,
|
|
'userId': user.id,
|
|
'isActive': user.is_active,
|
|
'createdOn': user.created_on.isoformat(),
|
|
'email': user.email,
|
|
}
|
|
|
|
if include_perms:
|
|
roles, permissions = get_permissions(user)
|
|
payload['roles'] = roles
|
|
payload['permissions'] = permissions
|
|
|
|
return payload
|
|
|
|
|
|
def get_permissions(user):
|
|
if not user.roles:
|
|
raise AttributeError('User object does not have roles')
|
|
|
|
roles = {}
|
|
permissions = defaultdict(set)
|
|
for role in user.roles:
|
|
perms = set()
|
|
for perm in role.permissions:
|
|
if perm.permission and perm.view_menu:
|
|
perms.add(
|
|
(perm.permission.name, perm.view_menu.name),
|
|
)
|
|
if perm.permission.name in ('datasource_access',
|
|
'database_access'):
|
|
permissions[perm.permission.name].add(perm.view_menu.name)
|
|
roles[role.name] = [
|
|
[perm.permission.name, perm.view_menu.name]
|
|
for perm in role.permissions
|
|
if perm.permission and perm.view_menu
|
|
]
|
|
|
|
return roles, permissions
|
|
|
|
|
|
def get_viz(
|
|
slice_id=None,
|
|
form_data=None,
|
|
datasource_type=None,
|
|
datasource_id=None,
|
|
force=False,
|
|
):
|
|
if slice_id:
|
|
slc = (
|
|
db.session.query(models.Slice)
|
|
.filter_by(id=slice_id)
|
|
.one()
|
|
)
|
|
return slc.get_viz()
|
|
else:
|
|
viz_type = form_data.get('viz_type', 'table')
|
|
datasource = ConnectorRegistry.get_datasource(
|
|
datasource_type, datasource_id, db.session)
|
|
viz_obj = viz.viz_types[viz_type](
|
|
datasource,
|
|
form_data=form_data,
|
|
force=force,
|
|
)
|
|
return viz_obj
|
|
|
|
|
|
def get_form_data(slice_id=None, use_slice_data=False):
|
|
form_data = {}
|
|
post_data = request.form.get('form_data')
|
|
request_args_data = request.args.get('form_data')
|
|
# Supporting POST
|
|
if post_data:
|
|
form_data.update(json.loads(post_data))
|
|
# request params can overwrite post body
|
|
if request_args_data:
|
|
form_data.update(json.loads(request_args_data))
|
|
|
|
url_id = request.args.get('r')
|
|
if url_id:
|
|
saved_url = db.session.query(models.Url).filter_by(id=url_id).first()
|
|
if saved_url:
|
|
url_str = parse.unquote_plus(
|
|
saved_url.url.split('?')[1][10:], encoding='utf-8', errors=None)
|
|
url_form_data = json.loads(url_str)
|
|
# allow form_date in request override saved url
|
|
url_form_data.update(form_data)
|
|
form_data = url_form_data
|
|
|
|
if request.args.get('viz_type'):
|
|
# Converting old URLs
|
|
form_data = cast_form_data(form_data)
|
|
|
|
form_data = {
|
|
k: v
|
|
for k, v in form_data.items()
|
|
if k not in FORM_DATA_KEY_BLACKLIST
|
|
}
|
|
|
|
# When a slice_id is present, load from DB and override
|
|
# the form_data from the DB with the other form_data provided
|
|
slice_id = form_data.get('slice_id') or slice_id
|
|
slc = None
|
|
|
|
# Check if form data only contains slice_id and additional filters
|
|
valid_keys = ['slice_id', 'extra_filters', 'adhoc_filters']
|
|
valid_slice_id = all(key in valid_keys for key in form_data)
|
|
|
|
# Include the slice_form_data if request from explore or slice calls
|
|
# or if form_data only contains slice_id and additional filters
|
|
if slice_id and (use_slice_data or valid_slice_id):
|
|
slc = db.session.query(models.Slice).filter_by(id=slice_id).one_or_none()
|
|
if slc:
|
|
slice_form_data = slc.form_data.copy()
|
|
slice_form_data.update(form_data)
|
|
form_data = slice_form_data
|
|
|
|
update_time_range(form_data)
|
|
|
|
return form_data, slc
|
|
|
|
|
|
def get_datasource_info(datasource_id, datasource_type, form_data):
|
|
"""Compatibility layer for handling of datasource info
|
|
|
|
datasource_id & datasource_type used to be passed in the URL
|
|
directory, now they should come as part of the form_data,
|
|
This function allows supporting both without duplicating code"""
|
|
datasource = form_data.get('datasource', '')
|
|
if '__' in datasource:
|
|
datasource_id, datasource_type = datasource.split('__')
|
|
# The case where the datasource has been deleted
|
|
datasource_id = None if datasource_id == 'None' else datasource_id
|
|
|
|
if not datasource_id:
|
|
raise Exception(
|
|
'The datasource associated with this chart no longer exists')
|
|
datasource_id = int(datasource_id)
|
|
return datasource_id, datasource_type
|