重置回正式服fork功能
This commit is contained in:
parent
3741445d2b
commit
7eb9f0ce2e
|
@ -2,42 +2,21 @@ class ForksController < ApplicationController
|
||||||
before_action :require_login
|
before_action :require_login
|
||||||
before_action :require_profile_completed, only: [:create]
|
before_action :require_profile_completed, only: [:create]
|
||||||
before_action :load_project
|
before_action :load_project
|
||||||
before_action :authenticate_user!
|
before_action :authenticate_project!, :authenticate_user!
|
||||||
before_action :authenticate_project!, only: [:create]
|
|
||||||
|
|
||||||
def fork_list
|
|
||||||
@user = current_user
|
|
||||||
@organizations = current_user.organizations
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
def create
|
def create
|
||||||
target_owner = if params[:organization].present? && @organization
|
@new_project = Projects::ForkServiceProjects::ForkService.new(current_user, @project, params[:organization]).call
|
||||||
@organization
|
|
||||||
else
|
|
||||||
current_user
|
|
||||||
end
|
|
||||||
@new_project = Projects::ForkService.new(target_owner, @project, params[:organization], params[:new_name], params[:new_identifier]).call
|
|
||||||
if @new_project == false
|
|
||||||
render_result(-1, "已fork过一次该项目,无法再次进行fork")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def authenticate_project!
|
def authenticate_project!
|
||||||
if params[:organization].present?
|
if current_user&.id == @project.user_id
|
||||||
return render_forbidden('参数错误,当organization存在时不允许fork重命名') if params[:new_identifier].present? || params[:new_name].present?
|
render_result(-1, "自己不能fork自己的项目")
|
||||||
@organization = Organization.find_by(login:params[:organization])
|
elsif Project.exists?(user_id: current_user.id, identifier: @project.identifier)
|
||||||
return render_forbidden('组织不存在') unless @organization.present?
|
render_result(0, "fork失败,你已拥有了这个项目")
|
||||||
return render_forbidden('你没有权限操作') unless @organization.is_admin?(current_user.id)
|
|
||||||
return render_result(-1, "fork失败,组织已拥有了这个项目") if @organization && Project.exists?(user_id: [@organization.id], identifier: (params[:new_identifier] || @project.identifier))
|
|
||||||
return render_result(-1, "fork失败,请联系系统管理员") if gitea_check_exit(@organization)
|
|
||||||
else
|
|
||||||
return render_result(-1, "fork失败,您已fork过了这个项目") if Project.exists?(user_id: current_user.id, forked_from_project_id: @project.id)
|
|
||||||
return render_result(-2, "fork失败, fork本人项目需要为fork仓库重命名") if Project.exists?(user_id: current_user.id, identifier: (params[:new_identifier] || @project.identifier))
|
|
||||||
return render_result(-1, "fork失败,请联系系统管理员") if gitea_check_exit(current_user)
|
|
||||||
end
|
end
|
||||||
|
# return if current_user != @project.owner
|
||||||
|
# render_result(-1, "自己不能fork自己的项目")
|
||||||
end
|
end
|
||||||
|
|
||||||
def authenticate_user!
|
def authenticate_user!
|
||||||
|
@ -45,9 +24,4 @@ class ForksController < ApplicationController
|
||||||
return if @project.member?(current_user) || current_user.admin?
|
return if @project.member?(current_user) || current_user.admin?
|
||||||
render_forbidden('你没有权限操作')
|
render_forbidden('你没有权限操作')
|
||||||
end
|
end
|
||||||
|
end
|
||||||
def gitea_check_exit(user)
|
|
||||||
data = Gitea::Repository::GetService.new(user, params[:new_identifier]|| @project.identifier).call
|
|
||||||
data.present?
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -18,7 +18,6 @@ class Projects::ForkService < ApplicationService
|
||||||
:license_id, :ignore_id, {repository: [:identifier, :hidden]}]
|
:license_id, :ignore_id, {repository: [:identifier, :hidden]}]
|
||||||
|
|
||||||
result = Gitea::Repository::ForkService.new(@project.owner, @target_owner, @project.identifier, @organization, @new_identifier).call
|
result = Gitea::Repository::ForkService.new(@project.owner, @target_owner, @project.identifier, @organization, @new_identifier).call
|
||||||
return false if result['clone_url'].nil?
|
|
||||||
clone_project.owner = @target_owner
|
clone_project.owner = @target_owner
|
||||||
clone_project.forked_from_project_id = @project.id
|
clone_project.forked_from_project_id = @project.id
|
||||||
clone_project.gpid = result['id']
|
clone_project.gpid = result['id']
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
json.user do
|
|
||||||
json.id @user.id
|
|
||||||
json.type @user.type
|
|
||||||
json.name @user.real_name
|
|
||||||
json.login @user.login
|
|
||||||
json.mail @user.mail
|
|
||||||
json.image_url url_to_avatar(@user)
|
|
||||||
json.forked Project.exists?(user_id: @user.id, forked_from_project_id: @project.id)
|
|
||||||
end
|
|
||||||
json.organizations @organizations do |organization|
|
|
||||||
json.forked Project.exists?(user_id: organization.id, forked_from_project_id: @project.id)
|
|
||||||
json.id organization.id
|
|
||||||
json.name organization.login
|
|
||||||
json.nickname organization.nickname.blank? ? organization.name : organization.nickname
|
|
||||||
json.avatar_url url_to_avatar(organization)
|
|
||||||
json.created_at organization.created_on.strftime("%Y-%m-%d")
|
|
||||||
end
|
|
|
@ -625,11 +625,7 @@ Rails.application.routes.draw do
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :hooks
|
resources :hooks
|
||||||
resources :forks, only: [:create] do
|
resources :forks, only: [:create]
|
||||||
collection do
|
|
||||||
get :fork_list
|
|
||||||
end
|
|
||||||
end
|
|
||||||
resources :project_trends, :path => :activity, only: [:index, :create]
|
resources :project_trends, :path => :activity, only: [:index, :create]
|
||||||
resources :issue_tags, :path => :labels, only: [:create, :edit, :update, :destroy, :index]
|
resources :issue_tags, :path => :labels, only: [:create, :edit, :update, :destroy, :index]
|
||||||
resources :version_releases, :path => :releases, only: [:index,:new, :show, :create, :edit, :update, :destroy]
|
resources :version_releases, :path => :releases, only: [:index,:new, :show, :create, :edit, :update, :destroy]
|
||||||
|
|
Loading…
Reference in New Issue