From f5160cf7d3a69e3a392c529baa3d2d5513629ce9 Mon Sep 17 00:00:00 2001 From: Ville Brofeldt Date: Sun, 18 Dec 2022 19:39:34 +0200 Subject: [PATCH] remove admin as birth_names owner/creator --- superset/examples/birth_names.py | 81 +++++++------------ .../examples/supported_charts_dashboard.py | 76 +++++++++-------- .../fixtures/birth_names_dashboard.py | 2 +- 3 files changed, 66 insertions(+), 93 deletions(-) diff --git a/superset/examples/birth_names.py b/superset/examples/birth_names.py index 406a70b2cc4d5..e8832462aac6f 100644 --- a/superset/examples/birth_names.py +++ b/superset/examples/birth_names.py @@ -19,13 +19,11 @@ from typing import Dict, List, Tuple, Union import pandas as pd -from flask_appbuilder.security.sqla.models import User from sqlalchemy import DateTime, inspect, String from sqlalchemy.sql import column -from superset import app, db, security_manager +from superset import app, db from superset.connectors.sqla.models import SqlaTable, SqlMetric, TableColumn -from superset.exceptions import NoDataException from superset.models.core import Database from superset.models.dashboard import Dashboard from superset.models.slice import Slice @@ -42,17 +40,6 @@ ) -def get_admin_user() -> User: - admin = security_manager.find_user("admin") - if admin is None: - raise NoDataException( - "Admin user does not exist. " - "Please, check if test users are properly loaded " - "(`superset load_test_users`)." - ) - return admin - - def gen_filter( subject: str, comparator: str, operator: str = "==" ) -> Dict[str, Union[bool, str]]: @@ -125,7 +112,7 @@ def load_birth_names( db.session.commit() - slices, _ = create_slices(obj, admin_owner=True) + slices, _ = create_slices(obj) create_dashboard(slices) @@ -165,7 +152,7 @@ def _add_table_metrics(datasource: SqlaTable) -> None: datasource.metrics = metrics -def create_slices(tbl: SqlaTable, admin_owner: bool) -> Tuple[List[Slice], List[Slice]]: +def create_slices(tbl: SqlaTable) -> Tuple[List[Slice], List[Slice]]: metrics = [ { "expressionType": "SIMPLE", @@ -206,26 +193,16 @@ def create_slices(tbl: SqlaTable, admin_owner: bool) -> Tuple[List[Slice], List[ ], } - admin = get_admin_user() - if admin_owner: - slice_props = dict( - datasource_id=tbl.id, - datasource_type=DatasourceType.TABLE, - owners=[admin], - created_by=admin, - ) - else: - slice_props = dict( - datasource_id=tbl.id, - datasource_type=DatasourceType.TABLE, - owners=[], - created_by=admin, - ) + slice_kwargs = { + "datasource_id": tbl.id, + "datasource_type": DatasourceType.TABLE, + "owners": [], + } print("Creating some slices") slices = [ Slice( - **slice_props, + **slice_kwargs, slice_name="Participants", viz_type="big_number", params=get_slice_json( @@ -238,7 +215,7 @@ def create_slices(tbl: SqlaTable, admin_owner: bool) -> Tuple[List[Slice], List[ ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Genders", viz_type="pie", params=get_slice_json( @@ -246,7 +223,7 @@ def create_slices(tbl: SqlaTable, admin_owner: bool) -> Tuple[List[Slice], List[ ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Trends", viz_type="line", params=get_slice_json( @@ -260,7 +237,7 @@ def create_slices(tbl: SqlaTable, admin_owner: bool) -> Tuple[List[Slice], List[ ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Genders by State", viz_type="dist_bar", params=get_slice_json( @@ -296,7 +273,7 @@ def create_slices(tbl: SqlaTable, admin_owner: bool) -> Tuple[List[Slice], List[ ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Girls", viz_type="table", params=get_slice_json( @@ -309,7 +286,7 @@ def create_slices(tbl: SqlaTable, admin_owner: bool) -> Tuple[List[Slice], List[ ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Girl Name Cloud", viz_type="word_cloud", params=get_slice_json( @@ -325,7 +302,7 @@ def create_slices(tbl: SqlaTable, admin_owner: bool) -> Tuple[List[Slice], List[ ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Boys", viz_type="table", params=get_slice_json( @@ -338,7 +315,7 @@ def create_slices(tbl: SqlaTable, admin_owner: bool) -> Tuple[List[Slice], List[ ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Boy Name Cloud", viz_type="word_cloud", params=get_slice_json( @@ -354,7 +331,7 @@ def create_slices(tbl: SqlaTable, admin_owner: bool) -> Tuple[List[Slice], List[ ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Top 10 Girl Name Share", viz_type="area", params=get_slice_json( @@ -371,7 +348,7 @@ def create_slices(tbl: SqlaTable, admin_owner: bool) -> Tuple[List[Slice], List[ ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Top 10 Boy Name Share", viz_type="area", params=get_slice_json( @@ -388,7 +365,7 @@ def create_slices(tbl: SqlaTable, admin_owner: bool) -> Tuple[List[Slice], List[ ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Pivot Table v2", viz_type="pivot_table_v2", params=get_slice_json( @@ -411,7 +388,7 @@ def create_slices(tbl: SqlaTable, admin_owner: bool) -> Tuple[List[Slice], List[ ] misc_slices = [ Slice( - **slice_props, + **slice_kwargs, slice_name="Average and Sum Trends", viz_type="dual_line", params=get_slice_json( @@ -430,13 +407,13 @@ def create_slices(tbl: SqlaTable, admin_owner: bool) -> Tuple[List[Slice], List[ ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Num Births Trend", viz_type="line", params=get_slice_json(defaults, viz_type="line", metrics=metrics), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Daily Totals", viz_type="table", params=get_slice_json( @@ -449,7 +426,7 @@ def create_slices(tbl: SqlaTable, admin_owner: bool) -> Tuple[List[Slice], List[ ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Number of California Births", viz_type="big_number_total", params=get_slice_json( @@ -468,7 +445,7 @@ def create_slices(tbl: SqlaTable, admin_owner: bool) -> Tuple[List[Slice], List[ ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Top 10 California Names Timeseries", viz_type="line", params=get_slice_json( @@ -500,7 +477,7 @@ def create_slices(tbl: SqlaTable, admin_owner: bool) -> Tuple[List[Slice], List[ ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Names Sorted by Num in California", viz_type="table", params=get_slice_json( @@ -520,7 +497,7 @@ def create_slices(tbl: SqlaTable, admin_owner: bool) -> Tuple[List[Slice], List[ ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Number of Girls", viz_type="big_number_total", params=get_slice_json( @@ -533,7 +510,7 @@ def create_slices(tbl: SqlaTable, admin_owner: bool) -> Tuple[List[Slice], List[ ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Pivot Table", viz_type="pivot_table", params=get_slice_json( @@ -557,12 +534,10 @@ def create_slices(tbl: SqlaTable, admin_owner: bool) -> Tuple[List[Slice], List[ def create_dashboard(slices: List[Slice]) -> Dashboard: print("Creating a dashboard") - admin = get_admin_user() dash = db.session.query(Dashboard).filter_by(slug="births").first() if not dash: dash = Dashboard() - dash.owners = [admin] - dash.created_by = admin + dash.owners = [] db.session.add(dash) dash.published = True diff --git a/superset/examples/supported_charts_dashboard.py b/superset/examples/supported_charts_dashboard.py index 551741bf7d17b..54aa650d502b0 100644 --- a/superset/examples/supported_charts_dashboard.py +++ b/superset/examples/supported_charts_dashboard.py @@ -23,7 +23,7 @@ from sqlalchemy import inspect -from superset import db, security_manager +from superset import db from superset.connectors.sqla.models import SqlaTable from superset.models.dashboard import Dashboard from superset.models.slice import Slice @@ -41,13 +41,11 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: - admin = security_manager.find_user("admin") - slice_props = dict( - datasource_id=tbl.id, - datasource_type=DatasourceType.TABLE, - owners=[admin], - created_by=admin, - ) + slice_kwargs = { + "datasource_id": tbl.id, + "datasource_type": DatasourceType.TABLE, + "owners": [], + } defaults = { "limit": "25", @@ -62,7 +60,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: # TIER 1 # --------------------- Slice( - **slice_props, + **slice_kwargs, slice_name="Big Number", viz_type="big_number_total", params=get_slice_json( @@ -72,7 +70,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Big Number with Trendline", viz_type="big_number", params=get_slice_json( @@ -82,7 +80,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Table", viz_type="table", params=get_slice_json( @@ -93,7 +91,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Pivot Table", viz_type="pivot_table_v2", params=get_slice_json( @@ -105,7 +103,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Time-Series Line Chart", viz_type="echarts_timeseries_line", params=get_slice_json( @@ -116,7 +114,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Time-Series Area Chart", viz_type="echarts_area", params=get_slice_json( @@ -127,7 +125,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Time-Series Bar Chart V2", viz_type="echarts_timeseries_bar", params=get_slice_json( @@ -138,7 +136,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Time-Series Scatter Chart", viz_type="echarts_timeseries_scatter", params=get_slice_json( @@ -149,7 +147,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Pie Chart", viz_type="pie", params=get_slice_json( @@ -161,7 +159,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Bar Chart", viz_type="dist_bar", params=get_slice_json( @@ -175,7 +173,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: # TIER 2 # --------------------- Slice( - **slice_props, + **slice_kwargs, slice_name="Box Plot Chart", viz_type="box_plot", params=get_slice_json( @@ -187,7 +185,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Bubble Chart", viz_type="bubble", params=get_slice_json( @@ -217,7 +215,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Calendar Heatmap", viz_type="cal_heatmap", params=get_slice_json( @@ -228,7 +226,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Chord Chart", viz_type="chord", params=get_slice_json( @@ -240,7 +238,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Time-Series Percent Change Chart", viz_type="compare", params=get_slice_json( @@ -251,7 +249,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Time-Series Generic Chart", viz_type="echarts_timeseries", params=get_slice_json( @@ -262,7 +260,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Time-Series Smooth Line Chart", viz_type="echarts_timeseries_smooth", params=get_slice_json( @@ -273,7 +271,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Time-Series Step Line Chart", viz_type="echarts_timeseries_step", params=get_slice_json( @@ -284,7 +282,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Funnel Chart", viz_type="funnel", params=get_slice_json( @@ -295,7 +293,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Gauge Chart", viz_type="gauge_chart", params=get_slice_json( @@ -306,7 +304,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Heatmap Chart", viz_type="heatmap", params=get_slice_json( @@ -318,7 +316,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Line Chart", viz_type="line", params=get_slice_json( @@ -329,7 +327,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Mixed Chart", viz_type="mixed_timeseries", params=get_slice_json( @@ -342,7 +340,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Partition Chart", viz_type="partition", params=get_slice_json( @@ -353,7 +351,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Radar Chart", viz_type="radar", params=get_slice_json( @@ -376,7 +374,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Nightingale Chart", viz_type="rose", params=get_slice_json( @@ -387,7 +385,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Sankey Chart", viz_type="sankey", params=get_slice_json( @@ -398,7 +396,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Sunburst Chart", viz_type="sunburst", params=get_slice_json( @@ -409,7 +407,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Treemap Chart", viz_type="treemap", params=get_slice_json( @@ -420,7 +418,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Treemap V2 Chart", viz_type="treemap_v2", params=get_slice_json( @@ -431,7 +429,7 @@ def create_slices(tbl: SqlaTable) -> List[Slice]: ), ), Slice( - **slice_props, + **slice_kwargs, slice_name="Word Cloud Chart", viz_type="word_cloud", params=get_slice_json( diff --git a/tests/integration_tests/fixtures/birth_names_dashboard.py b/tests/integration_tests/fixtures/birth_names_dashboard.py index 41fcd47919f35..be680a720dd84 100644 --- a/tests/integration_tests/fixtures/birth_names_dashboard.py +++ b/tests/integration_tests/fixtures/birth_names_dashboard.py @@ -68,7 +68,7 @@ def _create_dashboards(): from superset.examples.birth_names import create_dashboard, create_slices - slices, _ = create_slices(table, admin_owner=False) + slices, _ = create_slices(table) dash = create_dashboard(slices) slices_ids_to_delete = [slice.id for slice in slices] dash_id_to_delete = dash.id