fixed 删除用户时删除讨论数据

This commit is contained in:
xxq250 2024-10-08 15:01:38 +08:00
parent 94667f4b71
commit 66a7c4eb00
1 changed files with 12 additions and 5 deletions

View File

@ -13,14 +13,16 @@ class Api::V1::Users::DeleteUserService < ApplicationService
# org.team_users.joins(:team).where(user_id: @user.id, teams: {authorize: %w(owner)})
owner_count = org.team_users.joins(:team).where(teams: {authorize: %w(owner)}).count
# 多个owner时,仅将用户从组织移除, 一个时直接删除
if owner_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
org.team_users.where(user_id: @user.id).destroy_all
org.organization_users.where(user_id: @user.id, organization_id: org.id).destroy_all
if owner_count == 1
if org.team_users.joins(:team).where(user_id: @user.id, teams: { authorize: %w(owner) }).count > 0
org.destroy!
end
end
end
@user.destroy!
del_user_data_by_sql(@user.id)
Gitea::User::DeleteService.call(@user.login, true)
end
return true
@ -28,4 +30,9 @@ class Api::V1::Users::DeleteUserService < ApplicationService
raise Error, "服务器错误,请联系系统管理员!"
end
end
def del_user_data_by_sql(user_id)
sql1 = "delete from memos where author_id=#{user_id}"
ActiveRecord::Base.connection.execute(sql1)
end
end