A platform for community discussion. Free, open, simple.
DEV: change GET `/admin/dashboard/problems.json` to POST as it performs a state-changing action (#38462)
Gabriel Grubba8c18481d86ce
diff --git a/config/routes.rb b/config/routes.rbindex dc08e0333ca..0f735fb51a0 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -342,7 +342,7 @@ Discourse::Application.routes.draw dopost "/toggle-feature" => "dashboard#toggle_feature"resources :dashboard, only: [:index] do- collection { get "problems" }+ collection { post "problems" }endresources :api, only: [:index], constraints: AdminConstraint.new dodiff --git a/frontend/discourse/admin/models/admin-dashboard.js b/frontend/discourse/admin/models/admin-dashboard.jsindex 3fcae043f67..651ab673d74 100644--- a/frontend/discourse/admin/models/admin-dashboard.js+++ b/frontend/discourse/admin/models/admin-dashboard.js@@ -8,39 +8,39 @@ const GENERAL_ATTRIBUTES = [];export default class AdminDashboard extends EmberObject {- static fetch() {- return ajax("/admin/dashboard.json").then((json) => {- const model = AdminDashboard.create();- model.setProperties({- version_check: json.version_check,- });-- return model;+ static async fetch() {+ const json = await ajax("/admin/dashboard.json");+ const model = AdminDashboard.create();++ model.setProperties({+ version_check: json.version_check,});- }- static fetchGeneral() {- return ajax("/admin/dashboard/general.json").then((json) => {- const model = AdminDashboard.create();+ return model;+ }- const attributes = {};- GENERAL_ATTRIBUTES.forEach((a) => (attributes[a] = json[a]));+ static async fetchGeneral() {+ const json = await ajax("/admin/dashboard/general.json");+ const model = AdminDashboard.create();- model.setProperties({- reports: json.reports,- attributes,- loaded: true,- });+ const attributes = {};+ GENERAL_ATTRIBUTES.forEach((a) => (attributes[a] = json[a]));- return model;+ model.setProperties({+ reports: json.reports,+ attributes,+ loaded: true,});++ return model;}- static fetchProblems() {- return ajax("/admin/dashboard/problems.json").then((json) => {- const model = AdminDashboard.create(json);- model.set("loaded", true);- return model;- });+ static async fetchProblems() {+ const json = await ajax("/admin/dashboard/problems.json", { type: "POST" });+ const model = AdminDashboard.create(json);++ model.set("loaded", true);++ return model;}}diff --git a/frontend/discourse/tests/helpers/create-pretender.js b/frontend/discourse/tests/helpers/create-pretender.jsindex cfe95294d87..f3b398729f7 100644--- a/frontend/discourse/tests/helpers/create-pretender.js+++ b/frontend/discourse/tests/helpers/create-pretender.js@@ -1053,6 +1053,10 @@ export function applyDefaultHandlers(pretender) {});});+ pretender.post("/admin/dashboard/problems.json", () => {+ return response(200, fixturesByUrl["/admin/dashboard/problems.json"]);+ });+pretender.get("/admin/customize/watched_words", () => {return response(200, fixturesByUrl["/admin/customize/watched_words.json"]);});diff --git a/spec/requests/admin/dashboard_controller_spec.rb b/spec/requests/admin/dashboard_controller_spec.rbindex 1ad3ee7ff1d..3e41daf09b0 100644--- a/spec/requests/admin/dashboard_controller_spec.rb+++ b/spec/requests/admin/dashboard_controller_spec.rb@@ -102,10 +102,9 @@ RSpec.describe Admin::DashboardController docontext "when logged in as an admin" dobefore { sign_in(admin) }-context "when there are no problems" doit "returns an empty array" do- get "/admin/dashboard/problems.json"+ post "/admin/dashboard/problems.json"expect(response.status).to eq(200)json = response.parsed_body@@ -120,7 +119,7 @@ RSpec.describe Admin::DashboardController doendit "returns an array of strings" do- get "/admin/dashboard/problems.json"+ post "/admin/dashboard/problems.json"expect(response.status).to eq(200)json = response.parsed_bodyexpect(json["problems"].size).to eq(2)@@ -137,7 +136,7 @@ RSpec.describe Admin::DashboardController doendit "returns a list of problems" do- get "/admin/dashboard/problems.json"+ post "/admin/dashboard/problems.json"expect(response.status).to eq(200)json = response.parsed_body@@ -149,7 +148,7 @@ RSpec.describe Admin::DashboardController dobefore { sign_in(user) }it "denies access with a 404 response" do- get "/admin/dashboard/problems.json"+ post "/admin/dashboard/problems.json"expect(response.status).to eq(404)expect(response.parsed_body["errors"]).to include(I18n.t("not_found"))