Move change owner functionality to RepositoryRow

This commit is contained in:
Mojca Lorber 2019-04-29 14:02:02 +02:00
parent eac90109f7
commit 5fd4c47388
2 changed files with 7 additions and 6 deletions

View file

@ -30,4 +30,10 @@ class RepositoryRow < ApplicationRecord
def self.name_like(query)
where('repository_rows.name ILIKE ?', "%#{query}%")
end
def self.change_owner(team, user, new_owner)
joins(:repository)
.where('repositories.team_id = ? and repository_rows.created_by_id = ?', team, user)
.update_all(created_by_id: new_owner.id)
end
end

View file

@ -79,12 +79,7 @@ class UserTeam < ApplicationRecord
# Make new owner author of all inventory items that were added
# by departing user and belong to this team.
repository_rows =
RepositoryRow.joins(:repository)
.where('repositories.team_id = ? and repository_rows.created_by_id = ?', team, user)
repository_rows.find_each do |repository_row|
repository_row.update(created_by: new_owner)
end
RepositoryRow.change_owner(team, user, new_owner)
super()
end