mirror of
https://github.com/apache/superset.git
synced 2026-04-19 16:14:52 +00:00
[security] Refactor security code into SupersetSecurityManager (#4565)
* move access permissions methods to security manager * consolidate all security methods into SupersetSecurityManager * update security method calls * update calls from tests * move get_or_create_main_db to utils * raise if supersetsecuritymanager is not extended * rename sm to security_manager
This commit is contained in:
@@ -16,10 +16,9 @@ from sqlalchemy import BigInteger, Date, DateTime, Float, String, Text
|
||||
import geohash
|
||||
import polyline
|
||||
|
||||
from superset import app, db, utils
|
||||
from superset import app, db, security_manager, utils
|
||||
from superset.connectors.connector_registry import ConnectorRegistry
|
||||
from superset.models import core as models
|
||||
from superset.security import get_or_create_main_db
|
||||
|
||||
# Shortcuts
|
||||
DB = models.Database
|
||||
@@ -71,7 +70,7 @@ def load_energy():
|
||||
if not tbl:
|
||||
tbl = TBL(table_name=tbl_name)
|
||||
tbl.description = "Energy consumption"
|
||||
tbl.database = get_or_create_main_db()
|
||||
tbl.database = utils.get_or_create_main_db()
|
||||
db.session.merge(tbl)
|
||||
db.session.commit()
|
||||
tbl.fetch_metadata()
|
||||
@@ -179,7 +178,7 @@ def load_world_bank_health_n_pop():
|
||||
tbl = TBL(table_name=tbl_name)
|
||||
tbl.description = utils.readfile(os.path.join(DATA_FOLDER, 'countries.md'))
|
||||
tbl.main_dttm_col = 'year'
|
||||
tbl.database = get_or_create_main_db()
|
||||
tbl.database = utils.get_or_create_main_db()
|
||||
tbl.filter_select_enabled = True
|
||||
db.session.merge(tbl)
|
||||
db.session.commit()
|
||||
@@ -583,7 +582,7 @@ def load_birth_names():
|
||||
if not obj:
|
||||
obj = TBL(table_name='birth_names')
|
||||
obj.main_dttm_col = 'ds'
|
||||
obj.database = get_or_create_main_db()
|
||||
obj.database = utils.get_or_create_main_db()
|
||||
obj.filter_select_enabled = True
|
||||
db.session.merge(obj)
|
||||
db.session.commit()
|
||||
@@ -870,7 +869,7 @@ def load_unicode_test_data():
|
||||
if not obj:
|
||||
obj = TBL(table_name='unicode_test')
|
||||
obj.main_dttm_col = 'dttm'
|
||||
obj.database = get_or_create_main_db()
|
||||
obj.database = utils.get_or_create_main_db()
|
||||
db.session.merge(obj)
|
||||
db.session.commit()
|
||||
obj.fetch_metadata()
|
||||
@@ -948,7 +947,7 @@ def load_random_time_series_data():
|
||||
if not obj:
|
||||
obj = TBL(table_name='random_time_series')
|
||||
obj.main_dttm_col = 'ds'
|
||||
obj.database = get_or_create_main_db()
|
||||
obj.database = utils.get_or_create_main_db()
|
||||
db.session.merge(obj)
|
||||
db.session.commit()
|
||||
obj.fetch_metadata()
|
||||
@@ -1011,7 +1010,7 @@ def load_country_map_data():
|
||||
if not obj:
|
||||
obj = TBL(table_name='birth_france_by_region')
|
||||
obj.main_dttm_col = 'dttm'
|
||||
obj.database = get_or_create_main_db()
|
||||
obj.database = utils.get_or_create_main_db()
|
||||
db.session.merge(obj)
|
||||
db.session.commit()
|
||||
obj.fetch_metadata()
|
||||
@@ -1086,7 +1085,7 @@ def load_long_lat_data():
|
||||
if not obj:
|
||||
obj = TBL(table_name='long_lat')
|
||||
obj.main_dttm_col = 'datetime'
|
||||
obj.database = get_or_create_main_db()
|
||||
obj.database = utils.get_or_create_main_db()
|
||||
db.session.merge(obj)
|
||||
db.session.commit()
|
||||
obj.fetch_metadata()
|
||||
@@ -1147,7 +1146,7 @@ def load_multiformat_time_series_data():
|
||||
if not obj:
|
||||
obj = TBL(table_name='multiformat_time_series')
|
||||
obj.main_dttm_col = 'ds'
|
||||
obj.database = get_or_create_main_db()
|
||||
obj.database = utils.get_or_create_main_db()
|
||||
dttm_and_expr_dict = {
|
||||
'ds': [None, None],
|
||||
'ds2': [None, None],
|
||||
@@ -1769,7 +1768,7 @@ def load_flights():
|
||||
if not tbl:
|
||||
tbl = TBL(table_name=tbl_name)
|
||||
tbl.description = "Random set of flights in the US"
|
||||
tbl.database = get_or_create_main_db()
|
||||
tbl.database = utils.get_or_create_main_db()
|
||||
db.session.merge(tbl)
|
||||
db.session.commit()
|
||||
tbl.fetch_metadata()
|
||||
@@ -1800,7 +1799,7 @@ def load_paris_iris_geojson():
|
||||
if not tbl:
|
||||
tbl = TBL(table_name=tbl_name)
|
||||
tbl.description = "Map of Paris"
|
||||
tbl.database = get_or_create_main_db()
|
||||
tbl.database = utils.get_or_create_main_db()
|
||||
db.session.merge(tbl)
|
||||
db.session.commit()
|
||||
tbl.fetch_metadata()
|
||||
@@ -1830,7 +1829,7 @@ def load_sf_population_polygons():
|
||||
if not tbl:
|
||||
tbl = TBL(table_name=tbl_name)
|
||||
tbl.description = "Population density of San Francisco"
|
||||
tbl.database = get_or_create_main_db()
|
||||
tbl.database = utils.get_or_create_main_db()
|
||||
db.session.merge(tbl)
|
||||
db.session.commit()
|
||||
tbl.fetch_metadata()
|
||||
@@ -1860,7 +1859,7 @@ def load_bart_lines():
|
||||
if not tbl:
|
||||
tbl = TBL(table_name=tbl_name)
|
||||
tbl.description = "BART lines"
|
||||
tbl.database = get_or_create_main_db()
|
||||
tbl.database = utils.get_or_create_main_db()
|
||||
db.session.merge(tbl)
|
||||
db.session.commit()
|
||||
tbl.fetch_metadata()
|
||||
|
||||
Reference in New Issue
Block a user