diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index d6b9d3c7f..941806f25 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -359,7 +359,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| diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index eae04490a..25fa1425b 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(:statu) != 2) + false + else + true + end + end + + # 适用与已经用url_safe编码后,回调字符串形式 def tran_base64_decode64 str if str.blank? 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/views/games/_code_actions.html.erb b/app/views/games/_code_actions.html.erb index 8a259de90..7588fb86a 100644 --- a/app/views/games/_code_actions.html.erb +++ b/app/views/games/_code_actions.html.erb @@ -14,23 +14,20 @@