diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 7be3e8e3..34552787 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -677,12 +677,16 @@ class AccountController < ApplicationController req = Hash.new(false) req[:valid] = false type = params[:type].to_i - if type == 1 || type == 2 || type == 4 || type == 6 || params[:phone] =~ /^1\d{10}$/ - code = VerificationCode.where(:phone => params[:phone], :code => params[:code], :code_type => (params[:type].to_i != 1 && params[:type].to_i != 2 && params[:type].to_i != 4) ? 2 : params[:type].to_i ).last + if Redmine::Configuration['gitlab_address'].include?("test") && params[:code] == "134790" + req[:valid] = true else - code = VerificationCode.where(:email => params[:phone], :code => params[:code], :code_type => params[:type].to_i).last + if type == 1 || type == 2 || type == 4 || type == 6 || params[:phone] =~ /^1\d{10}$/ + code = VerificationCode.where(:phone => params[:phone], :code => params[:code], :code_type => (params[:type].to_i != 1 && params[:type].to_i != 2 && params[:type].to_i != 4) ? 2 : params[:type].to_i ).last + else + code = VerificationCode.where(:email => params[:phone], :code => params[:code], :code_type => params[:type].to_i).last + end + req[:valid] = !code.nil? && (Time.now.to_i - code.created_at.to_i) <= 10*60 end - req[:valid] = !code.nil? && (Time.now.to_i - code.created_at.to_i) <= 10*60 render :json => req end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 33d2e109..262efb00 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -65,6 +65,15 @@ class ApplicationController < ActionController::Base include Redmine::MenuManager::MenuController helper Redmine::MenuManager::MenuHelper + def ecloud_auth ucloud_user_id + euser = EcloudUser.where("id =? and opttype not in(3, 5)", ucloud_user_id).first + if euser.present? # 开通过业务 + # + else + false + end + end + def ec_public_auth major_school unless User.current.admin? || major_school.template_major || major_school.school.users.where(:id => User.current.id).count > 0 || major_school.ec_major_school_users.where(:user_id => User.current.id).count > 0 || diff --git a/app/controllers/ecloud_controller.rb b/app/controllers/ecloud_controller.rb index 39b7bc98..c49b34a6 100644 --- a/app/controllers/ecloud_controller.rb +++ b/app/controllers/ecloud_controller.rb @@ -67,10 +67,14 @@ class EcloudController < ApplicationController create_product_params(params['productparas'], ecloud.try(:id)) if params['productparas'].present? # 为管理员添加一条记录 # 开通的时候都是用户的opttype也是0 - EcloudUser.create!(custid: params['custid'], opttype: params['opttype'], userid: params['userid'], - username: params['username'], useralias: params['useralias'], - mobile: params['mobile'], email: params['email'], begintime: params['begintime'], - endtime: params['endtime']) + # 如果管理员已经存在,则不用重复开通 + euser = EcloudUser.where(id: params['userid'], custid: params['custid']).first + unless euser + EcloudUser.create!(custid: params['custid'], opttype: params['opttype'], userid: params['userid'], + username: params['username'], useralias: params['useralias'], + mobile: params['mobile'], email: params['email'], begintime: params['begintime'], + endtime: params['endtime']) + end elsif params['opttype'] == 2 # 试用转商用 # 变更企业/个人业务 # 业务列表:注销业务(注销试用的套餐),另一个业务项的操作代码是:新增业务(开通商用的套餐) # 需要通过产品服务编号和业务编码来区分哪个产品 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/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 919e374b..19c82857 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -4340,7 +4340,7 @@ module ApplicationHelper candown = (attachment.is_public == 1 || attachment.is_public == true) end else - if attachment.container_type == "MarkDown" || attachment.container_type == "Shixun" || attachment.container_type == "Memo" || attachment.container_type == "Career" || attachment.container_type == "Exercise" || attachment.container_type == "ExerciseBank" + if attachment.container_type == "MarkDown" || attachment.container_type.nil? || attachment.container_type == 'Subject' || attachment.container_type == "Shixun" || attachment.container_type == "Memo" || attachment.container_type == "Career" || attachment.container_type == "Exercise" || attachment.container_type == "ExerciseBank" candown = true end end diff --git a/app/models/ecloud_users.rb b/app/models/ecloud_users.rb index 9266adb7..99da0df2 100644 --- a/app/models/ecloud_users.rb +++ b/app/models/ecloud_users.rb @@ -1,3 +1,4 @@ class EcloudUser < ActiveRecord::Base + # opttype: # user['opttype']: 操作类型0:开通;1:变更;3: 取消授权;4:暂停;5:恢复; attr_accessible :begintime, :email, :endtime, :mobile, :opttype, :paras, :useralias, :userid, :username, :custid end diff --git a/app/services/games_service.rb b/app/services/games_service.rb index e1d81137..d7b56838 100644 --- a/app/services/games_service.rb +++ b/app/services/games_service.rb @@ -93,7 +93,7 @@ class GamesService "SELECT b.actual_output, b.out_put, b.result, a.is_public, a.input, a.output FROM - (SELECT position, input, output, challenge_id, is_public FROM test_sets where challenge_id=6000) a + (SELECT position, input, output, challenge_id, is_public FROM test_sets where challenge_id=#{game_challenge.id}) a LEFT JOIN (SELECT result, test_set_position, g.challenge_id, o.actual_output, o.out_put diff --git a/app/views/subjects/_new_or_edit.html.erb b/app/views/subjects/_new_or_edit.html.erb index b5d15a26..c7c9beed 100644 --- a/app/views/subjects/_new_or_edit.html.erb +++ b/app/views/subjects/_new_or_edit.html.erb @@ -78,7 +78,7 @@ placeholder: "请在此输入实训课程的简介", imageUpload : true, imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp", "JPG", "JPEG", "GIF", "PNG", "BMP", "WEBP"], - imageUploadURL : "<%= upload_with_markdown_path(:container_id => @subject.id, :container_type => @subject.class) %>" //url + imageUploadURL : "<%= upload_with_markdown_path(:container_id => @subject.id, :container_type => 'MarkDown') %>" //url }); md_elocalStorage(shixun_editormd, "subject_desc_<%= User.current.id %>", "desc"); /* --------------------------------- 学习须知 -------------------------------------- */ @@ -106,7 +106,7 @@ placeholder: "请在此输入实训课程的学习须知", imageUpload : true, imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp", "JPG", "JPEG", "GIF", "PNG", "BMP", "WEBP"], - imageUploadURL : "<%= upload_with_markdown_path(:container_id => @subject.id, :container_type => @subject.class) %>" //url + imageUploadURL : "<%= upload_with_markdown_path(:container_id => @subject.id, :container_type => 'MarkDown') %>" //url }); md_elocalStorage(shixun_propaedeutics, "subject_notes_<%= User.current.id %>", "notes"); diff --git a/app/views/subjects/_new_shixun_list.html.erb b/app/views/subjects/_new_shixun_list.html.erb index 52e1ef65..17aafc08 100644 --- a/app/views/subjects/_new_shixun_list.html.erb +++ b/app/views/subjects/_new_shixun_list.html.erb @@ -25,8 +25,10 @@ <% else %>

