新增:添加全部或者移除全部团队项目
This commit is contained in:
parent
d04ed7e008
commit
0f41cabe71
|
@ -21,6 +21,17 @@ class Organizations::TeamProjectsController < Organizations::BaseController
|
||||||
tip_exception(e.message)
|
tip_exception(e.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create_all
|
||||||
|
tip_exception("该组织团队项目包括组织所有项目,不允许更改") if @team.includes_all_project
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
@organization.projects.each do |project|
|
||||||
|
TeamProject.build(@organization.id, @team.id, project.id)
|
||||||
|
end
|
||||||
|
Gitea::Organization::TeamProject::CreateAllService.call(@organization.gitea_token, @team.gtid, @organization.login)
|
||||||
|
render_ok
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
tip_exception("该组织团队项目包括组织所有项目,不允许更改") if @team.includes_all_project
|
tip_exception("该组织团队项目包括组织所有项目,不允许更改") if @team.includes_all_project
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
|
@ -33,6 +44,17 @@ class Organizations::TeamProjectsController < Organizations::BaseController
|
||||||
tip_exception(e.message)
|
tip_exception(e.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def destroy_all
|
||||||
|
tip_exception("该组织团队项目包括组织所有项目,不允许更改") if @team.includes_all_project
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
@team.team_projects.each do |project|
|
||||||
|
project.destroy!
|
||||||
|
end
|
||||||
|
Gitea::Organization::TeamProject::DeleteAllService.call(@organization.gitea_token, @team.gtid, @organization.login)
|
||||||
|
render_ok
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def load_organization
|
def load_organization
|
||||||
@organization = Organization.find_by(login: params[:organization_id]) || Organization.find_by(id: params[:organization_id])
|
@organization = Organization.find_by(login: params[:organization_id]) || Organization.find_by(id: params[:organization_id])
|
||||||
|
@ -47,7 +69,7 @@ class Organizations::TeamProjectsController < Organizations::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_operate_project
|
def load_operate_project
|
||||||
@operate_project = Project.find_by(id: project_mark) || Project.find_by(identifier: project_mark)
|
@operate_project = @organization.projects.find_by(id: project_mark) || @organization.find_by(identifier: project_mark)
|
||||||
tip_exception("项目不存在") if @operate_project.nil?
|
tip_exception("项目不存在") if @operate_project.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
class Gitea::Organization::TeamProject::CreateAllService < Gitea::ClientService
|
||||||
|
attr_reader :token, :gtid, :org_name
|
||||||
|
|
||||||
|
def initialize(token, gtid, org_name)
|
||||||
|
@token = token
|
||||||
|
@gtid = gtid
|
||||||
|
@org_name = org_name
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
response = put(url, request_params)
|
||||||
|
render_status(response)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def request_params
|
||||||
|
Hash.new.merge(token: token)
|
||||||
|
end
|
||||||
|
|
||||||
|
def url
|
||||||
|
"/teams/#{gtid}/repos/#{org_name}".freeze
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,23 @@
|
||||||
|
class Gitea::Organization::TeamProject::DeleteAllService < Gitea::ClientService
|
||||||
|
attr_reader :token, :gtid, :org_name
|
||||||
|
|
||||||
|
def initialize(token, gtid, org_name)
|
||||||
|
@token = token
|
||||||
|
@gtid = gtid
|
||||||
|
@org_name = org_name
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
response = delete(url, params)
|
||||||
|
render_status(response)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def params
|
||||||
|
Hash.new.merge(token: token)
|
||||||
|
end
|
||||||
|
|
||||||
|
def url
|
||||||
|
"/teams/#{gtid}/repos/#{org_name}".freeze
|
||||||
|
end
|
||||||
|
end
|
|
@ -135,7 +135,12 @@ Rails.application.routes.draw do
|
||||||
delete :quit
|
delete :quit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
resources :team_projects, only: [:index, :create, :destroy] do ;end
|
resources :team_projects, only: [:index, :create, :destroy] do
|
||||||
|
collection do
|
||||||
|
post :create_all
|
||||||
|
delete :destroy_all
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
resources :projects, only: [:index] do
|
resources :projects, only: [:index] do
|
||||||
collection do
|
collection do
|
||||||
|
|
Loading…
Reference in New Issue