You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by dp...@apache.org on 2022/09/06 18:18:13 UTC
[superset] branch master updated: feat: only show active user for chart/dashboard/datasource owner drop… (#20837)
This is an automated email from the ASF dual-hosted git repository.
dpgaspar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new 9be4870c7f feat: only show active user for chart/dashboard/datasource owner drop… (#20837)
9be4870c7f is described below
commit 9be4870c7f855f086671f281875d165fe27d8d13
Author: Zef Lin <ze...@preset.io>
AuthorDate: Tue Sep 6 11:17:50 2022 -0700
feat: only show active user for chart/dashboard/datasource owner drop… (#20837)
---
.../src/components/Datasource/DatasourceEditor.jsx | 10 +++--
.../dashboard/components/PropertiesModal/index.tsx | 8 ++--
.../explore/components/PropertiesModal/index.tsx | 8 ++--
superset/views/base_api.py | 22 ++++++++++
tests/integration_tests/base_api_tests.py | 48 ++++++++++++++++++----
.../queries/saved_queries/api_tests.py | 3 +-
6 files changed, 78 insertions(+), 21 deletions(-)
diff --git a/superset-frontend/src/components/Datasource/DatasourceEditor.jsx b/superset-frontend/src/components/Datasource/DatasourceEditor.jsx
index 260cf5eab7..c5a21f65e4 100644
--- a/superset-frontend/src/components/Datasource/DatasourceEditor.jsx
+++ b/superset-frontend/src/components/Datasource/DatasourceEditor.jsx
@@ -540,10 +540,12 @@ function OwnersSelector({ datasource, onChange }) {
return SupersetClient.get({
endpoint: `/api/v1/dataset/related/owners?q=${query}`,
}).then(response => ({
- data: response.json.result.map(item => ({
- value: item.value,
- label: item.text,
- })),
+ data: response.json.result
+ .filter(item => item.extra.active)
+ .map(item => ({
+ value: item.value,
+ label: item.text,
+ })),
totalCount: response.json.count,
}));
}, []);
diff --git a/superset-frontend/src/dashboard/components/PropertiesModal/index.tsx b/superset-frontend/src/dashboard/components/PropertiesModal/index.tsx
index ebdc753226..15c04c323a 100644
--- a/superset-frontend/src/dashboard/components/PropertiesModal/index.tsx
+++ b/superset-frontend/src/dashboard/components/PropertiesModal/index.tsx
@@ -132,12 +132,12 @@ const PropertiesModal = ({
return SupersetClient.get({
endpoint: `/api/v1/dashboard/related/${accessType}?q=${query}`,
}).then(response => ({
- data: response.json.result.map(
- (item: { value: number; text: string }) => ({
+ data: response.json.result
+ .filter((item: { extra: { active: boolean } }) => item.extra.active)
+ .map((item: { value: number; text: string }) => ({
value: item.value,
label: item.text,
- }),
- ),
+ })),
totalCount: response.json.count,
}));
},
diff --git a/superset-frontend/src/explore/components/PropertiesModal/index.tsx b/superset-frontend/src/explore/components/PropertiesModal/index.tsx
index 3aa0fa60d2..cb0a6e33bb 100644
--- a/superset-frontend/src/explore/components/PropertiesModal/index.tsx
+++ b/superset-frontend/src/explore/components/PropertiesModal/index.tsx
@@ -107,12 +107,12 @@ function PropertiesModal({
return SupersetClient.get({
endpoint: `/api/v1/chart/related/owners?q=${query}`,
}).then(response => ({
- data: response.json.result.map(
- (item: { value: number; text: string }) => ({
+ data: response.json.result
+ .filter((item: { extra: { active: boolean } }) => item.extra.active)
+ .map((item: { value: number; text: string }) => ({
value: item.value,
label: item.text,
- }),
- ),
+ })),
totalCount: response.json.count,
}));
},
diff --git a/superset/views/base_api.py b/superset/views/base_api.py
index 0728501cce..eb957a48ef 100644
--- a/superset/views/base_api.py
+++ b/superset/views/base_api.py
@@ -56,6 +56,7 @@ get_related_schema = {
class RelatedResultResponseSchema(Schema):
value = fields.Integer(description="The related item identifier")
text = fields.String(description="The related item string representation")
+ extra = fields.Dict(description="The extra metadata for related item")
class RelatedResponseSchema(Schema):
@@ -223,6 +224,15 @@ class BaseSupersetModelRestApi(ModelRestApi):
}
"""
+ extra_fields_rel_fields: Dict[str, List[str]] = {"owners": ["email", "active"]}
+ """
+ Declare extra fields for the representation of the Model object::
+
+ extra_fields_rel_fields = {
+ "<RELATED_FIELD>": "[<RELATED_OBJECT_FIELD_1>, <RELATED_OBJECT_FIELD_2>]"
+ }
+ """
+
allowed_distinct_fields: Set[str] = set()
add_columns: List[str]
@@ -317,6 +327,17 @@ class BaseSupersetModelRestApi(ModelRestApi):
return getattr(model, model_column_name)
return str(model)
+ def _get_extra_field_for_model(
+ self, model: Model, column_name: str
+ ) -> Dict[str, str]:
+ ret = {}
+ if column_name in self.extra_fields_rel_fields:
+ model_column_names = self.extra_fields_rel_fields.get(column_name)
+ if model_column_names:
+ for key in model_column_names:
+ ret[key] = getattr(model, key)
+ return ret
+
def _get_result_from_rows(
self, datamodel: SQLAInterface, rows: List[Model], column_name: str
) -> List[Dict[str, Any]]:
@@ -324,6 +345,7 @@ class BaseSupersetModelRestApi(ModelRestApi):
{
"value": datamodel.get_pk_value(row),
"text": self._get_text_for_model(row, column_name),
+ "extra": self._get_extra_field_for_model(row, column_name),
}
for row in rows
]
diff --git a/tests/integration_tests/base_api_tests.py b/tests/integration_tests/base_api_tests.py
index 8dbbb6862e..16cc8cc18d 100644
--- a/tests/integration_tests/base_api_tests.py
+++ b/tests/integration_tests/base_api_tests.py
@@ -264,10 +264,26 @@ class ApiOwnersTestCaseMixin:
assert 4 == response["count"]
sorted_results = sorted(response["result"], key=lambda value: value["text"])
expected_results = [
- {"text": "gamma user", "value": 2},
- {"text": "gamma2 user", "value": 3},
- {"text": "gamma_no_csv user", "value": 6},
- {"text": "gamma_sqllab user", "value": 4},
+ {
+ "extra": {"active": True, "email": "gamma@fab.org"},
+ "text": "gamma user",
+ "value": 2,
+ },
+ {
+ "extra": {"active": True, "email": "gamma2@fab.org"},
+ "text": "gamma2 user",
+ "value": 3,
+ },
+ {
+ "extra": {"active": True, "email": "gamma_no_csv@fab.org"},
+ "text": "gamma_no_csv user",
+ "value": 6,
+ },
+ {
+ "extra": {"active": True, "email": "gamma_sqllab@fab.org"},
+ "text": "gamma_sqllab user",
+ "value": 4,
+ },
]
# TODO Check me
assert expected_results == sorted_results
@@ -286,8 +302,16 @@ class ApiOwnersTestCaseMixin:
assert 2 == response["count"]
sorted_results = sorted(response["result"], key=lambda value: value["text"])
expected_results = [
- {"text": "gamma user", "value": 2},
- {"text": "gamma_sqllab user", "value": 4},
+ {
+ "extra": {"active": True, "email": "gamma@fab.org"},
+ "text": "gamma user",
+ "value": 2,
+ },
+ {
+ "extra": {"active": True, "email": "gamma_sqllab@fab.org"},
+ "text": "gamma_sqllab user",
+ "value": 4,
+ },
]
assert expected_results == sorted_results
@@ -305,8 +329,16 @@ class ApiOwnersTestCaseMixin:
assert 2 == response["count"]
sorted_results = sorted(response["result"], key=lambda value: value["text"])
expected_results = [
- {"text": "gamma user", "value": 2},
- {"text": "gamma_sqllab user", "value": 4},
+ {
+ "extra": {"active": True, "email": "gamma@fab.org"},
+ "text": "gamma user",
+ "value": 2,
+ },
+ {
+ "extra": {"active": True, "email": "gamma_sqllab@fab.org"},
+ "text": "gamma_sqllab user",
+ "value": 4,
+ },
]
assert expected_results == sorted_results
diff --git a/tests/integration_tests/queries/saved_queries/api_tests.py b/tests/integration_tests/queries/saved_queries/api_tests.py
index 2569e7af40..437225f6c5 100644
--- a/tests/integration_tests/queries/saved_queries/api_tests.py
+++ b/tests/integration_tests/queries/saved_queries/api_tests.py
@@ -445,7 +445,8 @@ class TestSavedQueryApi(SupersetTestCase):
expected_result = {
"count": len(databases),
"result": [
- {"text": str(database), "value": database.id} for database in databases
+ {"extra": {}, "text": str(database), "value": database.id}
+ for database in databases
],
}