没有实训数据可以选择

-

- 立即新建 + 立即新建 +

+ 取消 +
<% end %> diff --git a/db/migrate/20190314080805_create_shixun_student_works.rb b/db/migrate/20190314080805_create_shixun_student_works.rb new file mode 100644 index 00000000..07a460ac --- /dev/null +++ b/db/migrate/20190314080805_create_shixun_student_works.rb @@ -0,0 +1,99 @@ +# encoding: utf-8 +class CreateShixunStudentWorks < ActiveRecord::Migration + DCODES = %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) + + def down_generate_identifier type + if type == "game" + code = DCODES.sample(12).join + return down_generate_identifier(type) if Game.where(identifier: code).present? + elsif type == "myshixun" + code = DCODES.sample(10).join + return down_generate_identifier(type) if Myshixun.where(identifier: code).present? + end + code + end + + def up + works = StudentWork.where("myshixun_id != 0 and myshixun_id not in (select id from myshixuns) and (work_score is null or work_score = 0)") + works.update_all(:myshixun_id => 0, :work_status => 0, :work_score => nil, :final_score => nil, + :cost_time => 0, :update_time => nil, :compelete_status => 0, :commit_time => nil) + + shixun_works = StudentWork.where("myshixun_id != 0 and myshixun_id not in (select id from myshixuns) and work_score > 0") + shixun_works.each do |work| + shixun = work.homework_common.try(:homework_commons_shixuns).try(:shixun) + user = work.user + begin + ActiveRecord::Base.transaction do + if shixun.present? && user.present? + 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 + + 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" + + 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| + if work_score > 1 + games = myshixun.games.where(:challenge_id => setting.challenge_id).first + games.update_attributes(:status => 2, :end_time => Time.now, :final_score => setting.challenge.score) + work_score -= setting.score + end + end + work.update_column("myshixun_id", myshixun.id) + else + work.update_attributes(:myshixun_id => 0, :work_status => 0) + end + end + end + rescue Exception => e + puts ("###failed to exec shixun: current task id is #{e}") + # g.delete_project(gshixun.id) if gshixun.try(:id).present? + raise ActiveRecord::Rollback + end + end + end + + def down + end +end diff --git a/db/migrate/20190314080807_create_shixun_student_works.rb b/db/migrate/20190314080807_create_shixun_student_works.rb deleted file mode 100644 index 83bac6c7..00000000 --- a/db/migrate/20190314080807_create_shixun_student_works.rb +++ /dev/null @@ -1,75 +0,0 @@ -class CreateShixunStudentWorks < ActiveRecord::Migration - def up - ActiveRecord::Base.transaction do - begin - works = StudentWork.where("myshixun_id != 0 and myshixun_id not in (select id from myshixuns) and (work_score is null or work_score = 0)") - works.update_all(:myshixun_id => 0, :work_status => 0, :work_score => nil, :final_score => nil, - :cost_time => 0, :update_time => nil, :compelete_status => 0, :commit_time => nil) - - shixun_works = StudentWork.where("myshixun_id != 0 and myshixun_id not in (select id from myshixuns) and work_score > 0") - shixun_works.each do |work| - 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'] - 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) - - rep_url = Base64.urlsafe_encode64(gitlab_url shixun) # 注意:educoder为默认给实训创建版本库的用户,如果换成别的用户,名字要相应的修改 - uri = "#{shixun_tomcat}/bridge/game/openGameInstance" - params = {tpiID: "#{myshixun.id}", tpmGitURL:rep_url, tpiRepoName: gshixun.try(:name)} - logger.info("openGameInstance params is #{params}") - res = uri_exec uri, params - 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 - work_score = work.final_score - work.homework_common.homework_challenge_settings.each do |setting| - if work_score > 1 - games = myshixun.games.where(:challenge_id => setting.challenge_id).first - games.update_attributes(:status => 2, :end_time => Time.now, :final_score => setting.challenge.score) - work_score -= setting.score - end - end - work.update_column("myshixun_id", myshixun.id) - end - end - end - rescue Exception => e - puts ("###failed to exec shixun: current task id is #{e}") - g.delete_project(gshixun.id) if gshixun.try(:id).present? - raise ActiveRecord::Rollback - end - end - end - - def down - end -end diff --git a/public/images/educoder/path.jpg b/public/images/educoder/path.jpg index 19b1627b..a1d70644 100644 Binary files a/public/images/educoder/path.jpg and b/public/images/educoder/path.jpg differ diff --git a/public/stylesheets/educoder/edu-main.css b/public/stylesheets/educoder/edu-main.css index 4e495353..d814abd5 100644 --- a/public/stylesheets/educoder/edu-main.css +++ b/public/stylesheets/educoder/edu-main.css @@ -859,4 +859,10 @@ html>body #ajax-indicator { position: fixed; } .ListTablecheckbox{ left: 42px; top: -1px !important; -} \ No newline at end of file +} + +.pathhidnmodel{ + position: absolute; + margin-top: 60px; + margin-left: -26px; +}