|
|
|
@@ -119,7 +119,7 @@ class Api::V1::UsersController < Api::V1::BaseController |
|
|
|
|
|
|
|
def check_user_can_delete |
|
|
|
org_ids = TeamUser.where(user_id: @observe_user.id).pluck(:organization_id) | OrganizationUser.where(user_id: @observe_user.id).pluck(:organization_id) |
|
|
|
org_count = Organization.where(id: org_ids).count |
|
|
|
org_count = TeamUser.where(organization_id: org_ids).where(user_id: @observe_user.id).joins(:team).where(teams: {authorize: %w(owner)}).count |
|
|
|
project_count = Project.where(user_id: @observe_user.id).count |
|
|
|
render_ok({ can_delete: org_count == 0 && project_count == 0, org_count: org_count, project_count: project_count }) |
|
|
|
end |
|
|
|
@@ -128,7 +128,7 @@ class Api::V1::UsersController < Api::V1::BaseController |
|
|
|
def destroy |
|
|
|
return tip_exception(-1, "密码不正确.") unless @observe_user.check_password?(params[:password]) |
|
|
|
org_ids = TeamUser.where(user_id: @observe_user.id).pluck(:organization_id) | OrganizationUser.where(user_id: @observe_user.id).pluck(:organization_id) |
|
|
|
org_count = Organization.where(id: org_ids).count |
|
|
|
org_count = TeamUser.where(organization_id: org_ids).where(user_id: @observe_user.id).joins(:team).where(teams: {authorize: %w(owner)}).count |
|
|
|
project_count = Project.where(user_id: @observe_user.id).count |
|
|
|
return tip_exception(-1, "当前账号名下存在未删除或退出的组织/仓库,请先删除或退出后再尝试注销操作.") if org_count > 0 || project_count > 0 |
|
|
|
UserAction.create(action_id: @observe_user.id, action_type: "DestroyUser", user_id: @observe_user.id, :ip => request.remote_ip, data_bank: @observe_user.attributes.to_json, memo: params[:memo]) |
|
|
|
|