Skip to content

A platform for community discussion. Free, open, simple.

FIX: Restore default format for data-explorer endpoints (#38503)

David Taylore9e7f85bab38
diff --git a/plugins/discourse-data-explorer/config/routes.rb b/plugins/discourse-data-explorer/config/routes.rb
index 106891739b3..219ba232926 100644
--- a/plugins/discourse-data-explorer/config/routes.rb
+++ b/plugins/discourse-data-explorer/config/routes.rb
@@ -35,13 +35,15 @@ Discourse::Application.routes.draw do
# Legacy /admin/plugins/explorer/ API routes - route directly to controller
# since redirects don't preserve POST/PUT/DELETE request bodies
- get "/admin/plugins/explorer/schema" => "discourse_data_explorer/query#schema"
- get "/admin/plugins/explorer/groups" => "discourse_data_explorer/query#groups"
- post "/admin/plugins/explorer/queries" => "discourse_data_explorer/query#create"
- put "/admin/plugins/explorer/queries/:id" => "discourse_data_explorer/query#update"
- delete "/admin/plugins/explorer/queries/:id" => "discourse_data_explorer/query#destroy"
- post "/admin/plugins/explorer/queries/:id/run" => "discourse_data_explorer/query#run",
- :constraints => {
- format: /(json|csv)/,
- }
+ scope "/", defaults: { format: :json } do
+ get "/admin/plugins/explorer/schema" => "discourse_data_explorer/query#schema"
+ get "/admin/plugins/explorer/groups" => "discourse_data_explorer/query#groups"
+ post "/admin/plugins/explorer/queries" => "discourse_data_explorer/query#create"
+ put "/admin/plugins/explorer/queries/:id" => "discourse_data_explorer/query#update"
+ delete "/admin/plugins/explorer/queries/:id" => "discourse_data_explorer/query#destroy"
+ post "/admin/plugins/explorer/queries/:id/run" => "discourse_data_explorer/query#run",
+ :constraints => {
+ format: /(json|csv)/,
+ }
+ end
end
diff --git a/plugins/discourse-data-explorer/spec/requests/query_controller_spec.rb b/plugins/discourse-data-explorer/spec/requests/query_controller_spec.rb
index 81fe8f92233..9a61fb98aa6 100644
--- a/plugins/discourse-data-explorer/spec/requests/query_controller_spec.rb
+++ b/plugins/discourse-data-explorer/spec/requests/query_controller_spec.rb
@@ -781,5 +781,20 @@ describe DiscourseDataExplorer::QueryController do
expect(response.parsed_body["columns"]).to eq(["legacy_value"])
expect(response.parsed_body["rows"]).to eq([[42]])
end
+
+ it "serves POST /admin/plugins/explorer/queries/:id/run without .json suffix or Accept header" do
+ query = make_query("SELECT 42 as legacy_value")
+ post "/admin/plugins/explorer/queries/#{query.id}/run",
+ params: {
+ params: {}.to_json,
+ },
+ headers: {
+ "Accept" => "",
+ }
+ expect(response.status).to eq(200)
+ expect(response.parsed_body["success"]).to eq(true)
+ expect(response.parsed_body["columns"]).to eq(["legacy_value"])
+ expect(response.parsed_body["rows"]).to eq([[42]])
+ end
end
end