mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-26 17:51:13 +08:00
Move change owner functionality to RepositoryRow
This commit is contained in:
parent
eac90109f7
commit
5fd4c47388
2 changed files with 7 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue