mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-06 15:05:26 +08:00
Merge pull request #288 from Ducz0r/lm-sci-675-fix
Fix a bug where user could be assigned to same project twice [SCI-675]
This commit is contained in:
commit
e4b3d397a0
1 changed files with 14 additions and 7 deletions
|
@ -29,9 +29,15 @@ class UserOrganization < ActiveRecord::Base
|
||||||
# If any project of the organization has the sole owner and that
|
# If any project of the organization has the sole owner and that
|
||||||
# owner is the user to be removed from the organization, then we must
|
# owner is the user to be removed from the organization, then we must
|
||||||
# create a new owner of the project (the provided user).
|
# create a new owner of the project (the provided user).
|
||||||
organization.projects.each do |project|
|
organization.projects.find_each do |project|
|
||||||
owners = project.user_projects.where(role: 0)
|
owners = project.user_projects.where(role: 0)
|
||||||
if owners.count == 1 && owners.first.user == user
|
if owners.count == 1 && owners.first.user == user
|
||||||
|
if project.users.exists?(new_owner.id)
|
||||||
|
# If the new owner is already assigned onto project,
|
||||||
|
# update its role
|
||||||
|
project.user_projects.find_by(user: new_owner).update(role: 0)
|
||||||
|
else
|
||||||
|
# Else, create a new association
|
||||||
UserProject.create(
|
UserProject.create(
|
||||||
user: new_owner,
|
user: new_owner,
|
||||||
project: project,
|
project: project,
|
||||||
|
@ -40,6 +46,7 @@ class UserOrganization < ActiveRecord::Base
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Also, make new owner author of all protocols that belong
|
# Also, make new owner author of all protocols that belong
|
||||||
# to the departing user.
|
# to the departing user.
|
||||||
|
|
Loading…
Reference in a new issue