From 6de49b88dfdc1f06692c91ab2f68b4bc8e7b3657 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Mon, 28 Oct 2019 13:18:47 +0000 Subject: [PATCH] FIX: Respond to user search correctly when category_id is blank Previously it would search for category_id=0, which does not exist. With the new permission checks, this returns a 404 --- app/controllers/users_controller.rb | 3 +-- spec/requests/users_controller_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a696aa4ab12..8d8386fa1f4 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -921,8 +921,7 @@ class UsersController < ApplicationController topic_id = params[:topic_id] topic_id = topic_id.to_i if topic_id - category_id = params[:category_id] - category_id = category_id.to_i if category_id + category_id = params[:category_id].to_i if category_id.present? topic_allowed_users = params[:topic_allowed_users] || false diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb index 63bb8279a22..0d454970f3b 100644 --- a/spec/requests/users_controller_spec.rb +++ b/spec/requests/users_controller_spec.rb @@ -3103,6 +3103,15 @@ describe UsersController do expect(json["users"].map { |u| u["username"] }).to include(privileged_user.username) end + it "interprets blank category id correctly" do + pm_topic = Fabricate(:private_message_post).topic + sign_in(pm_topic.user) + get "/u/search/users.json", params: { + term: "", topic_id: pm_topic.id, category_id: "" + } + expect(response.status).to eq(200) + end + context "when `enable_names` is true" do before do SiteSetting.enable_names = true