diff --git a/superset/charts/api.py b/superset/charts/api.py index d814d0fa02a98..57a812fb74aba 100644 --- a/superset/charts/api.py +++ b/superset/charts/api.py @@ -269,10 +269,12 @@ def ensure_thumbnails_enabled(self) -> Optional[Response]: base_related_field_filters = { "owners": [["id", BaseFilterRelatedUsers, lambda: []]], "created_by": [["id", BaseFilterRelatedUsers, lambda: []]], + "changed_by": [["id", BaseFilterRelatedUsers, lambda: []]], } related_field_filters = { "owners": RelatedFieldFilter("first_name", FilterRelatedOwners), "created_by": RelatedFieldFilter("first_name", FilterRelatedOwners), + "changed_by": RelatedFieldFilter("first_name", FilterRelatedOwners), } allowed_rel_fields = {"owners", "created_by", "changed_by"} diff --git a/superset/css_templates/api.py b/superset/css_templates/api.py index ac222da66f815..5332553d4fd7d 100644 --- a/superset/css_templates/api.py +++ b/superset/css_templates/api.py @@ -35,7 +35,12 @@ ) from superset.extensions import event_logger from superset.models.core import CssTemplate -from superset.views.base_api import BaseSupersetModelRestApi, statsd_metrics +from superset.views.base_api import ( + BaseSupersetModelRestApi, + RelatedFieldFilter, + statsd_metrics, +) +from superset.views.filters import BaseFilterRelatedUsers, FilterRelatedOwners logger = logging.getLogger(__name__) @@ -91,6 +96,13 @@ class CssTemplateRestApi(BaseSupersetModelRestApi): openapi_spec_tag = "CSS Templates" openapi_spec_methods = openapi_spec_methods_override + related_field_filters = { + "changed_by": RelatedFieldFilter("first_name", FilterRelatedOwners), + } + base_related_field_filters = { + "changed_by": [["id", BaseFilterRelatedUsers, lambda: []]], + } + @expose("/", methods=("DELETE",)) @protect() @safe diff --git a/superset/dashboards/api.py b/superset/dashboards/api.py index 716e4c416d0e1..1e0ecacb65f77 100644 --- a/superset/dashboards/api.py +++ b/superset/dashboards/api.py @@ -271,6 +271,7 @@ def ensure_thumbnails_enabled(self) -> Optional[Response]: base_related_field_filters = { "owners": [["id", BaseFilterRelatedUsers, lambda: []]], "created_by": [["id", BaseFilterRelatedUsers, lambda: []]], + "changed_by": [["id", BaseFilterRelatedUsers, lambda: []]], "roles": [["id", BaseFilterRelatedRoles, lambda: []]], } @@ -278,6 +279,7 @@ def ensure_thumbnails_enabled(self) -> Optional[Response]: "owners": RelatedFieldFilter("first_name", FilterRelatedOwners), "roles": RelatedFieldFilter("name", FilterRelatedRoles), "created_by": RelatedFieldFilter("first_name", FilterRelatedOwners), + "changed_by": RelatedFieldFilter("first_name", FilterRelatedOwners), } allowed_rel_fields = {"owners", "roles", "created_by", "changed_by"} diff --git a/superset/databases/api.py b/superset/databases/api.py index af5ce255aefe8..d490ac70dab55 100644 --- a/superset/databases/api.py +++ b/superset/databases/api.py @@ -125,11 +125,13 @@ from superset.utils.ssh_tunnel import mask_password_info from superset.views.base_api import ( BaseSupersetModelRestApi, + RelatedFieldFilter, requires_form_data, requires_json, statsd_metrics, ) from superset.views.error_handling import json_error_response +from superset.views.filters import BaseFilterRelatedUsers, FilterRelatedOwners logger = logging.getLogger(__name__) @@ -304,6 +306,13 @@ class DatabaseRestApi(BaseSupersetModelRestApi): openapi_spec_methods = openapi_spec_methods_override """ Overrides GET methods OpenApi descriptions """ + related_field_filters = { + "changed_by": RelatedFieldFilter("first_name", FilterRelatedOwners), + } + base_related_field_filters = { + "changed_by": [["id", BaseFilterRelatedUsers, lambda: []]], + } + @expose("//connection", methods=("GET",)) @protect() @safe diff --git a/superset/datasets/api.py b/superset/datasets/api.py index 0f14be1a6d175..f8f6bdc0b9604 100644 --- a/superset/datasets/api.py +++ b/superset/datasets/api.py @@ -242,10 +242,12 @@ class DatasetRestApi(BaseSupersetModelRestApi): base_related_field_filters = { "owners": [["id", BaseFilterRelatedUsers, lambda: []]], + "changed_by": [["id", BaseFilterRelatedUsers, lambda: []]], "database": [["id", DatabaseFilter, lambda: []]], } related_field_filters = { "owners": RelatedFieldFilter("first_name", FilterRelatedOwners), + "changed_by": RelatedFieldFilter("first_name", FilterRelatedOwners), "database": "database_name", } search_filters = { diff --git a/superset/queries/api.py b/superset/queries/api.py index 67afd8a81763c..5d1ed10d0650e 100644 --- a/superset/queries/api.py +++ b/superset/queries/api.py @@ -144,11 +144,13 @@ class QueryRestApi(BaseSupersetModelRestApi): ] base_related_field_filters = { "created_by": [["id", BaseFilterRelatedUsers, lambda: []]], + "changed_by": [["id", BaseFilterRelatedUsers, lambda: []]], "user": [["id", BaseFilterRelatedUsers, lambda: []]], "database": [["id", DatabaseFilter, lambda: []]], } related_field_filters = { "created_by": RelatedFieldFilter("first_name", FilterRelatedOwners), + "changed_by": RelatedFieldFilter("first_name", FilterRelatedOwners), "user": RelatedFieldFilter("first_name", FilterRelatedOwners), } diff --git a/superset/queries/saved_queries/api.py b/superset/queries/saved_queries/api.py index 4e34a75039f12..8a4fe32fb41ea 100644 --- a/superset/queries/saved_queries/api.py +++ b/superset/queries/saved_queries/api.py @@ -56,9 +56,11 @@ from superset.utils import json from superset.views.base_api import ( BaseSupersetModelRestApi, + RelatedFieldFilter, requires_form_data, statsd_metrics, ) +from superset.views.filters import BaseFilterRelatedUsers, FilterRelatedOwners logger = logging.getLogger(__name__) @@ -179,8 +181,12 @@ class SavedQueryRestApi(BaseSupersetModelRestApi): related_field_filters = { "database": "database_name", + "changed_by": RelatedFieldFilter("first_name", FilterRelatedOwners), + } + base_related_field_filters = { + "database": [["id", DatabaseFilter, lambda: []]], + "changed_by": [["id", BaseFilterRelatedUsers, lambda: []]], } - base_related_field_filters = {"database": [["id", DatabaseFilter, lambda: []]]} allowed_rel_fields = {"database", "changed_by", "created_by"} allowed_distinct_fields = {"catalog", "schema"} diff --git a/superset/reports/api.py b/superset/reports/api.py index 4a298b564dd8c..f8dd15e2f07ef 100644 --- a/superset/reports/api.py +++ b/superset/reports/api.py @@ -224,6 +224,7 @@ def ensure_alert_reports_enabled(self) -> Optional[Response]: "database": [["id", DatabaseFilter, lambda: []]], "owners": [["id", BaseFilterRelatedUsers, lambda: []]], "created_by": [["id", BaseFilterRelatedUsers, lambda: []]], + "changed_by": [["id", BaseFilterRelatedUsers, lambda: []]], } text_field_rel_fields = { "dashboard": "dashboard_title", @@ -235,6 +236,7 @@ def ensure_alert_reports_enabled(self) -> Optional[Response]: "chart": "slice_name", "database": "database_name", "created_by": RelatedFieldFilter("first_name", FilterRelatedOwners), + "changed_by": RelatedFieldFilter("first_name", FilterRelatedOwners), "owners": RelatedFieldFilter("first_name", FilterRelatedOwners), } diff --git a/superset/row_level_security/api.py b/superset/row_level_security/api.py index 077d55ff4ebb7..7ea0959842d03 100644 --- a/superset/row_level_security/api.py +++ b/superset/row_level_security/api.py @@ -47,10 +47,15 @@ from superset.views.base import DatasourceFilter from superset.views.base_api import ( BaseSupersetModelRestApi, + RelatedFieldFilter, requires_json, statsd_metrics, ) -from superset.views.filters import BaseFilterRelatedRoles +from superset.views.filters import ( + BaseFilterRelatedRoles, + BaseFilterRelatedUsers, + FilterRelatedOwners, +) logger = logging.getLogger(__name__) @@ -129,9 +134,13 @@ class RLSRestApi(BaseSupersetModelRestApi): edit_model_schema = RLSPutSchema() allowed_rel_fields = {"tables", "roles", "created_by", "changed_by"} + related_field_filters = { + "changed_by": RelatedFieldFilter("first_name", FilterRelatedOwners), + } base_related_field_filters = { "tables": [["id", DatasourceFilter, lambda: []]], "roles": [["id", BaseFilterRelatedRoles, lambda: []]], + "changed_by": [["id", BaseFilterRelatedUsers, lambda: []]], } openapi_spec_methods = openapi_spec_methods_override