From a1f263c31d7d9e5b5c77bea82ad16aba4c2e84df Mon Sep 17 00:00:00 2001
From: daiao <358551898@qq.com>
Date: Sat, 7 Sep 2019 10:12:01 +0800
Subject: [PATCH] =?UTF-8?q?vnc=E8=AF=84=E6=B5=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/controllers/games_controller.rb                       | 6 ++++--
 app/controllers/myshixuns_controller.rb                   | 3 ++-
 app/controllers/shixuns_controller.rb                     | 2 +-
 app/models/shixun.rb                                      | 3 +++
 app/views/games/show.json.jbuilder                        | 1 +
 app/views/shixuns/settings.json.jbuilder                  | 1 +
 db/migrate/20190907014649_add_vnc_evaluate_for_shixuns.rb | 5 +++++
 7 files changed, 17 insertions(+), 4 deletions(-)
 create mode 100644 db/migrate/20190907014649_add_vnc_evaluate_for_shixuns.rb

diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb
index 940db2883..ac72577e0 100644
--- a/app/controllers/games_controller.rb
+++ b/app/controllers/games_controller.rb
@@ -74,6 +74,7 @@ class GamesController < ApplicationController
         #@vnc_url = "http://#{service_host}:#{res['port']}/vnc_lite.html?password=headless"
         # 有域名版本
         @vnc_url = "https://#{res['port']}.#{service_host}/vnc_lite.html?password=headless"
+        @vnc_evaluate = @shixun.vnc_evaluate
       rescue Exception => e
         Rails.logger.error(e.message)
       end
@@ -535,13 +536,14 @@ class GamesController < ApplicationController
     end
 
     testCases = Base64.urlsafe_encode64(testSet.to_json) unless testSet.blank?
-
+    # 评测类型: 0,1,2 用于webssh的评测, 3用于vnc
+    podType = @shixun.vnc_evaluate ? 3 : @shixun.webssh
 
     # 注意:这个地方的参数写的时候不能换行
     content_modified = params[:content_modified] # 决定文件内容是否有修改,有修改如果中间层pull没有更新,则轮询等待更新
     br_params = {:tpiID => "#{@myshixun.id}", :tpiGitURL  => "#{gitUrl}", :buildID => "#{@game.id}",
                  :instanceChallenge  => "#{step}", :testCases => "#{testCases}", :resubmit => "#{resubmit}",
-                 :times => params[:first].to_i, :podType => @shixun.webssh, :content_modified => content_modified,
+                 :times => params[:first].to_i, :podType => podType, :content_modified => content_modified,
                  :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(@shixun))}",
                  :persistenceName => @shixun.identifier, :tpmScript => "#{tpmScript}", :sec_key => sec_key,
                  :timeLimit => game_challenge.exec_time, :isPublished => (@shixun.status < 2 ? 0 : 1) }
diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb
index 69bd01dde..8c11e88c5 100644
--- a/app/controllers/myshixuns_controller.rb
+++ b/app/controllers/myshixuns_controller.rb
@@ -266,7 +266,8 @@ class MyshixunsController < ApplicationController
                                         :identifier => @sec_key, :exec_time => exec_time)
         uid_logger("-- game build: file update #{@sec_key}, record id is #{record.id}, time is **** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}")
       end
-      unless @hide_code
+      # 隐藏代码文件 和  VNC的都不需要走版本库
+      unless @hide_code || @myshixun.shixun&.vnc_evaluate
         # 远程版本库文件内容
         last_content = GitService.file_content(repo_path: @repo_path, path: path)["content"]
         content = params[:content]
diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb
index 221197f4e..180c269b5 100644
--- a/app/controllers/shixuns_controller.rb
+++ b/app/controllers/shixuns_controller.rb
@@ -931,7 +931,7 @@ private
 		raise("实训名称不能为空") if params[:shixun][:name].blank?
 		params.require(:shixun).permit(:name, :trainee, :webssh, :can_copy, :use_scope, :vnc, :test_set_permission,
 																	 :task_pass, :multi_webssh, :opening_time, :mirror_script_id, :code_hidden,
-																	 :hide_code, :forbid_copy)
+																	 :hide_code, :forbid_copy, :vnc_evaluate)
 	end
 
 	def shixun_info_params
diff --git a/app/models/shixun.rb b/app/models/shixun.rb
index 33d36d026..9ad3cbcdf 100644
--- a/app/models/shixun.rb
+++ b/app/models/shixun.rb
@@ -5,6 +5,9 @@ class Shixun < ApplicationRecord
   # hide_code: 隐藏代码窗口
   # code_hidden: 隐藏代码目录
   # task_pass: 跳关
+  # webssh  0:不开启webssh;1:开启练习模式;  2:开启评测模式
+  # trainee 实训的难度
+  # vnc: VCN实训是否用于评测
   has_many :challenges, -> {order("challenges.position asc")}, dependent: :destroy
   has_many :challenge_tags, through: :challenges
 	has_many :myshixuns, :dependent => :destroy
diff --git a/app/views/games/show.json.jbuilder b/app/views/games/show.json.jbuilder
index 28d8bb859..048188746 100644
--- a/app/views/games/show.json.jbuilder
+++ b/app/views/games/show.json.jbuilder
@@ -3,6 +3,7 @@ json.(@base_date, :st, :discusses_count, :game_count, :record_onsume_time, :prev
     :shixun, :myshixun, :git_url)
 if @shixun.vnc
   json.vnc_url @vnc_url
+  json.vnc_evaluate @vnc_evaluate
 end
 json.user do
   json.partial! 'users/user', user: @user
diff --git a/app/views/shixuns/settings.json.jbuilder b/app/views/shixuns/settings.json.jbuilder
index e81498058..ad29f4176 100644
--- a/app/views/shixuns/settings.json.jbuilder
+++ b/app/views/shixuns/settings.json.jbuilder
@@ -22,6 +22,7 @@ json.shixun do
   json.hide_code @shixun.hide_code # 隐藏代码窗口
   json.code_hidden @shixun.code_hidden # 代码目录隐藏
   json.vnc @shixun.vnc
+  json.vnc_evaluate @shixun.vnc_evaluate
   #json.exec_time @shixun.exec_time
   json.webssh @shixun.webssh
   json.multi_webssh @shixun.multi_webssh
diff --git a/db/migrate/20190907014649_add_vnc_evaluate_for_shixuns.rb b/db/migrate/20190907014649_add_vnc_evaluate_for_shixuns.rb
new file mode 100644
index 000000000..861c4501e
--- /dev/null
+++ b/db/migrate/20190907014649_add_vnc_evaluate_for_shixuns.rb
@@ -0,0 +1,5 @@
+class AddVncEvaluateForShixuns < ActiveRecord::Migration[5.2]
+  def change
+    add_column :shixuns, :vnc_evaluate, :boolean, default: false
+  end
+end