已认证的老师能够跳关

dev_forum
daiao 5 years ago
parent b9ba6da862
commit 1738703bda

@ -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

@ -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

@ -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

@ -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

@ -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
Loading…
Cancel
Save