Merge branch 'dev_daiao' into dev_aliyun

dev_cs
daiao 5 years ago
commit 3d9287815d

@ -191,21 +191,28 @@ class ChallengesController < ApplicationController
sets_input = test_set.map(&:input)
sets_open = test_set.map(&:is_public)
set_score = test_set.map(&:score)
set_match_rule = test_set.map(&:match_rule)
params_hidden = params[:test_set].map{|set| set[:hidden].to_i == 0}
params_output = params[:test_set].map{|set| set[:output] }
params_input = params[:test_set].map{|set| set[:input] }
params_score = params[:test_set].map{|set| set[:score]}
params_test_set = params[:test_set].map{|set| set[:match_rule]}
# 测试集变化则需要更新(输入、 输出、 是否隐藏)
if sets_output != params_output || sets_open != params_hidden || sets_input != params_input || set_score != params_score
if sets_output != params_output || sets_open != params_hidden || sets_input != params_input ||
set_score != params_score || params_test_set != set_match_rule
test_set.delete_all unless test_set.blank?
params[:test_set].each_with_index do |set, index|
TestSet.create(:challenge_id => @challenge.id,
:input => "#{set[:input]}",
:output => "#{set[:output]}",
:is_public => params_hidden[index],
:score => set[:score],
:position => (index + 1))
end
params[:test_set].each_with_index do |set, index|
# last 末尾匹配, full: 全完匹配
logger.info("set: #{set}; match_rule : #{set[:match_rule]}")
match_rule = set[:match_rule] == 'last' ? 'last' : 'full'
TestSet.create(:challenge_id => @challenge.id,
:input => "#{set[:input]}",
:output => "#{set[:output]}",
:is_public => params_hidden[index],
:score => set[:score],
:match_rule => "#{match_rule}",
:position => (index + 1))
end
@challenge.update_column(:modify_time, Time.now)
# 测试集的
@shixun.myshixuns.update_all(:system_tip => 0)

@ -537,7 +537,7 @@ class GamesController < ApplicationController
game_challenge.test_sets.each do |test_set|
input = test_set.input.nil? ? "" : test_set.input.gsub("\r\n", "\n")
output = test_set.output.nil? ? "" : test_set.output.gsub("\r\n", "\n")
test_cases = {:input => input, :output => output}
test_cases = {:input => input, :output => output, :matchRule => test_set.match_rule}
testSet << test_cases
end
@ -560,6 +560,13 @@ class GamesController < ApplicationController
# needPortMapping web类型需要pod端口映射
br_params[:needPortMapping] = 8080 if @myshixun.mirror_name.include?("Web")
# 私密仓库的设置
secret_rep = @shixun.shixun_secret_repository
if secret_rep&.repo_name
secretGitUrl = repo_url secret_rep.repo_path
br_params.merge({secretGitUrl: secretGitUrl, secretDir: secret_rep.secret_dir_path})
end
# 中间层交互
uri = "#{shixun_tomcat}/bridge/game/gameEvaluate"
res = interface_post uri, br_params, 502, "gameEvaluate failed"

