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

[api] Fix, related fields need to be explicitly defined #9283

Merged
merged 3 commits into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions superset/datasets/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class DatasetRestApi(BaseSupersetModelRestApi):

filter_rel_fields_field = {"owners": "first_name", "database": "database_name"}
filter_rel_fields = {"database": [["id", DatabaseFilter, lambda: []]]}
allowed_rel_fields = {"database"}
dpgaspar marked this conversation as resolved.
Show resolved Hide resolved

@expose("/", methods=["POST"])
@protect()
Expand Down
5 changes: 4 additions & 1 deletion superset/views/base_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# under the License.
import functools
import logging
from typing import Dict, Tuple
from typing import Set, Dict, Tuple

from flask import request
from flask_appbuilder import ModelRestApi
Expand Down Expand Up @@ -101,6 +101,7 @@ class BaseSupersetModelRestApi(ModelRestApi):
"<RELATED_FIELD>": "<FILTER>")
}
""" # pylint: disable=pointless-string-statement
allowed_rel_fields: Set[str] = set()

def __init__(self):
super().__init__()
Expand Down Expand Up @@ -191,6 +192,8 @@ def related(self, column_name: str, **kwargs):
500:
$ref: '#/components/responses/500'
"""
if column_name not in self.allowed_rel_fields:
return self.response_404()
args = kwargs.get("rison", {})
# handle pagination
page, page_size = self._handle_page_args(args)
Expand Down
3 changes: 2 additions & 1 deletion superset/views/chart/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,5 @@ class ChartRestApi(SliceMixin, BaseOwnedModelRestApi):
"slices": ("slice_name", "asc"),
"owners": ("first_name", "asc"),
}
filter_rel_fields_field = {"owners": "first_name", "dashboards": "dashboard_title"}
filter_rel_fields_field = {"owners": "first_name"}
allowed_rel_fields = {"owners"}
3 changes: 2 additions & 1 deletion superset/views/dashboard/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ class DashboardRestApi(DashboardMixin, BaseOwnedModelRestApi):
"slices": ("slice_name", "asc"),
"owners": ("first_name", "asc"),
}
filter_rel_fields_field = {"owners": "first_name", "slices": "slice_name"}
filter_rel_fields_field = {"owners": "first_name"}
allowed_rel_fields = {"owners"}

@expose("/", methods=["DELETE"])
@protect()
Expand Down