Merge pull request #1706 from mlorb/ml-sci-3350

Change ownership of inventory items, when a user leaves a team [SCI-3350]
This commit is contained in:
mlorb 2019-04-30 10:39:14 +02:00 committed by GitHub
commit 9f0983de77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 2 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

@ -77,6 +77,10 @@ class UserTeam < ApplicationRecord
protocol.save
end
# Make new owner author of all inventory items that were added
# by departing user and belong to this team.
RepositoryRow.change_owner(team, user, new_owner)
super()
end

View file

@ -15,6 +15,7 @@
<li><%= t("users.settings.user_teams.destroy_uo_alert_line_1") %></li>
<li><%= t("users.settings.user_teams.destroy_uo_alert_line_2").html_safe %></li>
<li><%= t("users.settings.user_teams.destroy_uo_alert_line_3") %></li>
<li><%= t("users.settings.user_teams.destroy_uo_alert_line_4") %></li>
</ul>
</div>
<% end %>

View file

@ -13,6 +13,7 @@
<li><%= t("users.settings.user_teams.leave_uo_alert_line_1") %></li>
<li><%= t("users.settings.user_teams.leave_uo_alert_line_2").html_safe %></li>
<li><%= t("users.settings.user_teams.leave_uo_alert_line_3")%></li>
<li><%= t("users.settings.user_teams.leave_uo_alert_line_4")%></li>
</ul>
</div>
<% end %>

View file

@ -1497,14 +1497,16 @@ en:
leave_uo_alert_heading: "Leaving team has following consequences:"
leave_uo_alert_line_1: "you will lose access to all content belonging to the team (including projects, tasks, protocols and activities);"
leave_uo_alert_line_2: "all projects in the team where you were the sole <b>Owner</b> will receive a new owner from the team administrators;"
leave_uo_alert_line_3: "all repository protocols in the team belonging to you will be reassigned onto a new owner from team administrators."
leave_uo_alert_line_3: "all repository protocols in the team belonging to you will be reassigned onto a new owner from team administrators;"
leave_uo_alert_line_4: "all inventory items in the team added by you will be reassigned onto a new owner from team administrators."
leave_uo_confirm: "Leave"
destroy_uo_heading: "Remove user %{user} from team %{team}"
destroy_uo_message: "Are you sure you wish to remove user %{user} from team %{team}?"
destroy_uo_alert_heading: "Removing user from team has following consequences:"
destroy_uo_alert_line_1: "user will lose access to all content belonging to the team (including projects, tasks, protocols and activities);"
destroy_uo_alert_line_2: "all projects in the team where user was the sole <b>Owner</b> will be reassigned onto you as a new owner;"
destroy_uo_alert_line_3: "all repository protocols in the team belonging to user will be reassigned onto you."
destroy_uo_alert_line_3: "all repository protocols in the team belonging to user will be reassigned onto you;"
destroy_uo_alert_line_4: "all inventory items in the team added by user will be reassigned onto you."
destroy_uo_confirm: "Remove"
leave_flash: "Successfuly left team %{team}."