mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-08 06:04:35 +08:00
Please Hound
This commit is contained in:
parent
280b7a0e75
commit
1b6f50647c
1 changed files with 37 additions and 36 deletions
|
@ -36,7 +36,8 @@ module Users
|
||||||
render json: {
|
render json: {
|
||||||
html: render_to_string(
|
html: render_to_string(
|
||||||
partial:
|
partial:
|
||||||
'users/settings/user_teams/leave_user_team_modal_body.html.erb',
|
'users/settings/user_teams/' \
|
||||||
|
'leave_user_team_modal_body.html.erb',
|
||||||
locals: { user_team: @user_team }
|
locals: { user_team: @user_team }
|
||||||
),
|
),
|
||||||
heading: I18n.t(
|
heading: I18n.t(
|
||||||
|
@ -68,46 +69,46 @@ module Users
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
respond_to do |format|
|
# If user is last administrator of team,
|
||||||
# If user is last administrator of team,
|
# he/she cannot be deleted from it.
|
||||||
# he/she cannot be deleted from it.
|
invalid =
|
||||||
invalid =
|
@user_team.admin? &&
|
||||||
@user_team.admin? &&
|
@user_team
|
||||||
@user_team
|
.team
|
||||||
.team
|
.user_teams
|
||||||
.user_teams
|
.where(role: 2)
|
||||||
.where(role: 2)
|
.count <= 1
|
||||||
.count <= 1
|
|
||||||
|
|
||||||
unless invalid
|
unless invalid
|
||||||
begin
|
begin
|
||||||
UserTeam.transaction do
|
UserTeam.transaction do
|
||||||
# If user leaves on his/her own accord,
|
# If user leaves on his/her own accord,
|
||||||
# new owner for projects is the first
|
# new owner for projects is the first
|
||||||
# administrator of team
|
# administrator of team
|
||||||
if params[:leave]
|
if params[:leave]
|
||||||
new_owner =
|
new_owner =
|
||||||
@user_team
|
@user_team
|
||||||
.team
|
.team
|
||||||
.user_teams
|
.user_teams
|
||||||
.where(role: 2)
|
.where(role: 2)
|
||||||
.where.not(id: @user_team.id)
|
.where.not(id: @user_team.id)
|
||||||
.first
|
.first
|
||||||
.user
|
.user
|
||||||
else
|
else
|
||||||
# Otherwise, the new owner for projects is
|
# Otherwise, the new owner for projects is
|
||||||
# the current user (= an administrator removing
|
# the current user (= an administrator removing
|
||||||
# the user from the team)
|
# the user from the team)
|
||||||
new_owner = current_user
|
new_owner = current_user
|
||||||
end
|
|
||||||
reset_user_current_team(@user_team)
|
|
||||||
@user_team.destroy(new_owner)
|
|
||||||
end
|
end
|
||||||
rescue Exception
|
reset_user_current_team(@user_team)
|
||||||
invalid = true
|
@user_team.destroy(new_owner)
|
||||||
end
|
end
|
||||||
|
rescue Exception
|
||||||
|
invalid = true
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
if !invalid
|
if !invalid
|
||||||
if params[:leave]
|
if params[:leave]
|
||||||
flash[:notice] = I18n.t(
|
flash[:notice] = I18n.t(
|
||||||
|
|
Loading…
Add table
Reference in a new issue