Skip to content

Commit

Permalink
#894: updates to 'update-settings' endpoint
Browse files Browse the repository at this point in the history
aschonfeld committed Dec 13, 2024
1 parent 5310812 commit 1e26ed3
Showing 2 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions dtale/views.py
Original file line number Diff line number Diff line change
@@ -1625,6 +1625,13 @@ def update_settings(data_id):
"""

updated_settings = get_json_arg(request, "settings", {})

# block users from manually updating 'enable_custom_filters'
if "enable_custom_filters" in updated_settings:
raise ValueError(
"Cannot alter the property 'enable_custom_filters' from this endpoint"
)

if not global_state.load_flag(data_id, "enable_custom_filters", False):
updated_settings.pop("query", None)

15 changes: 15 additions & 0 deletions tests/dtale/test_views.py
Original file line number Diff line number Diff line change
@@ -585,6 +585,21 @@ def test_update_settings(test_data, unittest):
response_data = response.get_json()
assert "error" in response_data

settings = json.dumps(dict(enable_custom_filters=True))
with app.test_client() as c:
with ExitStack() as stack:
global_state.set_data(c.port, None)
response = c.get(
"/dtale/update-settings/{}".format(c.port),
query_string=dict(settings=settings),
)
assert response.status_code == 200, "should return 200 response"
response_data = response.get_json()
assert (
response_data["error"]
== "Cannot alter the property 'enable_custom_filters' from this endpoint"
)


@pytest.mark.unit
def test_update_formats():

0 comments on commit 1e26ed3

Please sign in to comment.