gitlink-forgeplus/app/controllers/forks_controller.rb

59 lines
2.4 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class ForksController < ApplicationController
before_action :require_login
before_action :require_profile_completed, only: [:create]
before_action :load_project
before_action :authenticate_user!
before_action :authenticate_project!, only: [:create]
def fork_list
@user = current_user
@organizations = current_user.organizations
end
def create
target_owner = if params[:organization].present? && @organization
@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
private
def authenticate_project!
if params[:organization].present?
return render_forbidden('参数错误当organization存在时不允许fork重命名') if params[:new_identifier].present? || params[:new_name].present?
@organization = Organization.find_by(login:params[:organization])
return render_forbidden('仓库不存在') unless @organization.present?
return render_forbidden('你没有权限操作') unless @organization.is_admin?(current_user.id)
end
if params[:organization].blank? && Project.exists?(user_id: current_user.id, identifier: (params[:new_identifier] || @project.identifier))
render_result(-1, "fork失败您已拥有了这个项目")
elsif @organization && Project.exists?(user_id: [@organization.id], identifier: (params[:new_identifier] || @project.identifier))
render_result(-1, "fork失败组织已拥有了这个项目")
elsif gitea_check_exit(current_user)
render_result(-1, "fork失败仓库底层数据出现了问题")
elsif @organization && gitea_check_exit(@organization)
render_result(-1, "fork失败fork失败仓库底层数据出现了问题")
end
# return if current_user != @project.owner
# render_result(-1, "自己不能fork自己的项目")
end
def authenticate_user!
return if @project.is_public
return if @project.member?(current_user) || current_user.admin?
render_forbidden('你没有权限操作')
end
def gitea_check_exit(user)
data = Gitea::Repository::GetService.new(user, params[:new_identifier] || @project.identifier)).call
data.present?
end
end