2017-04-07 10:16:13 +08:00
|
|
|
|
# encoding: utf-8
|
|
|
|
|
|
class ChallengesController < ApplicationController
|
|
|
|
|
|
layout "base_shixun"
|
2017-06-23 10:38:40 +08:00
|
|
|
|
before_filter :check_authentication
|
2017-09-12 16:22:52 +08:00
|
|
|
|
before_filter :find_shixun, :only => [:index, :new, :create, :destroy, :challenge_build, :update_evaluation, :add_choose_question, :new_choose_question, :choose_type_show, :edit_choose_question, :update_choose_question, :destroy_challenge_choose]
|
|
|
|
|
|
before_filter :find_challenge, :only => [:show, :edit, :update, :challenge_build, :index_up, :index_down, :destroy, :update_evaluation, :add_choose_question, :new_choose_question, :choose_type_show, :edit_choose_question, :update_choose_question, :destroy_challenge_choose]
|
2017-04-07 10:16:13 +08:00
|
|
|
|
before_filter :build_challege_from_params, :only => [:new, :create]
|
2017-04-28 10:21:02 +08:00
|
|
|
|
before_filter :tpi_manager_allowed, :only => [:challenge_build, :destroy, :edit, :new, :create]
|
|
|
|
|
|
before_filter :allowed_view, :only => [:show]
|
2017-07-20 16:25:44 +08:00
|
|
|
|
before_filter :query_challeges, :only => [:show, :edit, :update, :update_evaluation]
|
2017-04-07 10:16:13 +08:00
|
|
|
|
before_filter :find_shixun_language, :only => [:show, :new, :edit]
|
2017-09-07 19:16:55 +08:00
|
|
|
|
#before_filter :default_format_js, only: :new_or_edit_choose_question
|
2017-09-07 10:26:54 +08:00
|
|
|
|
|
2017-09-07 09:42:12 +08:00
|
|
|
|
#skip_before_filter :verify_authenticity_token, :only => [:new_or_edit_choose_question]
|
2017-04-07 10:16:13 +08:00
|
|
|
|
|
|
|
|
|
|
include ApplicationHelper
|
|
|
|
|
|
|
|
|
|
|
|
def new
|
|
|
|
|
|
# 顶部导航
|
2017-07-26 18:50:52 +08:00
|
|
|
|
@st = params[:st].to_i
|
2017-04-07 10:16:13 +08:00
|
|
|
|
@project_menu_type = 11
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
|
format.html { render :action => 'new', :layout => 'base_shixun' }
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def create
|
2017-07-21 15:11:20 +08:00
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
|
begin
|
|
|
|
|
|
challenge_count = @shixun.challenges.count
|
|
|
|
|
|
@challenge = Challenge.new(params[:challenge])
|
|
|
|
|
|
@challenge.position = challenge_count + 1
|
|
|
|
|
|
@challenge.shixun = @shixun
|
|
|
|
|
|
@challenge.user = User.current
|
2017-07-26 18:50:52 +08:00
|
|
|
|
@challenge.st = params[:st].to_i
|
2017-09-04 14:57:34 +08:00
|
|
|
|
@challenge.save!
|
|
|
|
|
|
=begin
|
2017-07-21 15:11:20 +08:00
|
|
|
|
if @challenge.save!
|
2017-07-28 10:40:37 +08:00
|
|
|
|
if params[:st].to_i != 0
|
|
|
|
|
|
#创建选项
|
|
|
|
|
|
params[:question][:cnt].each_with_index do |test, index|
|
|
|
|
|
|
answer = params[:choice][:answer][index] == "0" ? false : true
|
|
|
|
|
|
ChallengeQuestion.create(:option_name => test, :challenge_id => @challenge.id, :position => index, :right_key => answer)
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
2017-07-21 15:11:20 +08:00
|
|
|
|
end
|
2017-09-04 14:57:34 +08:00
|
|
|
|
=end
|
2017-08-04 17:28:53 +08:00
|
|
|
|
# 实训是否需要重启
|
2017-08-15 10:14:01 +08:00
|
|
|
|
# 非实践任务创建第一个阶段时调用 publishGame, 避免不包含实践任务的实训进行模拟实战时报错
|
|
|
|
|
|
if @challenge.position == 1 && params[:st].to_i != 0
|
|
|
|
|
|
add_shixun_modify_status @shixun, 1
|
|
|
|
|
|
else
|
|
|
|
|
|
shixun_modify_status_without_publish(@shixun, 1)
|
|
|
|
|
|
end
|
2017-07-21 15:11:20 +08:00
|
|
|
|
redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun)
|
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
|
flash[:error] = "#{e.message}"
|
2017-07-26 18:50:52 +08:00
|
|
|
|
redirect_to new_shixun_challenge_path(:shixun_id => @shixun, :st => params[:st].to_i)
|
2017-07-21 15:11:20 +08:00
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
|
|
end
|
2017-07-20 16:25:44 +08:00
|
|
|
|
end
|
2017-04-07 10:16:13 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
2017-04-12 13:36:13 +08:00
|
|
|
|
# 处理新建challenge返回的pipeline片段
|
|
|
|
|
|
def fragment_from_jenkins
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
2017-04-07 10:16:13 +08:00
|
|
|
|
def index
|
|
|
|
|
|
# 顶部导航
|
2017-08-11 19:56:27 +08:00
|
|
|
|
@challenges = @shixun.challenges.order("position asc")
|
2017-04-07 10:16:13 +08:00
|
|
|
|
respond_to do |format|
|
|
|
|
|
|
format.js
|
|
|
|
|
|
format.html
|
|
|
|
|
|
end
|
|
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
|
|
render_404
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def show
|
2017-07-04 14:53:18 +08:00
|
|
|
|
challenge_num = Challenge.where(:shixun_id => @shixun).count
|
|
|
|
|
|
challenge_pos = @challenge.position
|
|
|
|
|
|
if challenge_pos < challenge_num
|
2017-08-08 10:32:36 +08:00
|
|
|
|
@next_challenge = Challenge.where(:shixun_id => @shixun, :position => challenge_pos + 1).first
|
2017-07-04 14:53:18 +08:00
|
|
|
|
end
|
2017-08-08 10:32:36 +08:00
|
|
|
|
@prev_challenge = Challenge.where(:shixun_id => @shixun, :position => challenge_pos - 1).first if challenge_pos - 1 > 0
|
2017-04-07 10:16:13 +08:00
|
|
|
|
respond_to do |format|
|
|
|
|
|
|
format.html
|
|
|
|
|
|
format.js
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def edit
|
2017-07-26 18:50:52 +08:00
|
|
|
|
@st = @challenge.st
|
2017-07-21 16:57:47 +08:00
|
|
|
|
challenge_num = Challenge.where(:shixun_id => @shixun).count
|
|
|
|
|
|
challenge_pos = @challenge.position
|
|
|
|
|
|
if challenge_pos < challenge_num
|
|
|
|
|
|
@next_challenge = Challenge.where(:shixun_id => @shixun, :position => challenge_pos+1).first
|
|
|
|
|
|
end
|
2017-09-12 14:08:19 +08:00
|
|
|
|
@prev_challenge = Challenge.where(:shixun_id => @shixun, :position => challenge_pos - 1).first if (challenge_pos - 1) > 0
|
2017-07-21 09:12:42 +08:00
|
|
|
|
@tab = params[:tab].blank? ? 1 : params[:tab].to_i
|
|
|
|
|
|
@editor = params[:editor] # 编辑模式
|
2017-09-05 16:46:51 +08:00
|
|
|
|
respond_to do |format|
|
|
|
|
|
|
format.html
|
|
|
|
|
|
format.js
|
|
|
|
|
|
end
|
2017-04-07 10:16:13 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
2017-09-12 09:05:51 +08:00
|
|
|
|
def new_choose_question
|
2017-09-07 09:42:12 +08:00
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
|
begin
|
2017-09-12 09:05:51 +08:00
|
|
|
|
@challenge_choose = ChallengeChoose.new
|
|
|
|
|
|
@challenge_choose.challenge_id = @challenge.id
|
|
|
|
|
|
@challenge_choose.subject = params[:choose][:subject]
|
|
|
|
|
|
@challenge_choose.answer = params[:choose][:answer]
|
2017-09-07 09:42:12 +08:00
|
|
|
|
@challenge_choose.standard_answer = params[:standard_answer]
|
2017-09-12 09:05:51 +08:00
|
|
|
|
@challenge_choose.score = params[:challenge][:score].to_i
|
|
|
|
|
|
@challenge_choose.difficult = params[:challenge][:difficulty].to_i
|
|
|
|
|
|
@challenge_choose.position = params[:position].to_i
|
2017-09-12 14:08:19 +08:00
|
|
|
|
@challenge_choose.category = params[:category].to_i
|
2017-09-12 09:05:51 +08:00
|
|
|
|
if @challenge_choose.save!
|
|
|
|
|
|
# 创建选项
|
|
|
|
|
|
params[:question][:cnt].each_with_index do |test, index|
|
|
|
|
|
|
answer = params[:choice][:answer][index] == "0" ? false : true
|
|
|
|
|
|
ChallengeQuestion.create(:option_name => test, :challenge_choose_id => @challenge_choose.id, :position => index, :right_key => answer)
|
|
|
|
|
|
end
|
|
|
|
|
|
# 创建单选多选的技能标签
|
|
|
|
|
|
unless params[:knowledge].blank?
|
|
|
|
|
|
params[:knowledge][:input].each do |input|
|
|
|
|
|
|
ChallengeTag.create(:name => input, :challenge_choose_id => @challenge_choose.id, :challenge_id => @challenge.id)
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
2017-09-15 11:23:24 +08:00
|
|
|
|
@index = params[:position].to_i - 1
|
2017-09-27 10:27:51 +08:00
|
|
|
|
# 发起重置请求
|
|
|
|
|
|
shixun_modify_status_without_publish(@shixun, 1)
|
2017-09-07 09:42:12 +08:00
|
|
|
|
respond_to do |format|
|
|
|
|
|
|
format.js
|
|
|
|
|
|
end
|
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
|
flash[:error] = "#{e.message}"
|
|
|
|
|
|
redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun)
|
|
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
|
|
end
|
2017-09-06 14:42:31 +08:00
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
2017-09-12 16:22:52 +08:00
|
|
|
|
def update_choose_question
|
|
|
|
|
|
@challenge_choose = ChallengeChoose.where(:id => params[:choose_id]).first
|
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
|
@challenge_choose.update_attributes(:subject => params[:choose][:subject],
|
|
|
|
|
|
:answer => params[:choose][:answer],
|
|
|
|
|
|
:standard_answer => params[:standard_answer],
|
|
|
|
|
|
:score => params[:challenge][:score].to_i,
|
|
|
|
|
|
:difficult => params[:challenge][:difficulty].to_i)
|
|
|
|
|
|
begin
|
|
|
|
|
|
@challenge_choose.challenge_questions.delete_all
|
|
|
|
|
|
params[:question][:cnt].each_with_index do |test, index|
|
|
|
|
|
|
answer = params[:choice][:answer][index] == "0" ? false : true
|
|
|
|
|
|
ChallengeQuestion.create(:option_name => test, :challenge_choose_id => @challenge_choose.id, :position => index, :right_key => answer)
|
|
|
|
|
|
end
|
2017-09-26 16:14:14 +08:00
|
|
|
|
# 发起重置请求
|
|
|
|
|
|
shixun_modify_status_without_publish(@shixun, 1)
|
2017-09-12 16:22:52 +08:00
|
|
|
|
@challenge_choose.challenge_tags.delete_all unless @challenge_choose.challenge_tags.blank?
|
|
|
|
|
|
unless params[:knowledge].blank?
|
|
|
|
|
|
params[:knowledge][:input].each do |input|
|
|
|
|
|
|
ChallengeTag.create(:name => input, :challenge_choose_id => @challenge_choose.id, :challenge_id => @challenge.id)
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
@challenge_choose = ChallengeChoose.where(:id => params[:choose_id]).first
|
2017-09-14 19:41:30 +08:00
|
|
|
|
@index = params[:index].to_i
|
2017-09-12 16:22:52 +08:00
|
|
|
|
respond_to do |format|
|
|
|
|
|
|
format.js
|
|
|
|
|
|
end
|
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
|
flash[:error] = "#{e.message}"
|
|
|
|
|
|
format.html{redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun)}
|
|
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def edit_choose_question
|
|
|
|
|
|
@challenge_choose = ChallengeChoose.where(:id => params[:choose_id]).first
|
|
|
|
|
|
@category = @challenge_choose.category
|
|
|
|
|
|
@position = @challenge_choose.position.to_i
|
2017-09-14 19:41:30 +08:00
|
|
|
|
@index = params[:index].to_i
|
2017-09-12 16:22:52 +08:00
|
|
|
|
respond_to do |format|
|
|
|
|
|
|
format.js
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
2017-09-12 14:08:19 +08:00
|
|
|
|
def choose_type_show
|
|
|
|
|
|
@challenge_choose = ChallengeChoose.where(:id => params[:choose_id]).first
|
2017-09-14 19:41:30 +08:00
|
|
|
|
@index = params[:index].to_i
|
2017-09-12 14:08:19 +08:00
|
|
|
|
respond_to do |format|
|
|
|
|
|
|
format.js
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
2017-09-12 16:22:52 +08:00
|
|
|
|
def destroy_challenge_choose
|
|
|
|
|
|
@challenge_choose = ChallengeChoose.where(:id => params[:choose_id]).first
|
|
|
|
|
|
@challenge_choose.destroy
|
2017-09-27 08:47:48 +08:00
|
|
|
|
# 发起重置请求
|
|
|
|
|
|
shixun_modify_status_without_publish(@shixun, 1)
|
2017-09-12 16:22:52 +08:00
|
|
|
|
redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun)
|
|
|
|
|
|
end
|
|
|
|
|
|
|
2017-09-06 14:42:31 +08:00
|
|
|
|
def add_choose_question
|
2017-09-12 14:08:19 +08:00
|
|
|
|
@category = params[:category].to_i
|
2017-09-21 17:56:53 +08:00
|
|
|
|
@position = params[:position].to_i
|
2017-09-12 14:08:19 +08:00
|
|
|
|
#@challenge_choose = @challenge.challenge_chooses
|
2017-09-06 14:42:31 +08:00
|
|
|
|
respond_to do |format|
|
|
|
|
|
|
format.js
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
2017-04-07 10:16:13 +08:00
|
|
|
|
def destroy
|
2017-08-08 15:35:34 +08:00
|
|
|
|
next_challenges = @shixun.challenges.where("position > #{@challenge.position}")
|
|
|
|
|
|
next_challenges.update_all("position = position - 1")
|
|
|
|
|
|
@challenges = @shixun.challenges
|
|
|
|
|
|
add_shixun_modify_status(@shixun, 1)
|
2017-09-15 19:28:19 +08:00
|
|
|
|
@challenge.destroy
|
2017-04-07 10:16:13 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def update
|
2017-07-27 10:07:58 +08:00
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
|
@challenge.update_attributes(params[:challenge])
|
2017-09-05 16:46:51 +08:00
|
|
|
|
#if (params[:tab] == "1" || params[:tab].nil?) && @challenge.st != 0
|
|
|
|
|
|
# begin
|
|
|
|
|
|
# @challenge.challenge_questions.delete_all
|
|
|
|
|
|
# params[:question][:cnt].each_with_index do |test, index|
|
|
|
|
|
|
# answer = params[:choice][:answer][index] == "0" ? false : true
|
|
|
|
|
|
# ChallengeQuestion.create(:option_name => test, :challenge_id => @challenge.id, :position => index, :right_key => answer)
|
|
|
|
|
|
# end
|
|
|
|
|
|
# redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab])
|
|
|
|
|
|
# rescue Exception => e
|
|
|
|
|
|
# flash[:error] = "#{e.message}"
|
|
|
|
|
|
# format.html{redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun)}
|
|
|
|
|
|
# raise ActiveRecord::Rollback
|
|
|
|
|
|
# end
|
|
|
|
|
|
#else
|
2017-07-27 10:07:58 +08:00
|
|
|
|
redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab])
|
2017-09-05 16:46:51 +08:00
|
|
|
|
#end
|
2017-07-26 18:50:52 +08:00
|
|
|
|
end
|
2017-07-20 16:25:44 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def update_evaluation
|
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
|
@challenge.update_attributes(params[:challenge])
|
|
|
|
|
|
begin
|
|
|
|
|
|
if params[:tab].to_i == 2
|
|
|
|
|
|
@test_sets.delete_all unless @test_sets.blank?
|
|
|
|
|
|
if params[:test_set][:hidden].length > 0
|
|
|
|
|
|
params[:test_set][:input].each_with_index do |input, index|
|
|
|
|
|
|
unless (input[index] == params[:test_set][:output][index] && input[index].nil?)
|
|
|
|
|
|
params[:test_set][:hidden][index].to_i == 0 ? open = 1 : open = 0
|
|
|
|
|
|
TestSet.create(:challenge_id => @challenge.id, :input => input, :output => params[:test_set][:output][index], :is_public => open, :position => (index + 1))
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
2017-08-10 11:22:42 +08:00
|
|
|
|
# 向jenkins端发送请求,构建公共测试用例
|
2017-09-28 19:27:27 +08:00
|
|
|
|
shixun_modify_status_publish(@shixun, 1)
|
2017-07-20 16:25:44 +08:00
|
|
|
|
elsif params[:tab].to_i == 5
|
|
|
|
|
|
@challenge_tags.delete_all unless @challenge_tags.blank?
|
|
|
|
|
|
unless params[:knowledge].blank?
|
|
|
|
|
|
params[:knowledge][:input].each do |input|
|
|
|
|
|
|
ChallengeTag.create(:name => input, :challenge_id => @challenge.id)
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
2017-09-03 17:37:29 +08:00
|
|
|
|
if params[:tab].to_i == 5
|
|
|
|
|
|
redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab]), notice: 'Succeed'
|
|
|
|
|
|
else
|
|
|
|
|
|
redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab])
|
|
|
|
|
|
end
|
2017-07-20 16:25:44 +08:00
|
|
|
|
rescue Exception => e
|
|
|
|
|
|
flash[:error] = "#{e.message}"
|
|
|
|
|
|
redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab])
|
|
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
2017-04-07 10:16:13 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def index_down
|
|
|
|
|
|
next_challenge = @challenge.next_challenge
|
|
|
|
|
|
position = @challenge.position
|
|
|
|
|
|
@challenge.update_attribute(:position, (position + 1))
|
|
|
|
|
|
next_challenge.update_attribute(:position, next_challenge.position - 1)
|
|
|
|
|
|
@challenges = @shixun.challenges
|
2017-06-22 16:21:47 +08:00
|
|
|
|
# 向jenkins端发送请求,构建公共测试用例
|
|
|
|
|
|
add_shixun_modify_status(@shixun, 1)
|
2017-04-07 10:16:13 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def index_up
|
|
|
|
|
|
position = @challenge.position
|
|
|
|
|
|
last_challenge = @challenge.last_challenge
|
|
|
|
|
|
@challenge.update_attribute(:position, (position - 1))
|
|
|
|
|
|
last_challenge.update_attribute(:position, last_challenge.position + 1)
|
|
|
|
|
|
@challenges = @shixun.challenges
|
2017-06-22 16:21:47 +08:00
|
|
|
|
# 向jenkins端发送请求,构建公共测试用例
|
|
|
|
|
|
add_shixun_modify_status(@shixun, 1)
|
2017-04-07 10:16:13 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# build job 只负责发送请求
|
|
|
|
|
|
def challenge_build
|
|
|
|
|
|
gitUrl = git_repository_url(@shixun, "Shixun")
|
2017-08-06 15:34:24 +08:00
|
|
|
|
gitUrl = Base64.urlsafe_encode64(gitUrl)
|
2017-04-07 10:16:13 +08:00
|
|
|
|
taskId = params[:id]
|
|
|
|
|
|
jobName = @shixun.forked_form
|
|
|
|
|
|
step = @challenge.position
|
|
|
|
|
|
jenkins_shixuns = Redmine::Configuration['jenkins_shixuns']
|
|
|
|
|
|
if @challenge.status == 0
|
|
|
|
|
|
params = {:jobName => "#{jobName}", :taskId => "#{taskId}", :step => "#{step}", :gitUrl => "#{gitUrl}"}
|
|
|
|
|
|
uri = URI("#{jenkins_shixuns}/jenkins-exec/api/buildJob")
|
|
|
|
|
|
res = uri_exec uri, params
|
|
|
|
|
|
# @challenge.update_attribute(:status, 1)
|
|
|
|
|
|
end
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
|
format.js
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
def count_input input, output
|
|
|
|
|
|
if input.length == 0 && output.length == 0
|
|
|
|
|
|
result = 0
|
|
|
|
|
|
else
|
|
|
|
|
|
if input.length > output.length
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def tpi_manager_allowed
|
|
|
|
|
|
unless (User.current.manager_of_shixun?(@shixun) || User.current.admin?)
|
|
|
|
|
|
render_403
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
2017-04-28 10:21:02 +08:00
|
|
|
|
def allowed_view
|
2017-05-21 11:35:28 +08:00
|
|
|
|
unless (allow_to_view_challenge(@challenge, @shixun) || User.current.manager_of_shixun?(@shixun))
|
2017-04-28 10:21:02 +08:00
|
|
|
|
render_403
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
2017-04-07 10:16:13 +08:00
|
|
|
|
def build_challege_from_params
|
|
|
|
|
|
if params[:id].blank?
|
|
|
|
|
|
@challenge = Challenge.new
|
|
|
|
|
|
@challenge.shixun = @shixun
|
|
|
|
|
|
else
|
|
|
|
|
|
@challenge = @shixun.challenges.find(params[:id])
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
@challenge.shixun = @shixun
|
|
|
|
|
|
@challenge.user ||= User.current
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def query_challeges
|
|
|
|
|
|
@test_sets = @challenge.test_sets
|
|
|
|
|
|
@challenge_tags = @challenge.challenge_tags
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def find_challenge
|
|
|
|
|
|
@challenge = Challenge.find(params[:id])
|
|
|
|
|
|
@shixun = @challenge.shixun
|
|
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
|
|
render_404
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Find project of id params[:id]
|
|
|
|
|
|
def find_shixun
|
|
|
|
|
|
shixun_id = params[:shixun_id] || (params[:challenge] && params[:challenge][:shixun_id])
|
2017-04-25 17:15:37 +08:00
|
|
|
|
@shixun = Shixun.find_by_identifier(shixun_id)
|
2017-04-26 14:20:07 +08:00
|
|
|
|
if @shixun.nil?
|
|
|
|
|
|
render_404
|
|
|
|
|
|
return
|
2017-06-23 10:38:40 +08:00
|
|
|
|
else
|
|
|
|
|
|
if (@shixun.status == 0 && !(User.current.manager_of_shixun?(@shixun) || User.current.admin?))
|
|
|
|
|
|
render_403
|
|
|
|
|
|
return
|
|
|
|
|
|
end
|
2017-04-26 14:20:07 +08:00
|
|
|
|
end
|
2017-04-07 10:16:13 +08:00
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
|
|
render_404
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def find_shixun_language
|
|
|
|
|
|
language = @shixun.language
|
|
|
|
|
|
@language = language_switch language
|
|
|
|
|
|
end
|
|
|
|
|
|
|
2017-09-07 10:26:54 +08:00
|
|
|
|
def default_format_js
|
|
|
|
|
|
response.headers['content--type'] = 'text/javascript'
|
|
|
|
|
|
request.format = 'js'
|
|
|
|
|
|
end
|
2017-04-07 10:16:13 +08:00
|
|
|
|
end
|