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

villebro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 4ef2699  feat: Add owners and physical/virtual status to Datasets API 
list endpoint (#10025)
4ef2699 is described below

commit 4ef26993e2f88d69a2f4e632c570e1e555e2e2ef
Author: Will Barrett <w...@preset.io>
AuthorDate: Wed Jun 10 12:04:40 2020 -0700

    feat: Add owners and physical/virtual status to Datasets API list endpoint 
(#10025)
    
    * Add owners and physical/virtual status to Datasets API list endpoint
    
    * black
    
    * Update type definition for DatasourceKind
    
    Co-authored-by: Ville Brofeldt <33317356+ville...@users.noreply.github.com>
    
    * Fixin' tests and mypy
    
    Co-authored-by: Ville Brofeldt <33317356+ville...@users.noreply.github.com>
---
 .gitignore                         |  1 +
 superset/connectors/base/models.py | 13 +++++++++++++
 superset/datasets/api.py           |  5 +++++
 tests/datasets/api_tests.py        |  3 +++
 4 files changed, 22 insertions(+)

diff --git a/.gitignore b/.gitignore
index 0ccddfa..77e5aad 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,6 +23,7 @@
 .bento*
 .cache-loader
 .coverage
+cover
 .DS_Store
 .eggs
 .envrc
diff --git a/superset/connectors/base/models.py 
b/superset/connectors/base/models.py
index fb2d5eb..eb0d3e2 100644
--- a/superset/connectors/base/models.py
+++ b/superset/connectors/base/models.py
@@ -15,6 +15,7 @@
 # specific language governing permissions and limitations
 # under the License.
 import json
+from enum import Enum
 from typing import Any, Dict, Hashable, List, Optional, Type, Union
 
 from flask_appbuilder.security.sqla.models import User
@@ -51,6 +52,11 @@ COLUMN_FORM_DATA_PARAMS = [
 ]
 
 
+class DatasourceKind(str, Enum):
+    VIRTUAL = "virtual"
+    PHYSICAL = "physical"
+
+
 class BaseDatasource(
     AuditMixinNullable, ImportMixin
 ):  # pylint: disable=too-many-public-methods
@@ -101,6 +107,13 @@ class BaseDatasource(
     owners: List[User]
     update_from_object_fields: List[str]
 
+    @property
+    def kind(self) -> str:
+        if self.sql:
+            return DatasourceKind.VIRTUAL.value
+
+        return DatasourceKind.PHYSICAL.value
+
     @declared_attr
     def slices(self) -> RelationshipProperty:
         return relationship(
diff --git a/superset/datasets/api.py b/superset/datasets/api.py
index 7452b66..bafcebf 100644
--- a/superset/datasets/api.py
+++ b/superset/datasets/api.py
@@ -78,6 +78,11 @@ class DatasetRestApi(BaseSupersetModelRestApi):
         "changed_on",
         "default_endpoint",
         "explore_url",
+        "kind",
+        "owners.id",
+        "owners.username",
+        "owners.first_name",
+        "owners.last_name",
         "schema",
         "table_name",
     ]
diff --git a/tests/datasets/api_tests.py b/tests/datasets/api_tests.py
index 47d98e6..75e9aea 100644
--- a/tests/datasets/api_tests.py
+++ b/tests/datasets/api_tests.py
@@ -23,6 +23,7 @@ import prison
 import yaml
 from sqlalchemy.sql import func
 
+import tests.test_app
 from superset.connectors.sqla.models import SqlaTable, SqlMetric, TableColumn
 from superset.dao.exceptions import (
     DAOCreateFailedError,
@@ -96,6 +97,8 @@ class DatasetApiTests(SupersetTestCase):
             "default_endpoint",
             "explore_url",
             "id",
+            "kind",
+            "owners",
             "schema",
             "table_name",
         ]

Reply via email to