Skip to content

Commit

Permalink
Merge branch 'master' into remove_repeated_line
Browse files Browse the repository at this point in the history
  • Loading branch information
timifasubaa authored Sep 19, 2017
2 parents 4e76772 + c5252d0 commit 913e0f5
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 139 deletions.
24 changes: 14 additions & 10 deletions superset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
from superset.connectors.connector_registry import ConnectorRegistry
from superset import utils, config # noqa


APP_DIR = os.path.dirname(__file__)
CONFIG_MODULE = os.environ.get('SUPERSET_CONFIG', 'superset.config')

with open(APP_DIR + '/static/assets/backendSync.json', 'r') as f:
frontend_config = json.load(f)


app = Flask(__name__)
app.config.from_object(CONFIG_MODULE)
conf = app.config
Expand All @@ -53,14 +51,16 @@ def get_manifest_file(filename):
parse_manifest_json()
return '/static/assets/dist/' + manifest.get(filename, '')


parse_manifest_json()


@app.context_processor
def get_js_manifest():
return dict(js_manifest=get_manifest_file)

#################################################################

#################################################################

for bp in conf.get('BLUEPRINTS'):
try:
Expand Down Expand Up @@ -100,10 +100,11 @@ def get_js_manifest():

if app.config.get('ENABLE_TIME_ROTATE'):
logging.getLogger().setLevel(app.config.get('TIME_ROTATE_LOG_LEVEL'))
handler = TimedRotatingFileHandler(app.config.get('FILENAME'),
when=app.config.get('ROLLOVER'),
interval=app.config.get('INTERVAL'),
backupCount=app.config.get('BACKUP_COUNT'))
handler = TimedRotatingFileHandler(
app.config.get('FILENAME'),
when=app.config.get('ROLLOVER'),
interval=app.config.get('INTERVAL'),
backupCount=app.config.get('BACKUP_COUNT'))
logging.getLogger().addHandler(handler)

if app.config.get('ENABLE_CORS'):
Expand All @@ -114,17 +115,18 @@ def get_js_manifest():
app.wsgi_app = ProxyFix(app.wsgi_app)

if app.config.get('ENABLE_CHUNK_ENCODING'):
class ChunkedEncodingFix(object):

class ChunkedEncodingFix(object):
def __init__(self, app):
self.app = app

def __call__(self, environ, start_response):
# Setting wsgi.input_terminated tells werkzeug.wsgi to ignore
# content-length and read the stream till the end.
if 'chunked' == environ.get('HTTP_TRANSFER_ENCODING', '').lower():
if environ.get('HTTP_TRANSFER_ENCODING', '').lower() == u'chunked':
environ['wsgi.input_terminated'] = True
return self.app(environ, start_response)

app.wsgi_app = ChunkedEncodingFix(app.wsgi_app)

if app.config.get('UPLOAD_FOLDER'):
Expand All @@ -142,8 +144,10 @@ class MyIndexView(IndexView):
def index(self):
return redirect('/superset/welcome')


appbuilder = AppBuilder(
app, db.session,
app,
db.session,
base_template='superset/base.html',
indexview=MyIndexView,
security_manager_class=app.config.get("CUSTOM_SECURITY_MANAGER"))
Expand Down
8 changes: 4 additions & 4 deletions superset/assets/javascripts/explore/stores/controls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ const timeColumnOption = {
'account'),
};
const sortAxisChoices = [
['alpha_asc', 'Alphabetical ascending'],
['alpha_desc', 'Alphabetical descending'],
['value_asc', 'Value ascending'],
['value_desc', 'Value descending'],
['alpha_asc', 'Axis ascending'],
['alpha_desc', 'Axis descending'],
['value_asc', 'sum(value) ascending'],
['value_desc', 'sum(value) descending'],
];

