FIX: Remove `:term` from `admin/search_logs/term/:term` route.

Search log terms is a string that can contain characters like `/` which
messes with the route.
This commit is contained in:
Guo Xiang Tan 2019-03-29 09:48:20 +08:00
parent c836d67cac
commit 8c2fa99f78
4 changed files with 19 additions and 7 deletions

View File

@ -11,10 +11,11 @@ export default Discourse.Route.extend({
model(params) { model(params) {
this._params = params; this._params = params;
return ajax(`/admin/logs/search_logs/term/${params.term}.json`, { return ajax(`/admin/logs/search_logs/term.json`, {
data: { data: {
period: params.period, period: params.period,
search_type: params.searchType search_type: params.searchType,
term: params.term
} }
}).then(json => { }).then(json => {
// Add zero values for missing dates // Add zero values for missing dates

View File

@ -179,7 +179,7 @@ Discourse::Application.routes.draw do
end end
post "watched_words/upload" => "watched_words#upload" post "watched_words/upload" => "watched_words#upload"
resources :search_logs, only: [:index] resources :search_logs, only: [:index]
get 'search_logs/term/:term' => 'search_logs#term' get 'search_logs/term/' => 'search_logs#term'
end end
get "/logs" => "staff_action_logs#index" get "/logs" => "staff_action_logs#index"

View File

@ -39,19 +39,29 @@ RSpec.describe Admin::SearchLogsController do
context "#term" do context "#term" do
it "raises an error if you aren't logged in" do it "raises an error if you aren't logged in" do
get '/admin/logs/search_logs/term/ruby.json' get '/admin/logs/search_logs/term.json', params: {
term: "ruby"
}
expect(response.status).to eq(404) expect(response.status).to eq(404)
end end
it "raises an error if you aren't an admin" do it "raises an error if you aren't an admin" do
sign_in(user) sign_in(user)
get '/admin/logs/search_logs/term/ruby.json'
get '/admin/logs/search_logs/term.json', params: {
term: "ruby"
}
expect(response.status).to eq(404) expect(response.status).to eq(404)
end end
it "should work if you are an admin" do it "should work if you are an admin" do
sign_in(admin) sign_in(admin)
get '/admin/logs/search_logs/term/ruby.json'
get '/admin/logs/search_logs/term.json', params: {
term: "ruby"
}
expect(response.status).to eq(200) expect(response.status).to eq(200)

View File

@ -577,11 +577,12 @@ export default function() {
]); ]);
}); });
this.get("/admin/logs/search_logs/term/ruby.json", () => { this.get("/admin/logs/search_logs/term.json", () => {
return response(200, { return response(200, {
term: { term: {
type: "search_log_term", type: "search_log_term",
title: "Search Count", title: "Search Count",
term: "ruby",
data: [{ x: "2017-07-20", y: 2 }] data: [{ x: "2017-07-20", y: 2 }]
} }
}); });