diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index a51dccb6f..ef648f6b3 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -37,7 +37,8 @@ class GamesController < ApplicationController # 上一关、下一关 prev_game = @game.prev_of_current_game(@shixun.id, @game.myshixun_id, game_challenge.position) - next_game = @game.next_of_current_game(@shixun.id, @game.myshixun_id, game_challenge.position) + #next_game = @game.next_of_current_game(@shixun.id, @game.myshixun_id, game_challenge.position) + next_game = user_next_game(@shixun, game_challenge, @game, @identity) # 关卡点赞数, praise_or_tread = 1则表示赞过 praise_count = game_challenge.praises_count @@ -962,4 +963,14 @@ class GamesController < ApplicationController @identity = current_user.game_identity(@game) raise Educoder::TipException.new(403, "..") if @identity > User::EDU_GAME_MANAGER end + # identity用户身份 + def user_next_game(shixun, challenge, game, identity) + next_game = game.next_of_current_game(shixun.id, game.myshixun_id, challenge.position) + # 实训允许跳关 、 当前关卡已经通关、 用户是已认证的老师以上权限的人,允许跳关 + if shixun.task_pass || game.status == 2 || identity >= User::EDU_CERTIFICATION_TEACHER + next_game + else + nil + end + end end diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index cdeca4871..6fe3e4be8 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -7,9 +7,9 @@ class MyshixunsController < ApplicationController ## TPI关卡列表 def challenges # @challenges = Challenge.where(shixun_id: params[:shixun_id]) - - @shixun_status = @myshixun.shixun.status + @shixun = @myshixun.shixun @games = @myshixun.games.includes(:challenge).reorder("challenges.position") + @identity = current_user.game_identity(@games.first) end diff --git a/app/helpers/myshixuns_helper.rb b/app/helpers/myshixuns_helper.rb index 650f32f40..b7843612d 100644 --- a/app/helpers/myshixuns_helper.rb +++ b/app/helpers/myshixuns_helper.rb @@ -1,2 +1,14 @@ module MyshixunsHelper + + # 获取tpi的identifier, + # identity表示用户关卡的身份 + # task_pass: 实训是否允许跳关 + def get_game_identifier task_pass, game, game_identity + # 允许跳关、 关卡已经开启、 用户是已认证老师以上的身份 + if task_pass || game.status != 3 || game_identity >= User::EDU_CERTIFICATION_TEACHER + game.identifier + else + nil + end + end end diff --git a/app/models/shixun.rb b/app/models/shixun.rb index e35f9f1a6..82f689e3f 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -4,6 +4,7 @@ class Shixun < ApplicationRecord # status: 0:编辑 1:申请发布 2:正式发布 3:关闭 -1:软删除 # hide_code: 隐藏代码窗口 # code_hidden: 隐藏代码目录 + # task_pass: 跳关 has_many :challenges, dependent: :destroy has_many :challenge_tags, through: :challenges has_many :myshixuns, :dependent => :destroy diff --git a/app/views/myshixuns/challenges.json.jbuilder b/app/views/myshixuns/challenges.json.jbuilder index 802c2b561..0be94d9fd 100644 --- a/app/views/myshixuns/challenges.json.jbuilder +++ b/app/views/myshixuns/challenges.json.jbuilder @@ -3,7 +3,7 @@ json.array! @games do |game| json.partial! 'challenges/challenge', locals: { challenge: challenge } json.status game.status json.star game.star - json.identifier game.identifier - json.get_gold game.user_get_gold_and_experience(@shixun_status, challenge)[0] - json.get_experience game.user_get_gold_and_experience(@shixun_status, challenge)[1] + json.identifier get_game_identifier(@shixun.task_pass, game, @identity) + json.get_gold game.user_get_gold_and_experience(@shixun.status, challenge)[0] + json.get_experience game.user_get_gold_and_experience(@shixun.status, challenge)[1] end \ No newline at end of file