const groupByControl = {
Expand Down
18 changes: 13 additions & 5 deletions superset/assets/visualizations/heatmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import { colorScalerFactory } from '../javascripts/modules/colors';
import '../stylesheets/d3tip.css';
import './heatmap.css';

function cmp(a, b) {
return a > b ? 1 : -1;
}

// Inspired from http://bl.ocks.org/mbostock/3074470
// https://jsfiddle.net/cyril123/h0reyumq/
function heatmapVis(slice, payload) {
Expand Down Expand Up @@ -52,17 +56,21 @@ function heatmapVis(slice, payload) {

function ordScale(k, rangeBands, sortMethod) {
let domain = {};
const actualKeys = {}; // hack to preserve type of keys when number
data.forEach((d) => {
domain[d[k]] = domain[d[k]] || 0 + d.v;
domain[d[k]] = (domain[d[k]] || 0) + d.v;
actualKeys[d[k]] = d[k];
});
// Not usgin object.keys() as it converts to strings
const keys = Object.keys(actualKeys).map(s => actualKeys[s]);
if (sortMethod === 'alpha_asc') {
domain = Object.keys(domain).sort();
domain = keys.sort(cmp);
} else if (sortMethod === 'alpha_desc') {
domain = Object.keys(domain).sort().reverse();
domain = keys.sort(cmp).reverse();
} else if (sortMethod === 'value_desc') {
domain = Object.keys(domain).sort((d1, d2) => domain[d2] - domain[d1]);
domain = Object.keys(domain).sort((a, b) => domain[a] > domain[b] ? -1 : 1);
} else if (sortMethod === 'value_asc') {
domain = Object.keys(domain).sort((d1, d2) => domain[d1] - domain[d2]);
domain = Object.keys(domain).sort((a, b) => domain[b] > domain[a] ? -1 : 1);
}

if (k === 'y' && rangeBands) {
Expand Down
8 changes: 3 additions & 5 deletions superset/db_engine_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def fetch_result_sets(cls, db, datasource_type, force=False):
result_set_df = db.get_df(
"""SELECT table_schema, table_name FROM INFORMATION_SCHEMA.{}S
ORDER BY concat(table_schema, '.', table_name)""".format(
datasource_type.upper()), None)
datasource_type.upper()), None)
result_sets = defaultdict(list)
for unused, row in result_set_df.iterrows():
result_sets[row['table_schema']].append(row['table_name'])
Expand Down Expand Up @@ -1003,8 +1003,7 @@ def convert_dttm(cls, target_type, dttm):
tt = target_type.upper()
if tt == 'DATE':
return "'{}'".format(dttm.strftime('%Y-%m-%d'))
else:
return "'{}'".format(dttm.strftime('%Y-%m-%d %H:%M:%S'))
return "'{}'".format(dttm.strftime('%Y-%m-%d %H:%M:%S'))


class ImpalaEngineSpec(BaseEngineSpec):
Expand All @@ -1028,8 +1027,7 @@ def convert_dttm(cls, target_type, dttm):
tt = target_type.upper()
if tt == 'DATE':
return "'{}'".format(dttm.strftime('%Y-%m-%d'))
else:
return "'{}'".format(dttm.strftime('%Y-%m-%d %H:%M:%S'))
return "'{}'".format(dttm.strftime('%Y-%m-%d %H:%M:%S'))


engines = {
Expand Down
4 changes: 1 addition & 3 deletions superset/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from __future__ import print_function
from __future__ import unicode_literals

from superset import frontend_config
import re
from superset import frontend_config

FORM_DATA_KEY_WHITELIST = list(frontend_config.get('controls').keys()) + ['slice_id']

Expand Down Expand Up @@ -79,5 +79,3 @@ def cast_form_data(form_data):
if k not in FORM_DATA_KEY_WHITELIST:
del d[k]
return d


33 changes: 10 additions & 23 deletions superset/models/sql_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
import sqlalchemy as sqla
from sqlalchemy import (
Column, Integer, String, ForeignKey, Text, Boolean,
DateTime, Numeric,
)
DateTime, Numeric, )
from sqlalchemy.orm import backref, relationship

from superset import sm
Expand All @@ -28,7 +27,6 @@


class Query(Model):

"""ORM model for SQL query"""

__tablename__ = 'query'
Expand All @@ -39,8 +37,7 @@ class Query(Model):

# Store the tmp table into the DB only if the user asks for it.
tmp_table_name = Column(String(256))
user_id = Column(
Integer, ForeignKey('ab_user.id'), nullable=True)
user_id = Column(Integer, ForeignKey('ab_user.id'), nullable=True)
status = Column(String(16), default=QueryStatus.PENDING)
tab_name = Column(String(256))
sql_editor_id = Column(String(256))
Expand Down Expand Up @@ -80,14 +77,11 @@ class Query(Model):
database = relationship(
'Database',
foreign_keys=[database_id],
backref=backref('queries', cascade='all, delete-orphan')
)
user = relationship(
sm.user_model,
foreign_keys=[user_id])
backref=backref('queries', cascade='all, delete-orphan'))
user = relationship(sm.user_model, foreign_keys=[user_id])

__table_args__ = (
sqla.Index('ti_user_id_changed_on', user_id, changed_on),
sqla.Index('ti_user_id_changed_on', user_id, changed_on),
)

@property
Expand Down Expand Up @@ -128,25 +122,19 @@ def name(self):
"""Name property"""
ts = datetime.now().isoformat()
ts = ts.replace('-', '').replace(':', '').split('.')[0]
tab = (
self.tab_name.replace(' ', '_').lower()
if self.tab_name
else 'notab'
)
tab = (self.tab_name.replace(' ', '_').lower()
if self.tab_name else 'notab')
tab = re.sub(r'\W+', '', tab)
return "sqllab_{tab}_{ts}".format(**locals())


class SavedQuery(Model, AuditMixinNullable):

"""ORM model for SQL query"""

__tablename__ = 'saved_query'
id = Column(Integer, primary_key=True)
user_id = Column(
Integer, ForeignKey('ab_user.id'), nullable=True)
db_id = Column(
Integer, ForeignKey('dbs.id'), nullable=True)
user_id = Column(Integer, ForeignKey('ab_user.id'), nullable=True)
db_id = Column(Integer, ForeignKey('dbs.id'), nullable=True)
schema = Column(String(128))
label = Column(String(256))
description = Column(Text)
Expand All @@ -158,8 +146,7 @@ class SavedQuery(Model, AuditMixinNullable):
database = relationship(
'Database',
foreign_keys=[db_id],
backref=backref('saved_queries', cascade='all, delete-orphan')
)
backref=backref('saved_queries', cascade='all, delete-orphan'))

@property
def pop_tab_link(self):
Expand Down
23 changes: 12 additions & 11 deletions superset/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from superset.models import core as models
from superset.connectors.connector_registry import ConnectorRegistry


READ_ONLY_MODEL_VIEWS = {
'DatabaseAsync',
'DatabaseView',
Expand Down Expand Up @@ -104,16 +103,16 @@ def get_or_create_main_db():

def is_admin_only(pvm):
# not readonly operations on read only model views allowed only for admins
if (pvm.view_menu.name in READ_ONLY_MODEL_VIEWS and
pvm.permission.name not in READ_ONLY_PERMISSION):
if (pvm.view_menu.name in READ_ONLY_MODEL_VIEWS
and pvm.permission.name not in READ_ONLY_PERMISSION):
return True
return (pvm.view_menu.name in ADMIN_ONLY_VIEW_MENUS or
pvm.permission.name in ADMIN_ONLY_PERMISSIONS)
return (pvm.view_menu.name in ADMIN_ONLY_VIEW_MENUS
or pvm.permission.name in ADMIN_ONLY_PERMISSIONS)


def is_alpha_only(pvm):
if (pvm.view_menu.name in GAMMA_READ_ONLY_MODEL_VIEWS and
pvm.permission.name not in READ_ONLY_PERMISSION):
if (pvm.view_menu.name in GAMMA_READ_ONLY_MODEL_VIEWS
and pvm.permission.name not in READ_ONLY_PERMISSION):
return True
return pvm.permission.name in ALPHA_ONLY_PERMISSIONS

Expand All @@ -133,12 +132,14 @@ def is_gamma_pvm(pvm):

def is_sql_lab_pvm(pvm):
return pvm.view_menu.name in {'SQL Lab'} or pvm.permission.name in {
'can_sql_json', 'can_csv', 'can_search_queries'}
'can_sql_json', 'can_csv', 'can_search_queries'
}


def is_granter_pvm(pvm):
return pvm.permission.name in {'can_override_role_permissions',
'can_approve'}
return pvm.permission.name in {
'can_override_role_permissions', 'can_approve'
}


def set_role(role_name, pvm_check):
Expand Down Expand Up @@ -191,7 +192,7 @@ def merge_pv(view_menu, perm):
metrics += list(db.session.query(datasource_class.metric_class).all())

for metric in metrics:
if (metric.is_restricted):
if metric.is_restricted:
merge_pv('metric_access', metric.perm)


Expand Down
Loading

0 comments on commit 913e0f5

Please sign in to comment.