Default search by active chat channel memberships only (#6325) [deploy]
This commit is contained in:
parent
81e2a5efc3
commit
c64ca9750c
4 changed files with 26 additions and 12 deletions
|
|
@ -110,7 +110,6 @@ export function getChannels(
|
|||
dataHash[key] = value;
|
||||
}
|
||||
dataHash.per_page = 30;
|
||||
dataHash.status = 'active';
|
||||
dataHash.page = paginationNumber;
|
||||
dataHash.channel_text = query;
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,11 @@ module Search
|
|||
def initialize(params, user_id)
|
||||
@params = params.deep_symbolize_keys
|
||||
@params[:viewable_by] = user_id
|
||||
|
||||
# TODO: @mstruve: When we want to allow people like admins to
|
||||
# search ALL memberships this will need to change
|
||||
@params[:status] = "active"
|
||||
|
||||
build_body
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -159,11 +159,11 @@ RSpec.describe Search::ChatChannelMembership, type: :service, elasticsearch: tru
|
|||
expect(chat_channel_membership_docs.first["id"]).to eq(chat_channel_membership2.id)
|
||||
end
|
||||
|
||||
it "searches by status" do
|
||||
it "only returns active status memberships" do
|
||||
chat_channel_membership1.update(status: "inactive")
|
||||
chat_channel_membership2.update(status: "active")
|
||||
index_documents([chat_channel_membership1, chat_channel_membership2])
|
||||
params = { size: 5, status: "active" }
|
||||
params = { size: 5 }
|
||||
|
||||
chat_channel_membership_docs = described_class.search_documents(params: params, user_id: user.id)
|
||||
expect(chat_channel_membership_docs.count).to eq(1)
|
||||
|
|
@ -188,10 +188,10 @@ RSpec.describe Search::ChatChannelMembership, type: :service, elasticsearch: tru
|
|||
end
|
||||
|
||||
it "sorts documents for given field" do
|
||||
chat_channel_membership1.update(status: "inactive")
|
||||
chat_channel_membership2.update(status: "active")
|
||||
allow(chat_channel_membership1).to receive(:channel_type).and_return("not_direct")
|
||||
allow(chat_channel_membership2).to receive(:channel_type).and_return("direct")
|
||||
index_documents([chat_channel_membership1, chat_channel_membership2])
|
||||
params = { size: 5, sort_by: "status", sort_direction: "asc" }
|
||||
params = { size: 5, sort_by: "channel_type", sort_direction: "asc" }
|
||||
|
||||
chat_channel_membership_docs = described_class.search_documents(params: params, user_id: user.id)
|
||||
expect(chat_channel_membership_docs.count).to eq(2)
|
||||
|
|
|
|||
|
|
@ -16,12 +16,12 @@ RSpec.describe Search::QueryBuilders::ChatChannelMembership, type: :service do
|
|||
|
||||
describe "#as_hash" do
|
||||
it "applies FILTER_KEYS from params" do
|
||||
params = { channel_status: "active", channel_type: "direct", status: "open" }
|
||||
params = { channel_status: "active", channel_type: "direct" }
|
||||
filter = described_class.new(params, 1)
|
||||
expected_filters = [
|
||||
{ "term" => { "channel_status" => "active" } },
|
||||
{ "term" => { "channel_type" => "direct" } },
|
||||
{ "term" => { "status" => "open" } },
|
||||
{ "term" => { "status" => "active" } },
|
||||
{ "term" => { "viewable_by" => 1 } },
|
||||
]
|
||||
expect(filter.as_hash.dig("query", "bool", "filter")).to match_array(expected_filters)
|
||||
|
|
@ -46,16 +46,26 @@ RSpec.describe Search::QueryBuilders::ChatChannelMembership, type: :service do
|
|||
"query" => "a_name*", "fields" => [:channel_text], "lenient" => true, "analyze_wildcard" => true
|
||||
}
|
||||
}]
|
||||
expected_filters = [{ "term" => { "channel_status" => "active" } }, { "term" => { "viewable_by" => 1 } }]
|
||||
expected_filters = [{ "term" => { "channel_status" => "active" } }, { "term" => { "viewable_by" => 1 } }, { "term" => { "status" => "active" } }]
|
||||
expect(query.as_hash.dig("query", "bool", "must")).to match_array(expected_query)
|
||||
expect(query.as_hash.dig("query", "bool", "filter")).to match_array(expected_filters)
|
||||
end
|
||||
|
||||
it "ignores params we dont support" do
|
||||
params = { not_supported: "direct", status: "closed" }
|
||||
it "always applies viewable_by and status params" do
|
||||
params = {}
|
||||
filter = described_class.new(params, 1)
|
||||
expected_filters = [
|
||||
{ "term" => { "status" => "closed" } },
|
||||
{ "term" => { "status" => "active" } },
|
||||
{ "term" => { "viewable_by" => 1 } },
|
||||
]
|
||||
expect(filter.as_hash.dig("query", "bool", "filter")).to match_array(expected_filters)
|
||||
end
|
||||
|
||||
it "ignores params we dont support" do
|
||||
params = { not_supported: "direct" }
|
||||
filter = described_class.new(params, 1)
|
||||
expected_filters = [
|
||||
{ "term" => { "status" => "active" } },
|
||||
{ "term" => { "viewable_by" => 1 } },
|
||||
]
|
||||
expect(filter.as_hash.dig("query", "bool", "filter")).to match_array(expected_filters)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue