Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CV2-4223 readd condition for checking if we should even search for the type #1780

Merged
merged 6 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions app/models/concerns/alegre_v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,14 @@ def get_confirmed_items(project_media, field)
end

def get_similar_items_v2(project_media, field)
suggested_or_confirmed = get_suggested_items(project_media, field)
confirmed = get_confirmed_items(project_media, field)
Bot::Alegre.merge_suggested_and_confirmed(suggested_or_confirmed, confirmed, project_media)
type = get_type(project_media)
if !Bot::Alegre.should_get_similar_items_of_type?('master', project_media.team_id) || !Bot::Alegre.should_get_similar_items_of_type?(type, project_media.team_id)
{}
else
suggested_or_confirmed = get_suggested_items(project_media, field)
confirmed = get_confirmed_items(project_media, field)
Bot::Alegre.merge_suggested_and_confirmed(suggested_or_confirmed, confirmed, project_media)
end
end

def relate_project_media(project_media, field=nil)
Expand Down
20 changes: 19 additions & 1 deletion test/models/bot/alegre_v2_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -650,4 +650,22 @@ def teardown
assert_equal relationship.relationship_type, Relationship.suggested_type
Bot::Alegre.unstub(:get_similar_items_v2)
end
end

test "should not relate project media for audio if disabled on workspace" do
tbi = TeamBotInstallation.where(team: @team, user: @bot).last
tbi.set_audio_similarity_enabled = false
tbi.save!
Bot::Alegre.stubs(:merge_suggested_and_confirmed).never
pm = create_project_media team: @team, media: create_uploaded_audio
assert_equal({}, Bot::Alegre.get_similar_items_v2(pm, nil))
end

test "should not relate project media for image if disabled on workspace" do
tbi = TeamBotInstallation.where(team: @team, user: @bot).last
tbi.set_image_similarity_enabled = false
tbi.save!
Bot::Alegre.stubs(:merge_suggested_and_confirmed).never
pm = create_project_media team: @team, media: create_uploaded_image
assert_equal({}, Bot::Alegre.get_similar_items_v2(pm, nil))
end
end
Loading