Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add user filtering to changed_by. Fixes #27986 #29287

Merged
merged 6 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions superset/charts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
14 changes: 13 additions & 1 deletion superset/css_templates/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions superset/dashboards/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,15 @@ 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: []]],
}

related_field_filters = {
"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"}

Expand Down
9 changes: 9 additions & 0 deletions superset/databases/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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("/<int:pk>/connection", methods=("GET",))
@protect()
@safe
Expand Down
2 changes: 2 additions & 0 deletions superset/datasets/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 2 additions & 0 deletions superset/queries/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}

Expand Down
8 changes: 7 additions & 1 deletion superset/queries/saved_queries/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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"}

Expand Down
2 changes: 2 additions & 0 deletions superset/reports/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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),
}

Expand Down
11 changes: 10 additions & 1 deletion superset/row_level_security/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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
Expand Down
Loading