2020-03-09 00:40:16 +08:00
|
|
|
|
class ForksController < ApplicationController
|
2020-08-11 23:20:04 +08:00
|
|
|
|
before_action :require_login
|
2021-08-31 18:00:54 +08:00
|
|
|
|
before_action :require_profile_completed, only: [:create]
|
2020-08-11 23:20:04 +08:00
|
|
|
|
before_action :load_project
|
2020-03-09 00:40:16 +08:00
|
|
|
|
before_action :authenticate_project!, :authenticate_user!
|
|
|
|
|
|
|
|
|
|
|
|
def create
|
|
|
|
|
|
@new_project = Projects::ForkService.new(current_user, @project, params[:organization]).call
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
def authenticate_project!
|
2020-04-13 12:11:29 +08:00
|
|
|
|
if current_user&.id == @project.user_id
|
|
|
|
|
|
render_result(-1, "自己不能fork自己的项目")
|
|
|
|
|
|
elsif Project.exists?(user_id: current_user.id, identifier: @project.identifier)
|
2021-11-23 11:43:44 +08:00
|
|
|
|
render_result(0, "fork失败,你已拥有了这个项目")
|
2020-04-13 12:11:29 +08:00
|
|
|
|
end
|
|
|
|
|
|
# return if current_user != @project.owner
|
|
|
|
|
|
# render_result(-1, "自己不能fork自己的项目")
|
2020-03-09 00:40:16 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def authenticate_user!
|
|
|
|
|
|
return if @project.is_public
|
|
|
|
|
|
return if @project.member?(current_user) || current_user.admin?
|
|
|
|
|
|
render_forbidden('你没有权限操作')
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|