Skip to content

Commit

Permalink
Make sure that the current relationship user overwrites the previous …
Browse files Browse the repository at this point in the history
…user when moving targets to a new source (#2165)

Imagine we have items A and B. B has a similar item C. If B is added as similar to A, then C will also be moved from B to A.

Previously, in that operation, the user who created the relationship between B and C would be set as the user who created the relationship between A and C, but that's problematic - for example, it can prevent reports from being sent.

The fix here is to set that the user who created the new relationship between A and C is not the same user who created the relationship between B and C, but instead, it's the user who created the relationship between A and B.

Fixes: CV2-5837.
  • Loading branch information
caiosba authored Dec 21, 2024
1 parent eb1d6d4 commit 9a3263c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/relationship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def point_targets_to_new_source
Relationship.where(source_id: self.target_id).find_each do |old_relationship|
old_relationship.delete
options = {
user_id: old_relationship.user_id,
user_id: User.current&.id || old_relationship.user_id,
weight: old_relationship.weight
}
Relationship.create_unless_exists(self.source_id, old_relationship.target_id, old_relationship.relationship_type, options)
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/version.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = '0.0.1'
VERSION = 'v0.185.3'
15 changes: 15 additions & 0 deletions test/models/relationship_2_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -488,4 +488,19 @@ def teardown
assert Relationship.where(source: a, target: b).exists?
assert !Relationship.where(source: a, target: c).exists?
end

test "should set current user when moving targets to new source" do
t = create_team
u1 = create_user is_admin: true
u2 = create_user is_admin: true
a = create_project_media team: t
b = create_project_media team: t
c = create_project_media team: t
create_relationship source: b, target: c, user: u1
with_current_user_and_team(u2, t) do
create_relationship source: a, target: b
end
r = Relationship.where(source: a, target: c).last
assert_equal u2, r.reload.user
end
end

0 comments on commit 9a3263c

Please sign in to comment.