2017-04-07 10:16:13 +08:00
|
|
|
|
# encoding: utf-8
|
|
|
|
|
|
# REDO: 创建版本库权限控制
|
|
|
|
|
|
class ShixunsController < ApplicationController
|
|
|
|
|
|
layout 'base_shixun'
|
|
|
|
|
|
before_filter :require_login
|
2017-05-18 11:30:29 +08:00
|
|
|
|
before_filter :find_shixun, :except => [ :index, :new, :create, :index, :search ]
|
2017-04-07 10:16:13 +08:00
|
|
|
|
before_filter :shixun_view_allow, :only => [:show]
|
2017-05-19 17:30:30 +08:00
|
|
|
|
before_filter :require_manager, :only => [ :settings, :add_script, :publish, :collaborators_delete, :shixun_members_added, :add_collaborators]
|
2017-04-07 10:16:13 +08:00
|
|
|
|
|
|
|
|
|
|
include ApplicationHelper
|
|
|
|
|
|
|
|
|
|
|
|
def shixun_monitor
|
2017-04-12 16:06:03 +08:00
|
|
|
|
# monitor_filter
|
|
|
|
|
|
# if @had_exec
|
|
|
|
|
|
# @tpm = Myshixun.where(:user_id => User.current, :shixun_id => @shixun).first
|
|
|
|
|
|
# end
|
|
|
|
|
|
#
|
|
|
|
|
|
# respond_to do |format|
|
|
|
|
|
|
# format.js
|
|
|
|
|
|
# end
|
|
|
|
|
|
end
|
2017-04-07 10:16:13 +08:00
|
|
|
|
|
2017-05-02 17:18:34 +08:00
|
|
|
|
def statistics
|
|
|
|
|
|
@challenges = @shixun.challenges
|
2017-05-23 19:23:15 +08:00
|
|
|
|
@top_students = @shixun.myshixuns.where(:status => 1)
|
2017-05-02 17:18:34 +08:00
|
|
|
|
myshixuns = @shixun.myshixuns.includes(:games)
|
|
|
|
|
|
@latest_myshixuns = myshixuns.order("created_at desc").limit(4)
|
|
|
|
|
|
end
|
|
|
|
|
|
|
2017-04-24 14:42:54 +08:00
|
|
|
|
def index
|
2017-04-26 11:10:01 +08:00
|
|
|
|
@shixuns = Shixun.where(:authentication => 1).order('updated_at desc')
|
2017-04-28 15:11:11 +08:00
|
|
|
|
@shixun_my_score = Game.where(:user_id => User.current).sum(:final_score)
|
2017-04-25 14:18:52 +08:00
|
|
|
|
@current_user_had_passed = Myshixun.where(:status => 1).count
|
2017-04-24 17:29:38 +08:00
|
|
|
|
@shixuns_count = @shixuns.count
|
2017-04-24 14:42:54 +08:00
|
|
|
|
render :layout => "base_edu"
|
|
|
|
|
|
end
|
|
|
|
|
|
|
2017-05-18 11:30:29 +08:00
|
|
|
|
def propaedeutics
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
|
format.html
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
2017-05-19 16:56:09 +08:00
|
|
|
|
def collaborators
|
|
|
|
|
|
@collaborators = @shixun.collaborators
|
|
|
|
|
|
end
|
|
|
|
|
|
|
2017-05-19 17:14:15 +08:00
|
|
|
|
def collaborators_delete
|
|
|
|
|
|
user_id = params[:c_id]
|
|
|
|
|
|
shixun_member = ShixunMember.where(:user_id => user_id, :shixun_id => @shixun.id, :role => 2).first
|
|
|
|
|
|
shixun_member.delete
|
|
|
|
|
|
@collaborators = @shixun.collaborators
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
|
format.js
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
2017-05-19 16:56:09 +08:00
|
|
|
|
# 已存在的成员不添加
|
|
|
|
|
|
def add_collaborators
|
|
|
|
|
|
if !params[:search].nil?
|
|
|
|
|
|
# members = searchTeacherAndAssistant @course
|
|
|
|
|
|
member_ids = "(" + @shixun.shixun_members.map(&:user_id).join(',') + ")"
|
|
|
|
|
|
condition = "%#{params[:search].strip}%".gsub(" ","")
|
|
|
|
|
|
@users = User.where("id not in #{member_ids} and status = 1 and LOWER(concat(lastname, firstname)) LIKE '#{condition}'").includes(:user_extensions)
|
|
|
|
|
|
end
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
|
format.js
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def shixun_members_added
|
|
|
|
|
|
unless params[:membership][:user_ids].blank?
|
|
|
|
|
|
memberships = params[:membership][:user_ids]
|
|
|
|
|
|
memberships.each do |member|
|
|
|
|
|
|
ShixunMember.create(:user_id => member, :shixun_id => @shixun.id, :role => 2)
|
|
|
|
|
|
end
|
|
|
|
|
|
@collaborators = @shixun.collaborators
|
|
|
|
|
|
end
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
|
format.js
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
2017-04-27 10:18:15 +08:00
|
|
|
|
def search
|
2017-04-25 14:18:52 +08:00
|
|
|
|
# 确定 sort 1升序 2 降序
|
2017-04-26 11:10:01 +08:00
|
|
|
|
if params[:time_reorder]
|
2017-04-26 18:03:48 +08:00
|
|
|
|
order = "#{Shixun.table_name}.created_at #{params[:time_reorder]}"
|
2017-04-26 11:10:01 +08:00
|
|
|
|
elsif params[:hot_reorder]
|
2017-04-27 10:18:15 +08:00
|
|
|
|
order = "myshixun_count #{params[:hot_reorder]}, #{Shixun.table_name}.updated_at #{params[:hot_reorder]}"
|
2017-04-26 11:10:01 +08:00
|
|
|
|
else
|
2017-04-26 18:03:48 +08:00
|
|
|
|
order = "#{Shixun.table_name}.created_at desc"
|
2017-04-26 11:10:01 +08:00
|
|
|
|
end
|
|
|
|
|
|
@shixuns = Shixun.where(:authentication => 1).reorder(order)
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
|
format.js
|
|
|
|
|
|
end
|
2017-04-25 14:18:52 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
2017-04-12 16:06:03 +08:00
|
|
|
|
# jenkins回调脚本
|
2017-04-16 17:20:47 +08:00
|
|
|
|
# gameID 及实训ID
|
2017-04-12 16:06:03 +08:00
|
|
|
|
def publish
|
|
|
|
|
|
jenkins_shixuns = Redmine::Configuration['jenkins_shixuns']
|
2017-04-16 17:20:47 +08:00
|
|
|
|
fragments = []
|
|
|
|
|
|
testSet = []
|
2017-04-12 16:06:03 +08:00
|
|
|
|
testCases = []
|
|
|
|
|
|
begin
|
|
|
|
|
|
challenges = @shixun.challenges.includes(:test_sets)
|
|
|
|
|
|
challenges.each do |challenge|
|
2017-04-17 15:30:31 +08:00
|
|
|
|
pipeline_script = challenge.try(:pipeline_script)
|
2017-04-17 10:11:17 +08:00
|
|
|
|
challenge_script = {:challengeStage => "#{challenge.position}", :challengePipeline => "#{pipeline_script}"}
|
2017-04-16 17:20:47 +08:00
|
|
|
|
fragments << challenge_script
|
2017-04-19 14:18:36 +08:00
|
|
|
|
# 每一关所有的测试集
|
2017-04-12 16:06:03 +08:00
|
|
|
|
challenge.test_sets.each do |test_set|
|
2017-04-28 10:24:40 +08:00
|
|
|
|
test_cases = {:caseId => test_set.id.to_s, :input => test_set.input, :output => test_set.output, :isPublic => (test_set.is_public ? "1" : "0")}
|
2017-04-16 17:20:47 +08:00
|
|
|
|
testSet << test_cases
|
2017-04-12 16:06:03 +08:00
|
|
|
|
end
|
2017-04-17 10:11:17 +08:00
|
|
|
|
test_sets_list = {:challengeStage => challenge.position.to_s, :challengeTestCases => testSet}
|
2017-04-16 17:20:47 +08:00
|
|
|
|
testCases << test_sets_list
|
2017-04-19 14:18:36 +08:00
|
|
|
|
testSet = []
|
2017-04-12 16:06:03 +08:00
|
|
|
|
end
|
2017-04-17 10:11:17 +08:00
|
|
|
|
gameInfo = {:trainingID => @shixun.id.to_s, :operationEnvironment => @shixun.language, :challengePipelines => fragments, :testCases => testCases}
|
2017-04-12 16:06:03 +08:00
|
|
|
|
fragments = fragments.to_json
|
2017-04-16 17:20:47 +08:00
|
|
|
|
uri = URI("#{jenkins_shixuns}/jenkins-exec/game/publishGame")
|
2017-04-17 10:11:17 +08:00
|
|
|
|
params = {gameInfo:gameInfo.to_json}
|
|
|
|
|
|
res = uri_exec uri, params
|
2017-04-12 16:06:03 +08:00
|
|
|
|
if res['code'] == 0
|
|
|
|
|
|
@shixun.update_attribute(:status, 1)
|
2017-04-17 10:11:17 +08:00
|
|
|
|
@shixun.update_attribute(:script, res["msg"])
|
2017-04-17 15:30:31 +08:00
|
|
|
|
else
|
|
|
|
|
|
logger.error("res['code'] is #{res['code']}, res['msg'] is #{res['code']}")
|
|
|
|
|
|
@jenkin_error = true
|
2017-04-12 16:06:03 +08:00
|
|
|
|
end
|
2017-05-23 20:44:57 +08:00
|
|
|
|
rescue Exception => e
|
|
|
|
|
|
logger.error("pushlish game #{e}")
|
2017-04-12 16:06:03 +08:00
|
|
|
|
respond_to do |format|
|
|
|
|
|
|
format.js
|
|
|
|
|
|
end
|
2017-04-07 10:16:13 +08:00
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# copy_shixun:复制一个新的实训模块包括版本库
|
|
|
|
|
|
# copy_myshixun自动创建系列game,game中只包含状态等信息,公共信息从Challeges中读取
|
2017-04-11 11:09:06 +08:00
|
|
|
|
# 开启过实训的则直接跳入my实训页面
|
2017-04-07 10:16:13 +08:00
|
|
|
|
def shixun_exec
|
2017-04-11 11:09:06 +08:00
|
|
|
|
unless allow_shixun_exec(@shixun)
|
2017-04-07 10:16:13 +08:00
|
|
|
|
render_403
|
|
|
|
|
|
end
|
2017-04-11 11:09:06 +08:00
|
|
|
|
myshixun = Myshixun.where(:user_id => User.current.id, :shixun_id => @shixun.id).first
|
|
|
|
|
|
unless myshixun.blank?
|
2017-04-17 16:30:37 +08:00
|
|
|
|
logger.info("current task id is #{myshixun.current_task}")
|
|
|
|
|
|
redirect_to myshixun_game_path(myshixun.current_task, :myshixun_id => myshixun)
|
2017-04-11 11:09:06 +08:00
|
|
|
|
return
|
|
|
|
|
|
end
|
2017-04-07 10:16:13 +08:00
|
|
|
|
repository = @shixun.repository
|
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
|
begin
|
|
|
|
|
|
@g = Gitlab.client
|
|
|
|
|
|
if User.current.gid.nil?
|
|
|
|
|
|
s = Trustie::Gitlab::Sync.new
|
|
|
|
|
|
s.sync_user(User.current)
|
|
|
|
|
|
end
|
|
|
|
|
|
gshixun = @g.fork(@shixun.gpid, User.current.gid)
|
2017-05-11 16:52:00 +08:00
|
|
|
|
logger.info("#############gshixun is #{gshixun}")
|
2017-04-07 10:16:13 +08:00
|
|
|
|
if !gshixun.id.nil?
|
|
|
|
|
|
myshixun = copy_myshixun(@shixun, gshixun)
|
2017-04-27 10:18:15 +08:00
|
|
|
|
@shixun.update_attribute(:myshixun_count, (@shixun.myshixun_count + 1))
|
2017-04-07 10:16:13 +08:00
|
|
|
|
challenges = @shixun.challenges
|
|
|
|
|
|
# 之所以增加user_id是为了方便统计查询性能
|
|
|
|
|
|
challenges.each_with_index do |challenge, index|
|
|
|
|
|
|
status = (index == 0 ? 0 : 3)
|
2017-04-26 16:03:05 +08:00
|
|
|
|
code = CODES.sample(12).join
|
|
|
|
|
|
code = CODES.sample(12).join if Game.where(identifier: code).present?
|
|
|
|
|
|
Game.create!(:challenge_id => challenge.id, :myshixun_id => myshixun.id, :status => status, :user_id => myshixun.user_id, :open_time => Time.now, :identifier => code)
|
2017-04-07 10:16:13 +08:00
|
|
|
|
end
|
|
|
|
|
|
else
|
2017-05-23 20:53:27 +08:00
|
|
|
|
raise("实训云平台繁忙(繁忙等级:81)")
|
2017-04-07 10:16:13 +08:00
|
|
|
|
end
|
2017-04-19 15:08:04 +08:00
|
|
|
|
logger.info("myshixun id si #{myshixun.id} and current_task id is#{myshixun.current_task.id}")
|
2017-04-17 16:30:37 +08:00
|
|
|
|
redirect_to myshixun_game_path(myshixun.current_task, :myshixun_id => myshixun)
|
2017-04-07 10:16:13 +08:00
|
|
|
|
rescue Exception => e
|
2017-04-17 16:30:37 +08:00
|
|
|
|
flash[:error] = e.message
|
|
|
|
|
|
logger.info("failed to exec shixun: current task id is #{e}")
|
2017-04-07 10:16:13 +08:00
|
|
|
|
@g.delete_project(gshixun.id) if !gshixun.id.nil?
|
2017-04-17 16:30:37 +08:00
|
|
|
|
redirect_to shixun_challenges_path(@shixun)
|
2017-04-07 10:16:13 +08:00
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def new
|
|
|
|
|
|
@shixun = Shixun.new
|
|
|
|
|
|
|
|
|
|
|
|
respond_to do |format|
|
2017-05-17 17:19:16 +08:00
|
|
|
|
format.html{render :layout => 'base_edu'}
|
2017-04-07 10:16:13 +08:00
|
|
|
|
format.json
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
2017-04-25 17:15:37 +08:00
|
|
|
|
CODES = %W(2 3 4 5 6 7 8 9 A B C D E F G H J K L N M O P Q R S T U V W X Y Z)
|
2017-04-07 10:16:13 +08:00
|
|
|
|
def create
|
2017-04-25 17:15:37 +08:00
|
|
|
|
identifier = generate_identifier
|
2017-04-07 10:16:13 +08:00
|
|
|
|
@shixun = Shixun.new(params[:shixun])
|
|
|
|
|
|
@shixun.user_id = User.current.id
|
|
|
|
|
|
@shixun.language = params[:language]
|
2017-04-25 17:15:37 +08:00
|
|
|
|
@shixun.identifier = identifier
|
2017-04-07 10:16:13 +08:00
|
|
|
|
(params[:shixun][:is_public] == "1" ? @shixun.is_public = true : @shixun.is_public = false)
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
|
if @shixun.save
|
|
|
|
|
|
m = ShixunMember.new(:user_id => User.current.id, :role => 1)
|
|
|
|
|
|
@shixun.shixun_members << m
|
2017-05-08 15:28:35 +08:00
|
|
|
|
# 自动构建版本库
|
2017-05-08 16:35:29 +08:00
|
|
|
|
repository = Repository.new
|
|
|
|
|
|
repository.shixun = @shixun
|
|
|
|
|
|
repository.type = 'Repository::Gitlab'
|
|
|
|
|
|
repository.identifier = @shixun.identifier.downcase
|
|
|
|
|
|
repository.project_id = -1
|
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
|
if repository.save
|
|
|
|
|
|
begin
|
|
|
|
|
|
s = Trustie::Gitlab::Sync.new
|
|
|
|
|
|
gproject = s.create_shixun(@shixun, repository)
|
|
|
|
|
|
raise "sync failed" if @shixun.gpid.blank?
|
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
|
@shixun.update_attribute(:gpid, nil)
|
|
|
|
|
|
if @repository.id
|
|
|
|
|
|
@repository.destroy
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
2017-04-25 17:15:37 +08:00
|
|
|
|
format.html { redirect_to shixun_path @shixun, notice: l(:notice_successful_create) }
|
2017-04-07 10:16:13 +08:00
|
|
|
|
format.js
|
|
|
|
|
|
else
|
|
|
|
|
|
format.html { render action: "new" }
|
|
|
|
|
|
format.js
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def show
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
|
format.html{redirect_to shixun_challenges_path(@shixun)}
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
2017-04-25 17:15:37 +08:00
|
|
|
|
CODES = %W(2 3 4 5 6 7 8 9 A B C D E F G H J K L N M O P Q R S T U V W X Y Z)
|
|
|
|
|
|
def generate_identifier
|
|
|
|
|
|
code = CODES.sample(8).join
|
|
|
|
|
|
return generate_identifier if Shixun.where(identifier: code).present?
|
|
|
|
|
|
code
|
|
|
|
|
|
end
|
|
|
|
|
|
|
2017-04-07 10:16:13 +08:00
|
|
|
|
def edit
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def update
|
|
|
|
|
|
@shixun.attributes = params[:shixun]
|
|
|
|
|
|
@shixun.language = params[:language]
|
|
|
|
|
|
params[:shixun][:is_public] == "on" ? @shixun.is_public = 1 : @shixun.is_public = 0
|
|
|
|
|
|
@shixun.save
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
|
format.html{redirect_to settings_shixun_url(@shixun)}
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def settings
|
|
|
|
|
|
@repository = Repository.where(:shixun_id => @shixun, :type => "Repository::Gitlab").first
|
|
|
|
|
|
unless @repository.nil?
|
|
|
|
|
|
gitlab_address = Redmine::Configuration['gitlab_address']
|
2017-05-08 16:35:29 +08:00
|
|
|
|
login = User.find_by_mail("educoder@163.com").try(:login)
|
|
|
|
|
|
@repos_url = git_shixun_url(@shixun, login)
|
2017-04-07 10:16:13 +08:00
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# 添加实训脚本
|
|
|
|
|
|
def add_script
|
|
|
|
|
|
if @shixun.update_attribute(:script, params[:shixun_script])
|
|
|
|
|
|
@notice = "脚本添加成功"
|
|
|
|
|
|
else
|
|
|
|
|
|
@notice = "脚本添加失败"
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# 创建实训job
|
|
|
|
|
|
def shixun_job_create
|
|
|
|
|
|
if @shixun.challenges.count == 0
|
|
|
|
|
|
@notice = "实训开启失败:请先发布实训任务"
|
|
|
|
|
|
return
|
|
|
|
|
|
elsif Repository.where(:shixun_id => @shixun.id, :type => "Repository::Gitlab").count == 0
|
|
|
|
|
|
@notice = "实训开启失败:请先创建版本库"
|
|
|
|
|
|
return
|
|
|
|
|
|
end
|
|
|
|
|
|
@shixun.update_attribute(:status, 1)
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# 更新实训job
|
|
|
|
|
|
def shixun_job_update
|
|
|
|
|
|
# jobName = "#{@shixun.id}"
|
|
|
|
|
|
# pipeLine = "#{Base64.encode64(@shixun.script)}"
|
|
|
|
|
|
# uri = URI("http://123.59.135.74:9999/jenkins-exec/api/updateJob")
|
|
|
|
|
|
# params = {jobName: jobName, pipeLine: pipeLine}
|
|
|
|
|
|
# res = uri_exec uri, params
|
|
|
|
|
|
training_shixun_notice res
|
|
|
|
|
|
if res['code'] == 0
|
|
|
|
|
|
@shixun.update_attribute(:status, 1)
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Find shixun of id params[:id]
|
|
|
|
|
|
def find_shixun
|
2017-04-25 17:15:37 +08:00
|
|
|
|
@shixun = Shixun.find_by_identifier(params[:id])
|
|
|
|
|
|
render_404 if @shixun.nil?
|
2017-04-07 10:16:13 +08:00
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
|
|
render_404
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def monitor_filter
|
|
|
|
|
|
if User.current.id == @shixun.user_id
|
|
|
|
|
|
@notice = l(:label_shixun_mine)
|
|
|
|
|
|
else
|
|
|
|
|
|
if has_exec_cur_shixun(@shixun)
|
|
|
|
|
|
@notice = l(:label_shixun_had_forked)
|
|
|
|
|
|
@had_exec = true
|
|
|
|
|
|
else
|
|
|
|
|
|
@notice = l(:label_shixun_exec)
|
|
|
|
|
|
@had_exec = false
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
# REDO: 新增类型copy的时候
|
|
|
|
|
|
# 复制项目
|
|
|
|
|
|
# gshixun --> gitlab project
|
2017-04-26 16:03:05 +08:00
|
|
|
|
CODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z)
|
2017-04-07 10:16:13 +08:00
|
|
|
|
def copy_myshixun shixun, gshixun
|
|
|
|
|
|
myshixun = Myshixun.new
|
2017-05-18 14:50:39 +08:00
|
|
|
|
myshixun.attributes = shixun.attributes.dup.except("id","user_id","visits","gpid","status", "identifier","propaedeutics")
|
2017-04-07 10:16:13 +08:00
|
|
|
|
myshixun.shixun_id = shixun.id
|
|
|
|
|
|
myshixun.user_id = User.current.id
|
|
|
|
|
|
myshixun.gpid = gshixun.id
|
|
|
|
|
|
jenkins_shixuns = Redmine::Configuration['jenkins_shixuns']
|
|
|
|
|
|
if myshixun.save!
|
2017-04-26 16:03:05 +08:00
|
|
|
|
code = CODES.sample(10).join
|
|
|
|
|
|
code = CODES.sample(10).join if Myshixun.where(identifier: code).present?
|
|
|
|
|
|
myshixun.update_attribute(:identifier, code)
|
2017-04-07 10:16:13 +08:00
|
|
|
|
MyshixunMember.create!(:myshixun_id => myshixun.id, :user_id => User.current.id, :role => 1)
|
|
|
|
|
|
rep = Repository.new(:myshixun_id => myshixun.id, :identifier => gshixun.name,:project_id => -1, :shixun_id => -2)
|
|
|
|
|
|
rep.type = "Repository::Gitlab"
|
|
|
|
|
|
rep.save!
|
2017-05-11 16:24:49 +08:00
|
|
|
|
login = User.find_by_mail("educoder@163.com").try(:login)
|
|
|
|
|
|
rep_url = Base64.encode64(git_shixun_url shixun, login)
|
2017-04-17 10:11:17 +08:00
|
|
|
|
uri = URI("#{jenkins_shixuns}/jenkins-exec/game/openGameInstance")
|
2017-04-17 16:30:37 +08:00
|
|
|
|
pipeLine = "#{shixun.script}"
|
2017-04-17 10:11:17 +08:00
|
|
|
|
params = {jobNameForInstance: "myshixun_#{myshixun.id}", gamePipelineScript: pipeLine, instanceGitURL:rep_url}
|
|
|
|
|
|
res = uri_exec uri, params
|
2017-04-07 10:16:13 +08:00
|
|
|
|
if (res && res['code'] != 0)
|
2017-05-23 20:53:27 +08:00
|
|
|
|
raise("实训云平台繁忙(繁忙等级:83)")
|
2017-04-07 10:16:13 +08:00
|
|
|
|
end
|
|
|
|
|
|
return myshixun
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def training_shixun_notice res
|
|
|
|
|
|
if res['code'] == 0
|
|
|
|
|
|
@notice = "实训开启成功"
|
|
|
|
|
|
else
|
|
|
|
|
|
@notice = res['msg'].nil? ? "实训开启失败" : res['msg']
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# 权限控制
|
|
|
|
|
|
def shixun_view_allow
|
|
|
|
|
|
if @shixun.is_public?
|
|
|
|
|
|
true
|
|
|
|
|
|
else
|
|
|
|
|
|
User.current.member_of?(@shixun) ? true : false
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# 实训管理员或者超级管理员
|
|
|
|
|
|
def require_manager
|
2017-04-17 15:39:01 +08:00
|
|
|
|
render_403 unless (User.current.manager_of_shixun?(@shixun) || User.current.admin?)
|
2017-04-07 10:16:13 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|