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

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.

diff --git a/app/assets/javascripts/admin/routes/admin-search-logs-term.js.es6 b/app/assets/javascripts/admin/routes/admin-search-logs-term.js.es6
index 8d35930..54c145a 100644
--- a/app/assets/javascripts/admin/routes/admin-search-logs-term.js.es6
+++ b/app/assets/javascripts/admin/routes/admin-search-logs-term.js.es6
@@ -11,10 +11,11 @@ export default Discourse.Route.extend({
   model(params) {
     this._params = params;
 
-    return ajax(`/admin/logs/search_logs/term/${params.term}.json`, {
+    return ajax(`/admin/logs/search_logs/term.json`, {
       data: {
         period: params.period,
-        search_type: params.searchType
+        search_type: params.searchType,
+        term: params.term
       }
     }).then(json => {
       // Add zero values for missing dates
diff --git a/config/routes.rb b/config/routes.rb
index 968bc1f..9a82bf7 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -179,7 +179,7 @@ Discourse::Application.routes.draw do
       end
       post "watched_words/upload" => "watched_words#upload"
       resources :search_logs,           only: [:index]
-      get 'search_logs/term/:term' => 'search_logs#term'
+      get 'search_logs/term/' => 'search_logs#term'
     end
 
     get "/logs" => "staff_action_logs#index"
diff --git a/spec/requests/admin/search_logs_spec.rb b/spec/requests/admin/search_logs_spec.rb
index ed393c5..60a80fc 100644
--- a/spec/requests/admin/search_logs_spec.rb
+++ b/spec/requests/admin/search_logs_spec.rb
@@ -39,19 +39,29 @@ RSpec.describe Admin::SearchLogsController do
 
   context "#term" 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)
     end
 
     it "raises an error if you aren't an admin" do
       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)
     end
 
     it "should work if you are an admin" do
       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)
 
diff --git a/test/javascripts/helpers/create-pretender.js.es6 b/test/javascripts/helpers/create-pretender.js.es6
index 6a0a9eb..83ad588 100644
--- a/test/javascripts/helpers/create-pretender.js.es6
+++ b/test/javascripts/helpers/create-pretender.js.es6
@@ -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, {
         term: {
           type: "search_log_term",
           title: "Search Count",
+          term: "ruby",
           data: [{ x: "2017-07-20", y: 2 }]
         }
       });

GitHub sha: 8c2fa99f

1 Like

Follow up to 8c2fa99f782314ce1fde025090571ecb07f8b812.