@ -473,8 +473,19 @@ class ShixunsController < ApplicationController
@shixun.shixun_service_configs.create!(config) if name.present?
end
end
# 添加第二仓库
if params[:is_secret_repository]
add_secret_repository
else
# 如果有仓库,就要删
if @shixun.shixun_secret_repository&.repo_name
GitService.delete_repository(repo_path: @shixun.shixun_secret_repository.repo_path)
@shixun.shixun_secret_repository.destroy
end
end
rescue Exception => e
uid_logger_error(e.message)
uid_logger_error("实训保存失败--------#{e.message}")
tip_exception("实训保存失败")
raise ActiveRecord::Rollback
end
@ -819,6 +830,30 @@ class ShixunsController < ApplicationController
end
end
# 设置私密版本库的在tpm中的目录
def set_secret_dir
raise("设置路径不能为空") if params[:secret_dir_path].blank?
raise("请先配置私密版本库") if @shixun.shixun_secret_repository.blank?
@shixun.shixun_secret_repository.update_attributes(:secret_dir_path => params[:secret_dir_path])
normal_status("设置成功")
end
def secret_repository
begin
@repo_path = @shixun.shixun_secret_repository&.repo_path
@repo_url = repo_url @repo_path
@trees = GitService.file_tree(repo_path: @repo_path, path: params[:path])
logger.info("#11@@#@#@#@111#@@@@###{@trees}")
if @trees
logger.info("#@@#@#@#@#@@@@###{@trees.try(:count)}")
@latest_commit = [GitService.commits(repo_path: @repo_path).first]
Rails.logger.info("########## #{@latest_commit}")
end
rescue Exception => e
logger.error(e.message)
end
end
include GitCommon
def update_file
@ -955,7 +990,13 @@ private
end
def find_repo_name
@repo_path = @shixun.try(:repo_path)
# 有私密版本库的参数时,需要拿私密仓库
@repo_path = if params[:secret_repository]
@shixun.shixun_secret_repository&.repo_path
else
@shixun.try(:repo_path)
end
logger.info("######{@repo_path}")
@path = params[:path]
end
@ -990,4 +1031,13 @@ private
modify_shixun = ShixunModify.exists?(:myshixun_id => current_myshixun.id, :shixun_id => @shixun.id, :status => 1)
games.size != min_challenges.size || modify_shixun
end
# 添加私密仓库
def add_secret_repository
# 防止跟tpm版本库重名加了前缀secret
repo_path = repo_namespace(current_user.login, "secret_#{@shixun.identifier}")
GitService.add_repository(repo_path: repo_path)
ShixunSecretRepository.create!(repo_name: repo_path.split(".")[0], shixun_id: @shixun.id)
end
end

@ -38,6 +38,9 @@ class Shixun < ApplicationRecord
has_one :shixun_info, dependent: :destroy
# 第二版本库
has_one :shixun_secret_repository, dependent: :destroy
belongs_to :user
# 实训服务配置
has_many :shixun_service_configs, :dependent => :destroy

@ -0,0 +1,11 @@
class ShixunSecretRepository < ApplicationRecord
# repo_name: 仓库名
# secret_dir_name: 在tpm仓库的那个目录下
belongs_to :shixun
def repo_path
"#{repo_name}.git"
end
end

@ -1,2 +1,3 @@
class TestSet < ApplicationRecord
# match_rule: 匹配规则: full 完全匹配, last 末尾匹配
end

@ -16,7 +16,7 @@ elsif @tab == 1
json.has_web_route @shixun.has_web_route?
json.test_sets @challenge.test_sets do |set|
json.hidden (set.is_public ? 0 : 1)
json.(set, :input, :output, :score)
json.(set, :input, :output, :score, :match_rule)
end
elsif @tab == 2
# 参考答案

@ -0,0 +1,8 @@
json.trees @trees
if @trees.present?
json.partial! 'shixuns/commit', locals: { commits: @latest_commit }
end
json.git_url @repo_url
json.secret_dir_path @shixun.shixun_secret_repository&.secret_dir_path

@ -30,6 +30,8 @@ json.shixun do
json.scope_partment @shixun.schools.map(&:name) # 公开范围
json.opening_time @shixun.opening_time
json.forbid_copy @shixun.forbid_copy
# 私密仓库
json.is_secret_repository @shixun.shixun_secret_repository.present?
# 实训服务配置
json.shixun_service_configs do

@ -2,3 +2,4 @@ json.fork_from @fork_from
json.identity User.current.shixun_identity(@shixun)
json.power @power
json.partial! 'shixuns/top', locals: { shixun: @shixun, current_myshixun: @current_myshixun }
json.secret_repository @shixun.shixun_secret_repository.present?

@ -197,6 +197,8 @@ Rails.application.routes.draw do
get :get_script_contents
get :get_custom_script
post :repository
post :secret_repository
post :set_secret_dir
post :commits
post :file_content
post :update_file

@ -0,0 +1,10 @@
class CreateShixunSecretRepositories < ActiveRecord::Migration[5.2]
def change
create_table :shixun_secret_repositories do |t|
t.references :shixun
t.string :repo_name
t.string :secret_dir_path
t.timestamps
end
end
end

@ -0,0 +1,7 @@
class AddMatchRuleForTestSets < ActiveRecord::Migration[5.2]
def change
add_column :test_sets, :match_rule, :string
TestSet.update_all(match_rule: 'full')
end
end

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe ShixunSecretRepository, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end
Loading…
Cancel
Save