fork项目的时候一并forkmodule

This commit is contained in:
huang 2017-02-20 14:23:02 +08:00
parent 336c28ccdb
commit 8063932500
3 changed files with 53 additions and 17 deletions

View File

@ -845,7 +845,6 @@ class ProjectsController < ApplicationController
# 资源库fork弹框
def forked_pop
@task = params[:task]
respond_to do |format|
format.js
end

View File

@ -148,12 +148,12 @@ class RepositoriesController < ApplicationController
s = Trustie::Gitlab::Sync.new
s.sync_user(User.current)
ensure
logger.error "Synv user failed ==>#{User.current.id}"
logger.error "Syn user failed ==>#{User.current.id}"
end
end
gproject = g.fork(@project.gpid, User.current.gid)
if gproject
new_training_project = copy_project(@project, gproject)
new_training_project = copu_project_and_module(@project, gproject)
forked_count = @project.forked_count.to_i + 1
@project.update_attributes(:forked_count => forked_count)
# 发布实训任务,只发布实训任务的第一个
@ -163,6 +163,43 @@ class RepositoriesController < ApplicationController
end
end
def copu_project_and_module tproject, gproject
project = Project.new
project.name = tproject.name
project.is_public = tproject.is_public
project.status = tproject.status
project.description = tproject.description
project.hidden_repo = tproject.hidden_repo
project.user_id = User.current.id
project.project_type = 0
project.project_new_type = tproject.project_new_type
project.gpid = gproject.id
project.forked_from_project_id = tproject.id
project.enabled_module_names = tproject.enabled_module_names
if project.save
project.update_attribute(:training_status,1)
r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
m = Member.new(:user => User.current, :roles => [r])
if ProjectScore.where("project_id=?", project.id).first.nil?
ProjectScore.create(:project_id => project.id, :score => false)
end
project_info = ProjectInfo.new(:user_id => User.current.id, :project_id => project.id)
user_grades = UserGrade.create(:user_id => User.current.id, :project_id => project.id)
Rails.logger.debug "UserGrade created: #{user_grades.to_json}"
project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0, :project_type => @project.project_type,:grade => 0)
Rails.logger.debug "ProjectStatus created: #{project_status.to_json}"
project.members << m
project.project_infos << project_info
copy_repository(project, gproject)
return project
else
respond_to do |format|
format.html { render :action => 'forked', :layout => 'base_projects'}
format.api { render_validation_errors(@project) }
end
end
end
# REDO: 如果实训项目还没有创建任务的时候应该跳出
def publish_training_tasks original_project, new_training_project
original_task = TrainingTask.where(:project_id => original_project.id, :position => 1).first
@ -221,19 +258,19 @@ class RepositoriesController < ApplicationController
project.members << m
project.project_infos << project_info
copy_repository(project, gproject)
# respond_to do |format|
# format.html {
# flash[:notice] = l(:notice_successful_create)
# if params[:continue]
# attrs = {:parent_id => project.parent_id}.reject {|k,v| v.nil?}
# redirect_to new_project_url(attrs, :course => '0')
# else
# redirect_to project_path(project)
# end
# }
# format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => project.id) }
# format.js
# end
respond_to do |format|
format.html {
flash[:notice] = l(:notice_successful_create)
if params[:continue]
attrs = {:parent_id => project.parent_id}.reject {|k,v| v.nil?}
redirect_to new_project_url(attrs, :course => '0')
else
redirect_to project_path(project)
end
}
format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => project.id) }
format.js
end
return project
else
respond_to do |format|

View File

@ -7,7 +7,7 @@
<div class="sy_popup_con" style="width:380px;">
<ul class="sy_popup_add" >
<%# 实训项目和非实训项目,@type为true的时候为实训 %>
<% if @task %>
<% if @project.is_training_project? %>
<% if User.current.id == @project.user_id %>
<li class="center mb30" style="line-height:20px">
很抱歉,您不能在自己的实训项目中启动训练