mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-24 05:35:46 +08:00
[ADD]组织、组织团队
This commit is contained in:
74
app/services/organizations/teams/create_service.rb
Normal file
74
app/services/organizations/teams/create_service.rb
Normal file
@@ -0,0 +1,74 @@
|
||||
class Organizations::Teams::CreateService < ApplicationService
|
||||
attr_reader :user, :org, :params
|
||||
attr_accessor :team, :gitea_team
|
||||
|
||||
def initialize(user, org, params)
|
||||
@user = user
|
||||
@org = org
|
||||
@params = params
|
||||
end
|
||||
|
||||
def call
|
||||
Rails.logger.info("######Team create_service begin######")
|
||||
Rails.logger.info("######params #{params}######")
|
||||
ActiveRecord::Base.transaction do
|
||||
create_team
|
||||
create_units
|
||||
create_gitea_team
|
||||
sync_team_gtid
|
||||
end
|
||||
Rails.logger.info("######Team create_service end######")
|
||||
|
||||
team
|
||||
end
|
||||
|
||||
private
|
||||
def name
|
||||
params[:name]
|
||||
end
|
||||
|
||||
def description
|
||||
params[:description]
|
||||
end
|
||||
|
||||
def authorize
|
||||
params[:authorize].present? ? params[:authorize] : "common"
|
||||
end
|
||||
|
||||
def includes_all_project
|
||||
params[:includes_all_project].present? ? params[:includes_all_project] : false
|
||||
end
|
||||
|
||||
def can_create_org_project
|
||||
params[:can_create_org_project].present? ? params[:can_create_org_project] : false
|
||||
end
|
||||
|
||||
def create_team
|
||||
@team = Team.build(org.id, name, description, authorize,
|
||||
includes_all_project, can_create_org_project)
|
||||
end
|
||||
|
||||
def units_params
|
||||
%w(admin owner).include?(authorize) ? %w(code issues pulls releases) : params[:unit_types]
|
||||
end
|
||||
|
||||
def create_units
|
||||
return if units_params.blank?
|
||||
begin
|
||||
units_params.each do |unit|
|
||||
TeamUnit.build(org.id, team.id, unit)
|
||||
end
|
||||
rescue
|
||||
raise ActiveRecord::Rollback, "TeamUnit create error"
|
||||
end
|
||||
end
|
||||
|
||||
def create_gitea_team
|
||||
@gitea_team = Gitea::Organization::Team::CreateService.call(user.gitea_token, org, team)
|
||||
end
|
||||
|
||||
def sync_team_gtid
|
||||
team.update!(gtid: gitea_team["id"])
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user