Skip to content

Commit

Permalink
DEV: add an option in user-chooser to list staged users (#13201)
Browse files Browse the repository at this point in the history
* DEV: add an option in user-chooser to list staged users

* included rspec tests

* force boolean
  • Loading branch information
fzngagan committed May 31, 2021
1 parent 0922a69 commit 8085fc6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/assets/javascripts/discourse/app/lib/user-search.js
Expand Up @@ -21,6 +21,7 @@ function performSearch(
includeMessageableGroups,
allowedUsers,
groupMembersOf,
includeStagedUsers,
resultsFn
) {
let cached = cache[term];
Expand Down Expand Up @@ -49,6 +50,7 @@ function performSearch(
include_messageable_groups: includeMessageableGroups,
groups: groupMembersOf,
topic_allowed_users: allowedUsers,
include_staged_users: includeStagedUsers,
},
});

Expand Down Expand Up @@ -90,6 +92,7 @@ let debouncedSearch = function (
includeMessageableGroups,
allowedUsers,
groupMembersOf,
includeStagedUsers,
resultsFn
) {
discourseDebounce(
Expand All @@ -103,6 +106,7 @@ let debouncedSearch = function (
includeMessageableGroups,
allowedUsers,
groupMembersOf,
includeStagedUsers,
resultsFn,
300
);
Expand Down Expand Up @@ -189,7 +193,8 @@ export default function userSearch(options) {
allowedUsers = options.allowedUsers,
topicId = options.topicId,
categoryId = options.categoryId,
groupMembersOf = options.groupMembersOf;
groupMembersOf = options.groupMembersOf,
includeStagedUsers = options.includeStagedUsers;

if (oldSearch) {
oldSearch.abort();
Expand Down Expand Up @@ -226,6 +231,7 @@ export default function userSearch(options) {
includeMessageableGroups,
allowedUsers,
groupMembersOf,
includeStagedUsers,
function (r) {
cancel(clearPromise);
resolve(organizeResults(r, options));
Expand Down
Expand Up @@ -75,6 +75,7 @@ export default MultiSelectComponent.extend({
includeMessageableGroups: options.includeMessageableGroups,
groupMembersOf: options.groupMembersOf,
allowEmails: options.allowEmails,
includeStagedUsers: this.includeStagedUsers,
}).then((result) => {
if (typeof result === "string") {
// do nothing promise probably got cancelled
Expand Down
1 change: 1 addition & 0 deletions app/controllers/users_controller.rb
Expand Up @@ -1074,6 +1074,7 @@ def search_users
groups: @groups
}

options[:include_staged_users] = !!ActiveModel::Type::Boolean.new.cast(params[:include_staged_users])
options[:topic_id] = topic_id if topic_id
options[:category_id] = category_id if category_id

Expand Down
21 changes: 21 additions & 0 deletions spec/requests/users_controller_spec.rb
Expand Up @@ -3731,6 +3731,7 @@ def create_and_like_post(likee, liker)
fab!(:topic) { Fabricate :topic }
let(:user) { Fabricate :user, username: "joecabot", name: "Lawrence Tierney" }
let(:post1) { Fabricate(:post, user: user, topic: topic) }
let(:staged_user) { Fabricate(:user, staged: true) }

before do
SearchIndexer.enable
Expand Down Expand Up @@ -4000,6 +4001,26 @@ def users_found
end
end
end

context '`include_staged_users`' do
it "includes staged users when the param is true" do
get "/u/search/users.json", params: { term: staged_user.name, include_staged_users: true }
json = response.parsed_body
expect(json["users"].map { |u| u["name"] }).to include(staged_user.name)
end

it "doesn't include staged users when the param is not passed" do
get "/u/search/users.json", params: { term: staged_user.name }
json = response.parsed_body
expect(json["users"].map { |u| u["name"] }).not_to include(staged_user.name)
end

it "doesn't include staged users when the param explicitly set to false" do
get "/u/search/users.json", params: { term: staged_user.name, include_staged_users: false }
json = response.parsed_body
expect(json["users"].map { |u| u["name"] }).not_to include(staged_user.name)
end
end
end

describe '#email_login' do
Expand Down

0 comments on commit 8085fc6

Please sign in to comment.