mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-22 12:45:46 +08:00
新增:组织数据修复任务
This commit is contained in:
@@ -4,6 +4,35 @@ desc "初始化数据同步到gitea平台"
|
||||
# 再同步项目及项目成员
|
||||
|
||||
namespace :sync_data_to_gitea do
|
||||
desc "同步组织数据"
|
||||
# 同步组织成员,并仅保留最高权限
|
||||
task organizations: :environment do
|
||||
Organization.includes(:organization_users, teams: [:team_users, :team_projects]).find_each do |org|
|
||||
ActiveRecord::Base.transaction do
|
||||
org.teams.each do |team|
|
||||
if team.gtid.blank?
|
||||
gteam = $gitea_client.post_orgs_teams_by_org(org.login, {body: team.to_gitea_hash.to_json}) rescue nil
|
||||
team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil?
|
||||
end
|
||||
team.team_users.each do |teamuser|
|
||||
userlogin = teamuser&.user&.login
|
||||
next if ($gitea_client.get_teams_members_by_id_username(team.gtid, userlogin) rescue nil)
|
||||
tu_result = $gitea_client.put_teams_members_by_id_username(team.gtid, userlogin) rescue nil
|
||||
raise ActiveRecord::Rollback if tu_result.nil?
|
||||
end
|
||||
team.team_projects.each do |teamp|
|
||||
tp_result = $gitea_client.put_teams_repos_by_id_org_repo(team.gtid, org.login, teamp&.project.identifier) rescue nil
|
||||
raise ActiveRecord::Rollback if tp_result.nil?
|
||||
end
|
||||
end
|
||||
org.organization_users.each do |user|
|
||||
next if ($gitea_client.get_orgs_members_by_org_username(org.login, user.login) rescue nil)
|
||||
user.destroy!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
desc "同步用户"
|
||||
task users: :environment do
|
||||
users = User.where.not(mail: [nil, ""], type: 'Anonymous').or(User.where.not(login: [nil, ""])).distinct
|
||||
|
||||
Reference in New Issue
Block a user