|
|
|
@@ -27,6 +27,19 @@ class Admins::UsersController < Admins::BaseController |
|
|
|
|
|
|
|
def destroy |
|
|
|
UserAction.create(action_id: @user.id, action_type: "DestroyUser", user_id: current_user.id, :ip => request.remote_ip, data_bank: @user.attributes.to_json) |
|
|
|
org_ids = TeamUser.where(user_id: @user.id).pluck(:organization_id) | OrganizationUser..where(user_id: @user.id).pluck(:organization_id) |
|
|
|
organizations = Organization.where(id: org_ids) |
|
|
|
organizations.each do |org| |
|
|
|
# org.team_users.joins(:team).where(user_id: @user.id, teams: {authorize: %w(owner)}) |
|
|
|
org.team_users.joins(:team).where(teams: {authorize: %w(owner)}) |
|
|
|
# 多个owner时,仅将用户从组织移除, 一个时直接删除 |
|
|
|
if org.count > 1 |
|
|
|
org.team_users.joins(:team).where(user_id: @user.id, teams: {authorize: %w(owner)}).destroy_all |
|
|
|
org.organization_users.where(user_id: @user.id, organization_id: org.id).destroy_all |
|
|
|
else |
|
|
|
org.destroy |
|
|
|
end |
|
|
|
end |
|
|
|
@user.destroy! |
|
|
|
Gitea::User::DeleteService.call(@user.login) |
|
|
|
|
|
|
|
|