diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 7784f68a7..3b660b434 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -151,8 +151,7 @@ class ChallengesController < ApplicationController end end end - - redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab]) + redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab]), notice: 'Succeed' rescue Exception => e flash[:error] = "#{e.message}" redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab]) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index a0faf463a..8ed9cfc18 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -49,17 +49,17 @@ class CoursesController < ApplicationController @syllabuses_num = Course.where("is_end = #{@is_end} and is_delete = 0").count #@syllabus_count = all_syllabuses.count # 我创建的课堂 - create_syllabuses = Course.where(:tea_id => @user.id).where("is_end = #{@is_end} and is_delete = 0 and name like '%#{@search}%'") + create_syllabuses = Course.where(:tea_id => @user.id) # 我参与的课堂 - join_syllabuses = @user.courses.where("is_end = #{@is_end} and is_delete = 0 and tea_id != #{@user.id} and name like '%#{@search}%'") + join_syllabuses = @user.courses.where("is_delete = 0 and tea_id != #{@user.id}") @join_syllabuses_count = join_syllabuses.count @create_syllabuses_count = create_syllabuses.count # 页面筛选的课程 if @select == "create" - @syllabuses = create_syllabuses + @syllabuses = create_syllabuses.where("is_end = #{@is_end} and is_delete = 0 and name like '%#{@search}%'") elsif @select == "join" - @syllabuses = join_syllabuses + @syllabuses = join_syllabuses.where("is_end = #{@is_end} and is_delete = 0 and tea_id != #{@user.id} and name like '%#{@search}%'") elsif @select == "end" # 归档的课堂 end_syllabuses = Course.where("is_end = #{@is_end} and name like '%#{@search}%'") diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index d6b9d3c7f..796a3e72b 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -3,7 +3,7 @@ class GamesController < ApplicationController layout "base_myshixun" skip_before_filter :verify_authenticity_token, :only => [:file_update] before_filter :find_myshixun, :only => [:index] - before_filter :find_game, :only => [:show, :game_build, :entry,:next_step, :outputs_show, :file_edit, :file_update, + before_filter :find_game, :only => [:show, :game_build, :entry,:next_step, :outputs_show, :file_edit, :file_update, :get_waiting_time, :game_status, :change_status, :answer, :minus_score, :refresh_game_list, :reset_original_code, :reset_new_code, :evaluating_choice] before_filter :find_repository, :only => [:show, :entry, :file_edit, :file_update, :reset_original_code, :reset_new_code, :html_show] before_filter :allowd_manager @@ -147,6 +147,25 @@ class GamesController < ApplicationController end end + # 获取评测的等待的时间 + # res['waitNum'] 评测等待人数 + # res['waitingTime'] 评测等待时间 + # res['onRun'] 0 表示在等待中 1 表示可执行 + def get_waiting_time + shixun_tomcat = Redmine::Configuration['shixun_tomcat'] + uri = "#{shixun_tomcat}/bridge/game/getWaitingTime" + params = {:tpiID => "#{@myshixun.id}"} + res = uri_exec uri, params + if (res && res['code'] != 0) + @message = "实训云平台繁忙(繁忙等级:94)" + raise("实训云平台繁忙(繁忙等级:94)") + end + render :json => {:result => "success", :onRun => res['onRun'], :waitNum => res['waitNum'], :waitingTime => res['waitingTime'] } + #render :json => {:result => "success", :onRun => 1, :waitNum => 12, :waitingTime => 546 } + rescue Exception => e + render :json => {:result => "failed"} + end + # status 0: 未提交测评或者提交测评失败后报错;1:中间状态还没返回值;2:返回值并成功 # resubmit 唯一随机码,为了区分每一次重新评测结果 CODES = %W(1 2 3 4 5 6 7 8 9 A B C D E F G H J K L N M O P Q R S T U V W X Y Z) @@ -359,7 +378,9 @@ class GamesController < ApplicationController # 自动推送下一个任务 def next_step - render_403 if @game.status != 2 + unless show_next_stage?(@game, @myshixun.shixun.try(:status)) + render_403 + end next_game = @game.next_game next_game.update_attributes(:status => 0, :open_time => Time.now) if next_game.status == 3 respond_to do |format| @@ -548,7 +569,10 @@ class GamesController < ApplicationController # 判断成员是否允许查看 def allowd_view - render_403 if (@game.status == 3 && User.current.id != @myshixun.shixun.try(:user_id)) + if @myshixun.shixun.try(:status) == 2 && @game.status == 3 && User.current.id != @myshixun.shixun.try(:user_id) + render_403 + end + # render_403 if (@game.status == 3 && User.current.id != @myshixun.shixun.try(:user_id)) end def find__shixun_language diff --git a/app/controllers/iframes_controller.rb b/app/controllers/iframes_controller.rb index 9fed6add6..2d1091219 100644 --- a/app/controllers/iframes_controller.rb +++ b/app/controllers/iframes_controller.rb @@ -1,5 +1,7 @@ class IframesController < ApplicationController layout false + skip_before_filter :verify_authenticity_token, :only => [:html_content] + def show render :layout => false end diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index b321cd469..4bdf16e72 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -185,7 +185,7 @@ class ManagementsController < ApplicationController end if params[:support_shixuns] - @major = @major.where(:support_shixuns => params[:support_shixuns].to_i, :major_level => 2) + @major = @major.where(:support_shixuns => params[:support_shixuns].to_i,:major_level=> 2) end @major = @major.order("created_at #{@sx_order}") @@ -652,6 +652,7 @@ end def class_shixuns @menu_type = 4 @sub_type = 1 + @sx_order = params[:sx_order].blank? ? "desc" : params[:sx_order] @edit_class_sx_num=Subject.where(:status => 0).count @audit_class_sx_num=Subject.where(:status => 1).count @publish_class_sx_num=Subject.where(:status => 2).count @@ -680,6 +681,8 @@ end user_exs = UserExtensions.where(:user_id => @c_shixuns.map(&:user_id)) @schools = School.where(:id => user_exs.map(&:school_id)) end + @c_shixuns = @c_shixuns.order("created_at #{@sx_order}") + @c_shixuns_count = @c_shixuns.count limit = 20 @c_shixuns_pages = Paginator.new @c_shixuns_count, limit, params['page'] || 1 @@ -700,6 +703,7 @@ end def class_publish_shixuns @menu_type = 4 @sub_type = 2 + @sx_order = params[:sx_order].blank? ? "desc" : params[:sx_order] search = params[:search] # 搜索字 keyword = params[:keyword].blank? ? "u_name" : params[:keyword] # 根据姓名/课程名搜索 if params[:school_id] && params[:school_id] != '0' @@ -719,7 +723,7 @@ end user_exs = UserExtensions.where(:user_id => @c_shixuns.map(&:user_id)) @schools = School.where(:id => user_exs.map(&:school_id)) end - @c_shixuns = @c_shixuns.order("created_at desc") + @c_shixuns = @c_shixuns.order("created_at #{@sx_order}") @c_shixuns_count = @c_shixuns.count limit = 20 @c_shixuns_pages = Paginator.new @c_shixuns_count, limit, params['page'] || 1 @@ -898,35 +902,56 @@ end =end if params[:member_ids] && params[:trial_whether] == "trial_agree" - params[:member_ids].each do |member| - aUser = ApplyAction.where(:user_id => member, :container_type => "TrialAuthorization") - if aUser.blank? - ApplyAction.create(:user_id => member, :container_type => "TrialAuthorization", :status => 1) - else - aUser.update_all(:status => 1) - end - end + aUser = User.where(:id => params[:member_ids]) + aUser.update_all(:certification => 1) + apply_user = ApplyAction.where(:user_id => params[:member_ids]) + apply_user.update_all(:status => 1) unless apply_user.blank? elsif params[:member_ids] && params[:trial_whether] == "trial_cancel" - ApplyAction.where(:user_id => params[:member_ids], :container_type => "TrialAuthorization").update_all(:status => 2) + User.where(:id => params[:member_ids]).update_all(:certification => 0) + apply_user = ApplyAction.where(:user_id => params[:member_ids]) + apply_user.update_all(:status => 2) unless apply_user.blank? end - if params[:member_ids] && (params[:occupation] == "occupation_agree" || params[:realname] == "realname_agree") + if params[:member_ids] && params[:occupation] == "occupation_agree" + User.where(:id => params[:member_ids]).update_all(:professional_certification => true) + apply_user = ApplyUserAuthentication.where(:user_id => params[:member_ids], :auth_type => 2) + unless apply_user.blank? + apply_user.update_all(:status => 1) + end + elsif params[:member_ids] && params[:realname] == "realname_agree" User.where(:id => params[:member_ids]).update_all(:authentication => true) - elsif params[:member_ids] && (params[:occupation] == "occupation_agree" || params[:realname] == "realname_cancel") + apply_user = ApplyUserAuthentication.where(:user_id => params[:member_ids], :auth_type => 1) + unless apply_user.blank? + apply_user.update_all(:status => 1) + end + elsif params[:member_ids] && params[:occupation] == "occupation_cancel" + User.where(:id => params[:member_ids]).update_all(:professional_certification => false) + apply_user = ApplyUserAuthentication.where(:user_id => params[:member_ids], :auth_type => 2) + unless apply_user.blank? + apply_user.update_all(:status => 2) + end + elsif params[:member_ids] && params[:realname] == "realname_cancel" User.where(:id => params[:member_ids]).update_all(:authentication => false) + apply_user = ApplyUserAuthentication.where(:user_id => params[:member_ids], :auth_type => 1) + unless apply_user.blank? + apply_user.update_all(:status => 2) + end end if params[:trial] == "-1" apply = ApplyAction.where(:container_type => "TrialAuthorization") apply_id = apply.blank? ? -1 : "(" + apply.map{|a| a.user_id}.join(",") + ")" - apply_user_id = User.where("id not in #{apply_id} and status = 1").all + apply_user_id = User.where("id not in #{apply_id} and status = 1 and certification = 0").all apply_user_id = apply_user_id.blank? ? [-1] : apply_user_id.map{|a| a.id}.split(",")[0] elsif params[:trial] == "-2" apply_user_id = User.where(:status => 1).all apply_user_id = apply_user_id.blank? ? [-1] : apply_user_id.map{|a| a.id}.split(",")[0] - else - apply = ApplyAction.where(:status => params[:trial]) + elsif params[:trial] == "0" + apply = ApplyAction.where(:status => 0) apply_user_id = apply.blank? ? [-1] : apply.map{|a| a.user_id}.split(",")[0] + else + apply_user_id = User.where(:status => 1, :certification => params[:trial]).all + apply_user_id = apply_user_id.blank? ? [-1] : apply_user_id.map{|a| a.id}.split(",")[0] end if params[:school] == "" @@ -1031,6 +1056,7 @@ end end end apply_action.update_attributes(:status => (params[:type] == "1" ? 2 : 1), :reason => params[:reject_reason], :dealer_id => User.current.id) + User.where(:id => apply_action.user_id).first.update_attributes(:certification => (params[:type] == "1" ? 2 : 1)) user_id = User.find_by_sql("select id from users where concat(lastname,firstname) like '%#{search}%'") @authorizations = ApplyAction.where(:container_type => "TrialAuthorization", :status => 0, :user_id => user_id).includes(:user) @autu_count = @authorizations.count @@ -1155,6 +1181,7 @@ end format.html end end + # 课程实训发布审批 def deal_subject_authorization apply_action = ApplyAction.find(params[:apply_id]) @@ -1180,6 +1207,7 @@ end format.js end end + # 项目实训发布审批 def deal_shixun_authorization apply_action = ApplyAction.find(params[:apply_id]) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 2fd647c71..e1d4fe631 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -647,10 +647,10 @@ class ShixunsController < ApplicationController # 实训行为操作 def operation + @is_subject = params[:is_subject] @myshixun = Myshixun.where(:id => params[:myshixun_id]).first @is_modify = ShixunModify.where(:myshixun_id => params[:myshixun_id], :shixun_id => @shixun.try(:id), :status => 1).first @mail = User.current.mail.blank? - end private diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index c0182bf42..4431c4767 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -668,7 +668,8 @@ class UsersController < ApplicationController @offset ||= @course_result_pages.offset @course_result = paginateHelper @course_result, @limit else - @shixuns_result = Shixun.where(:status => [2,3]).where("name like ?", "%#{@search}%").reorder("created_at desc") + # @shixuns_result = Shixun.where(:status => [2,3]).where("name like ?", "%#{@search}%").reorder("created_at desc") + @shixuns_result = Shixun.where("name like ?", "%#{@search}%").reorder("created_at desc") @shixuns_result_count = @shixuns_result.count @shixun_pages = Paginator.new @shixuns_result_count, @limit, params['page'] || 1 @offset ||= @shixun_pages.offset diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e0b2604cb..1d9ab8c00 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -33,6 +33,18 @@ module ApplicationHelper extend Forwardable def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter + # 定义当前关卡是否有权开启下一关 + # :实训若发布了,必须通过当前关卡才能查看下一关 + # :未发布的实训,除了最后一关,其它的关卡都可以进入下一关 + def show_next_stage?(game, shixun_status) + if game.is_final_game? || ([2,3].include?(shixun_status.to_i) && game.try(:status) != 2) + false + else + true + end + end + + # 适用与已经用url_safe编码后,回调字符串形式 def tran_base64_decode64 str if str.blank? @@ -142,7 +154,7 @@ module ApplicationHelper # if params[:action] == "on_search" || params[:action] == "apply_trail" # 之所以这样处理是为了避开account页面ajax加载 # return true # end - authentication = ApplyAction.where(:user_id => User.current.id, :status => 1).first + authentication = User.where(:id => User.current.id, :certification => 1).first user_identity = User.current.try(:user_extensions).try(:identity) if user_identity.blank? || authentication.blank? redirect_to my_account_path @@ -3026,12 +3038,15 @@ module ApplicationHelper end end - def identity_authentication_status status - case status - when nil - "未授权" + def identity_authentication_status user + authorization = ApplyAction.where(:user_id => user, :container_type => "TrialAuthorization").last + case user.try(:certification) when 0 - "处理中" + if authorization.try(:status) == 0 + "处理中" + else + "未授权" + end when 1 "已授权" when 2 diff --git a/app/models/game.rb b/app/models/game.rb index 4b97fbbde..03d1d58ae 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -52,4 +52,9 @@ class Game < ActiveRecord::Base output = outputs.blank? ? nil : outputs.first return output end + + def is_final_game? + challenge = self.challenge + challenge.try(:position).to_i == challenge.shixun.challenges.count ? true : false + end end diff --git a/app/models/shixun.rb b/app/models/shixun.rb index d7ae9ebc0..40c2237f0 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -5,6 +5,7 @@ # 85:challenge创建的时候Jenkins处理异常;86:实训评测失败,jenkins返回错误结果; 87:版本库删除异常;88:点击评测失败,没返回数据;89:重置链接jenkins返回失败 # 90: 更新公共测试用例失败,返回code非0;91:实训有改动,评测的时候初始化数据,返回数据code非0;92:webssh开启失败,接口getConnectInfo返回code值非0 # 93: 实训断开连接失败,接口deleteSSH返回code值非0 +# 94: 获取评测等待时间失败,接口getWaitingTime返回code值为非0 # 116:challenge创建关卡的时候返回结果错误 # class Shixun < ActiveRecord::Base @@ -23,6 +24,7 @@ class Shixun < ActiveRecord::Base has_many :shixun_major_courses, :dependent => :destroy has_and_belongs_to_many :homework_commons has_many :discusses, :as => :dis, :dependent => :destroy + has_many :shixun_ports scope :visible, lambda{where(status: [2,3])} diff --git a/app/models/shixun_port.rb b/app/models/shixun_port.rb new file mode 100644 index 000000000..d7e04b397 --- /dev/null +++ b/app/models/shixun_port.rb @@ -0,0 +1,4 @@ +class ShixunPort < ActiveRecord::Base + attr_accessible :port, :shixun_id + belongs_to :shixun +end diff --git a/app/views/account/user_join.html.erb b/app/views/account/user_join.html.erb index 14399b9d9..1b32e71b5 100644 --- a/app/views/account/user_join.html.erb +++ b/app/views/account/user_join.html.erb @@ -35,7 +35,7 @@
-