From 8cce3e27ba4a63693627e1ca233dab05280e8217 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 29 Apr 2019 16:57:27 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9A=90=E8=97=8F=E5=92=8C=E5=B7=B2=E7=BB=8F?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=9A=84=E5=AE=9E=E8=AE=AD=EF=BC=8C=E4=B8=8D?= =?UTF-8?q?=E8=83=BD=E9=80=9A=E8=BF=87=E8=BF=9E=E6=8E=A5=E8=AE=BF=E9=97=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 2 +- app/models/shixun.rb | 7 ++++++- app/services/games_service.rb | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 685f9f74..df1da6ca 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -467,7 +467,7 @@ class ChallengesController < ApplicationController render_404 return else - if (@shixun.status == 0 && !User.current.manager_of_shixun?(@shixun)) || @shixun.status == -1 + if (@shixun.status == 0 && !User.current.manager_of_shixun?(@shixun)) || (!@shixun.operable? && !User.current.admin?) render_403 return end diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 54882be1..c7d0460a 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -62,13 +62,18 @@ class Shixun < ActiveRecord::Base include ApplicationHelper has_many :tidings, :as => :container, :dependent => :destroy - scope :visible, -> { where(status: -1) } + #scope :visible, -> { where(status: -1) } after_create :send_tiding def should_compile? self.mirror_repositories.published_main_mirror.first.try(:should_compile) end + # 可供使用的实训 + def operable? + self.status != -1 && !self.hidden + end + def is_published? self.status > 1 ? true : false end diff --git a/app/services/games_service.rb b/app/services/games_service.rb index bddb03b7..f172edbd 100644 --- a/app/services/games_service.rb +++ b/app/services/games_service.rb @@ -17,7 +17,8 @@ class GamesService myshixun = Myshixun.min.find(game.myshixun_id) shixun = Shixun.min.find(myshixun.shixun_id) - unless (myshixun.user_id == current_user.id || current_user.admin? || current_user.business? || current_user.id == shixun.try(:user_id) || current_user.is_certification_teacher) + unless ((myshixun.user_id == current_user.id || current_user.business? || current_user.id == shixun.try(:user_id) || + current_user.is_certification_teacher) && (shixun.operable?)) || current_user.admin? return{:status => 403} end game_challenge = Challenge.min.find(game.challenge_id)