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 2024/07/16 17:55:08 UTC

(superset) branch more-fixes-catalog-security-manager updated (4b21aaff14 -> 7b2b9be056)

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

beto pushed a change to branch more-fixes-catalog-security-manager
in repository https://gitbox.apache.org/repos/asf/superset.git


 discard 4b21aaff14 fix: set default catalog
     new 7b2b9be056 fix: set default catalog

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   (4b21aaff14)
            \
             N -- N -- N   refs/heads/more-fixes-catalog-security-manager (7b2b9be056)

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/security/manager.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)


(superset) 01/01: fix: set default catalog

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

beto pushed a commit to branch more-fixes-catalog-security-manager
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 7b2b9be05677588e3cf7c4432625298e70effef2
Author: Beto Dealmeida <ro...@dealmeida.net>
AuthorDate: Tue Jul 16 13:51:25 2024 -0400

    fix: set default catalog
---
 superset/commands/dataset/create.py | 11 +++++++++--
 superset/security/manager.py        | 31 +++++++++++++++++++------------
 2 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/superset/commands/dataset/create.py b/superset/commands/dataset/create.py
index a2d81e548b..2f5a9a8143 100644
--- a/superset/commands/dataset/create.py
+++ b/superset/commands/dataset/create.py
@@ -59,14 +59,21 @@ class CreateDatasetCommand(CreateMixin, BaseCommand):
         sql = self._properties.get("sql")
         owner_ids: Optional[list[int]] = self._properties.get("owners")
 
-        table = Table(self._properties["table_name"], schema, catalog)
+        database = DatasetDAO.get_database_by_id(database_id)
+        if not catalog:
+            catalog = self._properties["catalog"] = database.get_default_catalog()
+
+        table = Table(
+            self._properties["table_name"],
+            schema,
+            catalog,
+        )
 
         # Validate uniqueness
         if not DatasetDAO.validate_uniqueness(database_id, table):
             exceptions.append(DatasetExistsValidationError(table))
 
         # Validate/Populate database
-        database = DatasetDAO.get_database_by_id(database_id)
         if not database:
             exceptions.append(DatabaseNotFoundValidationError())
         self._properties["database"] = database
diff --git a/superset/security/manager.py b/superset/security/manager.py
index 30cf37f117..602749b20b 100644
--- a/superset/security/manager.py
+++ b/superset/security/manager.py
@@ -773,6 +773,9 @@ class SupersetSecurityManager(  # pylint: disable=too-many-public-methods
         # pylint: disable=import-outside-toplevel
         from superset.connectors.sqla.models import SqlaTable
 
+        default_catalog = database.get_default_catalog()
+        catalog = catalog or default_catalog
+
         if hierarchical and (
             self.can_access_database(database)
             or (catalog and self.can_access_catalog(database, catalog))
@@ -782,7 +785,6 @@ class SupersetSecurityManager(  # pylint: disable=too-many-public-methods
         # schema_access
         accessible_schemas: set[str] = set()
         schema_access = self.user_view_menu_names("schema_access")
-        default_catalog = database.get_default_catalog()
         default_schema = database.get_default_schema(default_catalog)
 
         for perm in schema_access:
@@ -797,9 +799,9 @@ class SupersetSecurityManager(  # pylint: disable=too-many-public-methods
                 accessible_schemas.add(parts[1])
 
             # [database].[catalog].[schema] matches when the catalog is equal to the
-            # requested catalog or, when no catalog specified, it's equal to the default
+            # requested catalog
             # catalog.
-            elif len(parts) == 3 and parts[1] == (catalog or default_catalog):
+            elif len(parts) == 3 and parts[1] == catalog:
                 accessible_schemas.add(parts[2])
 
         # datasource_access
@@ -905,10 +907,11 @@ class SupersetSecurityManager(  # pylint: disable=too-many-public-methods
         if self.can_access_database(database):
             return datasource_names
 
-        if catalog:
-            catalog_perm = self.get_catalog_perm(database.database_name, catalog)
-            if catalog_perm and self.can_access("catalog_access", catalog_perm):
-                return datasource_names
+        # If catalog is not set we need to use the default one.
+        catalog = catalog or database.get_default_catalog()
+        catalog_perm = self.get_catalog_perm(database.database_name, catalog)
+        if catalog_perm and self.can_access("catalog_access", catalog_perm):
+            return datasource_names
 
         if schema:
             default_catalog = database.get_default_catalog()
@@ -2182,6 +2185,7 @@ class SupersetSecurityManager(  # pylint: disable=too-many-public-methods
                 database = query.database
 
             database = cast("Database", database)
+            default_catalog = database.get_default_catalog()
 
             if self.can_access_database(database):
                 return
@@ -2195,19 +2199,22 @@ class SupersetSecurityManager(  # pylint: disable=too-many-public-methods
                 # from the SQLAlchemy URI if possible; if not, we use the SQLAlchemy
                 # inspector to read it.
                 default_schema = database.get_default_schema_for_query(query)
-                # Determining the default catalog is much easier, because DB engine
-                # specs need explicit support for catalogs.
-                default_catalog = database.get_default_catalog()
                 tables = {
                     Table(
                         table_.table,
                         table_.schema or default_schema,
-                        table_.catalog or default_catalog,
+                        table_.catalog or query.catalog,
                     )
                     for table_ in extract_tables_from_jinja_sql(query.sql, database)
                 }
             elif table:
-                tables = {table}
+                tables = {
+                    Table(
+                        table.table,
+                        table.schema,
+                        table.catalog or default_catalog,
+                    )
+                }
 
             denied = set()