forgeplus/app/controllers/forks_controller.rb

28 lines
941 B
Ruby
Raw Permalink 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_project!, :authenticate_user!
def create
@new_project = Projects::ForkService.new(current_user, @project, params[:organization]).call
end
private
def authenticate_project!
if current_user&.id == @project.user_id
render_result(-1, "自己不能fork自己的项目")
elsif Project.exists?(user_id: current_user.id, identifier: @project.identifier)
render_result(0, "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
end