You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by be...@apache.org on 2023/04/05 23:06:38 UTC

[superset] branch sc-69055 updated (abe61f778e -> 16095933f7)

This is an automated email from the ASF dual-hosted git repository.

beto pushed a change to branch sc-69055
in repository https://gitbox.apache.org/repos/asf/superset.git


 discard abe61f778e fix: load examples as anon user
     new 16095933f7 fix: load examples as anon user

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (abe61f778e)
            \
             N -- N -- N   refs/heads/sc-69055 (16095933f7)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 superset/dashboards/commands/importers/v1/utils.py | 3 ++-
 superset/databases/commands/importers/v1/utils.py  | 3 ++-
 superset/datasets/commands/importers/v1/utils.py   | 3 ++-
 3 files changed, 6 insertions(+), 3 deletions(-)


[superset] 01/01: fix: load examples as anon user

Posted by be...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

beto pushed a commit to branch sc-69055
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 16095933f7d86408f90b5c97f36e45f6f7e4aaa5
Author: Beto Dealmeida <ro...@dealmeida.net>
AuthorDate: Wed Apr 5 15:37:20 2023 -0700

    fix: load examples as anon user
---
 superset/charts/commands/importers/v1/utils.py     |  7 ++--
 superset/commands/importers/v1/examples.py         | 41 +++++++++++++++-------
 superset/dashboards/commands/importers/v1/utils.py | 10 ++++--
 superset/databases/commands/importers/v1/utils.py  |  6 +++-
 superset/datasets/commands/importers/v1/utils.py   |  6 +++-
 5 files changed, 51 insertions(+), 19 deletions(-)

diff --git a/superset/charts/commands/importers/v1/utils.py b/superset/charts/commands/importers/v1/utils.py
index cea8af7b4c..d4aeb17a1e 100644
--- a/superset/charts/commands/importers/v1/utils.py
+++ b/superset/charts/commands/importers/v1/utils.py
@@ -27,9 +27,12 @@ from superset.models.slice import Slice
 
 
 def import_chart(
-    session: Session, config: Dict[str, Any], overwrite: bool = False
+    session: Session,
+    config: Dict[str, Any],
+    overwrite: bool = False,
+    ignore_permissions: bool = False,
 ) -> Slice:
-    can_write = security_manager.can_access("can_write", "Chart")
+    can_write = ignore_permissions or security_manager.can_access("can_write", "Chart")
     existing = session.query(Slice).filter_by(uuid=config["uuid"]).first()
     if existing:
         if not overwrite or not can_write:
diff --git a/superset/commands/importers/v1/examples.py b/superset/commands/importers/v1/examples.py
index 8d14c8298a..35efdb1393 100644
--- a/superset/commands/importers/v1/examples.py
+++ b/superset/commands/importers/v1/examples.py
@@ -21,7 +21,7 @@ from sqlalchemy.orm import Session
 from sqlalchemy.orm.exc import MultipleResultsFound
 from sqlalchemy.sql import select
 
-from superset import db, security_manager
+from superset import db
 from superset.charts.commands.importers.v1 import ImportChartsCommand
 from superset.charts.commands.importers.v1.utils import import_chart
 from superset.charts.schemas import ImportV1ChartSchema
@@ -42,7 +42,7 @@ from superset.datasets.commands.importers.v1 import ImportDatasetsCommand
 from superset.datasets.commands.importers.v1.utils import import_dataset
 from superset.datasets.schemas import ImportV1DatasetSchema
 from superset.models.dashboard import dashboard_slices
-from superset.utils.core import get_example_default_schema, override_user
+from superset.utils.core import get_example_default_schema
 from superset.utils.database import get_example_database
 
 
@@ -69,13 +69,12 @@ class ImportExamplesCommand(ImportModelsCommand):
 
         # rollback to prevent partial imports
         try:
-            with override_user(security_manager.find_user(username="admin")):
-                self._import(
-                    db.session,
-                    self._configs,
-                    self.overwrite,
-                    self.force_data,
-                )
+            self._import(
+                db.session,
+                self._configs,
+                self.overwrite,
+                self.force_data,
+            )
             db.session.commit()
         except Exception as ex:
             db.session.rollback()
@@ -102,7 +101,12 @@ class ImportExamplesCommand(ImportModelsCommand):
         database_ids: Dict[str, int] = {}
         for file_name, config in configs.items():
             if file_name.startswith("databases/"):
