Skip to content

Commit

Permalink
Fixing how feed filters are applied until a list is chosen. (#1832)
Browse files Browse the repository at this point in the history
Reference: CV2-4398.
  • Loading branch information
caiosba committed Mar 22, 2024
1 parent 7b42d68 commit 10747e1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
9 changes: 6 additions & 3 deletions app/models/feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ def get_team_filters(feed_team_ids = nil)
conditions = { shared: true }
conditions[:team_id] = feed_team_ids if feed_team_ids.is_a?(Array)
self.feed_teams.where(conditions).find_each do |ft|
filter = ft.filters
filter = self.saved_search&.filters.to_h if self.team_id == ft.team_id
filters << filter.to_h.reject{ |k, _v| PROHIBITED_FILTERS.include?(k.to_s) }.merge({ 'team_id' => ft.team_id })
saved_search = self.team_id == ft.team_id ? self.saved_search : ft.saved_search
if saved_search.blank? # Do not share anything from this team if they haven't chosen a list yet
filters << { 'team_id' => ft.team_id, 'report_status' => ['none'] }
else
filters << saved_search.filters.to_h.reject{ |k, _v| PROHIBITED_FILTERS.include?(k.to_s) }.merge({ 'team_id' => ft.team_id })
end
end
filters
end
Expand Down
39 changes: 39 additions & 0 deletions test/controllers/elastic_search_10_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -440,4 +440,43 @@ def setup
assert_empty result.medias.map(&:id)
Team.current = nil
end

test "should not apply feed filters until a list is chosen" do
t1 = create_team
create_project_media team: t1, disable_es_callbacks: false
create_project_media team: t1, disable_es_callbacks: false
ss1 = create_saved_search team: t1, filters: {}
f = create_feed team: t1, saved_search: nil, data_points: [1, 2], published: true
t2 = create_team
create_project_media team: t2, disable_es_callbacks: false
ss2 = create_saved_search team: t2, filters: {}
ft = create_feed_team feed: f, team: t2, saved_search: nil, shared: true
sleep 2
Team.current = t1
query = { feed_id: f.id, feed_view: 'media', show_similar: true }

# No workspace has chosen a list yet
assert_equal 0, CheckSearch.new(query.to_json, nil, t1.id).number_of_results

# Only the first workspace has chosen a list
f.saved_search = ss1
f.save!
assert_equal 2, CheckSearch.new(query.to_json, nil, t1.id).number_of_results

# Only the second workspace has chosen a list
f.saved_search = nil
f.save!
ft.saved_search = ss2
ft.save!
assert_equal 1, CheckSearch.new(query.to_json, nil, t1.id).number_of_results

# Both workspaces have chosen a list
f.saved_search = ss1
f.save!
ft.saved_search = ss2
ft.save!
assert_equal 3, CheckSearch.new(query.to_json, nil, t1.id).number_of_results

Team.current = nil
end
end
8 changes: 6 additions & 2 deletions test/models/bot/smooch_5_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ def teardown
f1 = create_feed team_id: t1.id, published: true, data_points: [1, 2]
f1.teams << t2
FeedTeam.update_all(shared: true)
ft = FeedTeam.last
ft_ss = create_saved_search team: t2, filters: {}
ft.saved_search = ft_ss
ft.save!
f1.teams << t3
ft_ss = create_saved_search team: t1, filters: { keyword: 'Bar' }
f1.saved_search = ft_ss
f_ss = create_saved_search team: t1, filters: { keyword: 'Bar' }
f1.saved_search = f_ss
f1.save!
u = create_bot_user
[t1, t2, t3, t4].each { |t| TeamUser.create!(user: u, team: t, role: 'editor') }
Expand Down
6 changes: 6 additions & 0 deletions test/models/request_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ def setup
f.teams << t2
f.teams << t3
f.teams << t4
ss2 = create_saved_search team: t2, filters: {}
ss3 = create_saved_search team: t3, filters: {}
ss4 = create_saved_search team: t4, filters: {}
FeedTeam.where(team: t2, feed: f).update_all(saved_search_id: ss2.id)
FeedTeam.where(team: t3, feed: f).update_all(saved_search_id: ss3.id)
FeedTeam.where(team: t4, feed: f).update_all(saved_search_id: ss4.id)
FeedTeam.update_all(shared: true)
f.teams << t5
m = create_uploaded_image
Expand Down

0 comments on commit 10747e1

Please sign in to comment.