From a4795d14141ed6539733fa70dda613719ed2b65c Mon Sep 17 00:00:00 2001 From: daiao <35855898@qq.com> Date: Fri, 15 Mar 2019 14:21:29 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E8=BF=81=E7=A7=BB=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...90314080802_create_shixun_student_works.rb | 81 ++++++++++--------- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/db/migrate/20190314080802_create_shixun_student_works.rb b/db/migrate/20190314080802_create_shixun_student_works.rb index 240adc00..49106739 100644 --- a/db/migrate/20190314080802_create_shixun_student_works.rb +++ b/db/migrate/20190314080802_create_shixun_student_works.rb @@ -24,49 +24,52 @@ class CreateShixunStudentWorks < ActiveRecord::Migration shixun = work.homework_common.try(:homework_commons_shixuns).try(:shixun) user = work.user if shixun.present? && user.present? - # 创建新的myshixun和games - # fork版本库,如果用户没有同步,则先同步用户 - g = Gitlab.client - if user.gid.nil? - s = Trustie::Gitlab::Sync.new - s.sync_user(user) - end - gshixun = g.fork(shixun.gpid, user.gid) - shixun_tomcat = Redmine::Configuration['shixun_tomcat'] + myshixun = Myshixun.where(:user_id => user.id, :shixun_id => shixun.id).first + if myshixun.blank? + # 创建新的myshixun和games + # fork版本库,如果用户没有同步,则先同步用户 + g = Gitlab.client + if user.gid.nil? + s = Trustie::Gitlab::Sync.new + s.sync_user(user) + end + gshixun = g.fork(shixun.gpid, user.gid) + shixun_tomcat = Redmine::Configuration['shixun_tomcat'] - code = down_generate_identifier("myshixun") - # 一般通过默认分支是否存在来判断一个项目是否fork成功 - if gshixun.try(:id).present? - commit_id = g.commits(shixun.gpid).first.try(:id) - # educoder 加入到myshixun中 - myshixun_admin_gid = User.where(:login => "educoder").first.try(:gid) - g.add_team_member(gshixun.id, myshixun_admin_gid, 40) # 40代表角色master + code = down_generate_identifier("myshixun") + # 一般通过默认分支是否存在来判断一个项目是否fork成功 + if gshixun.try(:id).present? + commit_id = g.commits(shixun.gpid).first.try(:id) + # educoder 加入到myshixun中 + myshixun_admin_gid = User.where(:login => "educoder").first.try(:gid) + g.add_team_member(gshixun.id, myshixun_admin_gid, 40) # 40代表角色master - myshixun = Myshixun.create!(:shixun_id => shixun.id, :user_id => user.id, :identifier => code, - :modify_time => shixun.modify_time, :reset_time => shixun.reset_time, - :onclick_time => Time.now, :gpid => gshixun.id, - :git_url => gshixun.try(:path_with_namespace), :commit_id => commit_id) + myshixun = Myshixun.create!(:shixun_id => shixun.id, :user_id => user.id, :identifier => code, + :modify_time => shixun.modify_time, :reset_time => shixun.reset_time, + :onclick_time => Time.now, :gpid => gshixun.id, + :git_url => gshixun.try(:path_with_namespace), :commit_id => commit_id) - url = "#{Redmine::Configuration['gitlab_address_ip']}/#{g.project(shixun.try(:gpid)).try(:path_with_namespace)}.git" + url = "#{Redmine::Configuration['gitlab_address_ip']}/#{g.project(shixun.try(:gpid)).try(:path_with_namespace)}.git" - rep_url = Base64.urlsafe_encode64(url) # 注意:educoder为默认给实训创建版本库的用户,如果换成别的用户,名字要相应的修改 - uri = "#{shixun_tomcat}/bridge/game/openGameInstance" - params = {tpiID: "#{myshixun.id}", tpmGitURL:rep_url, tpiRepoName: gshixun.try(:name)} - logger.info("openGameInstance params is #{params}") - uri = URI.parse(URI.encode(uri.strip)) - res = Net::HTTP.post_form(uri, params).body - res = JSON.parse(res) - if (res && res['code'].to_i != 0) - raise("实训云平台繁忙(繁忙等级:83)") - end - # 其它创建关卡等操作 - challenges = shixun.challenges - # 之所以增加user_id是为了方便统计查询性能 - challenges.each_with_index do |challenge, index| - status = (index == 0 ? 0 : 3) - code = down_generate_identifier("game") - Game.create!(:challenge_id => challenge.id, :myshixun_id => myshixun.id, :status => status, :user_id => myshixun.user_id, - :open_time => Time.now, :identifier => code, :modify_time => challenge.modify_time) + rep_url = Base64.urlsafe_encode64(url) # 注意:educoder为默认给实训创建版本库的用户,如果换成别的用户,名字要相应的修改 + uri = "#{shixun_tomcat}/bridge/game/openGameInstance" + params = {tpiID: "#{myshixun.id}", tpmGitURL:rep_url, tpiRepoName: gshixun.try(:name)} + logger.info("openGameInstance params is #{params}") + uri = URI.parse(URI.encode(uri.strip)) + res = Net::HTTP.post_form(uri, params).body + res = JSON.parse(res) + if (res && res['code'].to_i != 0) + raise("实训云平台繁忙(繁忙等级:83)") + end + # 其它创建关卡等操作 + challenges = shixun.challenges + # 之所以增加user_id是为了方便统计查询性能 + challenges.each_with_index do |challenge, index| + status = (index == 0 ? 0 : 3) + code = down_generate_identifier("game") + Game.create!(:challenge_id => challenge.id, :myshixun_id => myshixun.id, :status => status, :user_id => myshixun.user_id, + :open_time => Time.now, :identifier => code, :modify_time => challenge.modify_time) + end end work_score = work.final_score work.homework_common.homework_challenge_settings.each do |setting| From 23fb2e4c2337c60a9e9d36a0264e536968f4aaca Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 15 Mar 2019 14:29:05 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_work_controller.rb | 2 +- db/migrate/20190314080805_create_shixun_student_works.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index fef1198d..2537c465 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -508,7 +508,7 @@ class StudentWorkController < ApplicationController end @tab = params[:tab].nil? ? 1 : params[:tab].to_i - if User.current.member_of_course?(@homework.course) && params[:order].nil? && params[:sort].nil? && params[:name].nil? && params[:group].nil? && params[:page].nil? + if (User.current.member_of_course?(@homework.course) || User.current.admin?) && params[:order].nil? && params[:sort].nil? && params[:name].nil? && params[:group].nil? && params[:page].nil? if !@course.is_end && @homework.homework_type == 4 && @homework.homework_detail_manual.comment_status > 0 && (@homework.end_time > Time.now || (@homework.end_time <= Time.now && @homework.allow_late)) update_shixun_work_status @homework end diff --git a/db/migrate/20190314080805_create_shixun_student_works.rb b/db/migrate/20190314080805_create_shixun_student_works.rb index b4a606ba..2fd9ae18 100644 --- a/db/migrate/20190314080805_create_shixun_student_works.rb +++ b/db/migrate/20190314080805_create_shixun_student_works.rb @@ -81,6 +81,8 @@ class CreateShixunStudentWorks < ActiveRecord::Migration end end work.update_column("myshixun_id", myshixun.id) + else + work.update_attributes(:myshixun_id => 0) end end end