-                database = import_database(session, config, overwrite=overwrite)
+                database = import_database(
+                    session,
+                    config,
+                    overwrite=overwrite,
+                    ignore_permissions=True,
+                )
                 database_ids[str(database.uuid)] = database.id
 
         # import datasets
@@ -131,9 +135,10 @@ class ImportExamplesCommand(ImportModelsCommand):
                         config,
                         overwrite=overwrite,
                         force_data=force_data,
+                        ignore_permissions=True,
                     )
                 except MultipleResultsFound:
-                    # Multiple result can be found for datasets. There was a bug in
+                    # Multiple results can be found for datasets. There was a bug in
                     # load-examples that resulted in datasets being loaded with a NULL
                     # schema. Users could then add a new dataset with the same name in
                     # the correct schema, resulting in duplicates, since the uniqueness
@@ -156,7 +161,12 @@ class ImportExamplesCommand(ImportModelsCommand):
             ):
                 # update datasource id, type, and name
                 config.update(dataset_info[config["dataset_uuid"]])
-                chart = import_chart(session, config, overwrite=overwrite)
+                chart = import_chart(
+                    session,
+                    config,
+                    overwrite=overwrite,
+                    ignore_permissions=True,
+                )
                 chart_ids[str(chart.uuid)] = chart.id
 
         # store the existing relationship between dashboards and charts
@@ -173,7 +183,12 @@ class ImportExamplesCommand(ImportModelsCommand):
                 except KeyError:
                     continue
 
-                dashboard = import_dashboard(session, config, overwrite=overwrite)
+                dashboard = import_dashboard(
+                    session,
+                    config,
+                    overwrite=overwrite,
+                    ignore_permissions=True,
+                )
                 dashboard.published = True
 
                 for uuid in find_chart_uuids(config["position"]):
diff --git a/superset/dashboards/commands/importers/v1/utils.py b/superset/dashboards/commands/importers/v1/utils.py
index 4d5e2ece81..9f0ffc36a1 100644
--- a/superset/dashboards/commands/importers/v1/utils.py
+++ b/superset/dashboards/commands/importers/v1/utils.py
@@ -146,9 +146,15 @@ def update_id_refs(  # pylint: disable=too-many-locals
 
 
 def import_dashboard(
-    session: Session, config: Dict[str, Any], overwrite: bool = False
+    session: Session,
+    config: Dict[str, Any],
+    overwrite: bool = False,
+    ignore_permissions: bool = False,
 ) -> Dashboard:
-    can_write = security_manager.can_access("can_write", "Dashboard")
+    can_write = ignore_permissions or security_manager.can_access(
+        "can_write",
+        "Dashboard",
+    )
     existing = session.query(Dashboard).filter_by(uuid=config["uuid"]).first()
     if existing:
         if not overwrite or not can_write:
diff --git a/superset/databases/commands/importers/v1/utils.py b/superset/databases/commands/importers/v1/utils.py
index bea13286b6..c0c0ee60d9 100644
--- a/superset/databases/commands/importers/v1/utils.py
+++ b/superset/databases/commands/importers/v1/utils.py
@@ -30,8 +30,12 @@ def import_database(
     session: Session,
     config: Dict[str, Any],
     overwrite: bool = False,
+    ignore_permissions: bool = False,
 ) -> Database:
-    can_write = security_manager.can_access("can_write", "Database")
+    can_write = ignore_permissions or security_manager.can_access(
+        "can_write",
+        "Database",
+    )
     existing = session.query(Database).filter_by(uuid=config["uuid"]).first()
     if existing:
         if not overwrite or not can_write:
diff --git a/superset/datasets/commands/importers/v1/utils.py b/superset/datasets/commands/importers/v1/utils.py
index 2363cf7497..2df85cdfa2 100644
--- a/superset/datasets/commands/importers/v1/utils.py
+++ b/superset/datasets/commands/importers/v1/utils.py
@@ -105,8 +105,12 @@ def import_dataset(
     config: Dict[str, Any],
     overwrite: bool = False,
     force_data: bool = False,
+    ignore_permissions: bool = False,
 ) -> SqlaTable:
-    can_write = security_manager.can_access("can_write", "Dataset")
+    can_write = ignore_permissions or security_manager.can_access(
+        "can_write",
+        "Dataset",
+    )
     existing = session.query(SqlaTable).filter_by(uuid=config["uuid"]).first()
     if existing:
         if not overwrite or not can_write: