From d21c46339bb23595d32b04de9da259e762a56491 Mon Sep 17 00:00:00 2001 From: jasder Date: Wed, 26 Jun 2019 09:58:59 +0800 Subject: [PATCH] ADD competition some eelated featrue --- app/controllers/messages_controller.rb | 8 +++++++- app/models/message.rb | 2 +- app/views/messages/reply_list.json.jbuilder | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 60a1c171c..33f4e5bfb 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -43,9 +43,15 @@ class MessagesController < ApplicationController @page_size = params[:page_size] || 10 @current_user = current_user || nil - @messages = @message.children.preload_messages + @messages = @message.children.preload_messages.includes(:message_detail, :praise_treads) @messages = @messages.ordered(sort: 1) unless @message.parent_id.nil? + @user_course_identity = current_user.course_identity(@message.board.course) + case @user_course_identity + when 5 || 6 || 7 + @messages = @messages.visible + end + @messages = @messages.page(@page).per(@page_size) end diff --git a/app/models/message.rb b/app/models/message.rb index c3b3bca40..6b41cdd95 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -18,7 +18,7 @@ class Message < ApplicationRecord scope :root_nodes, -> { where("parent_id IS NULL") } #判断该信息是帖子还是回复。null为发布的帖子 scope :reply_nodes, -> { where("parent_id IS NOT NULL") } - scope :visible, -> { where(is_hidden: false)} + scope :visible, -> { where(is_hidden: false) } scope :by_user, ->(user) { visible if user.nil? || !user.admin? } scope :preload_messages, -> { includes(:author, :message_detail) } scope :short, -> { select(:id, :subject, :created_on, :replies_count, :visits, :sticky, :praises_count) } diff --git a/app/views/messages/reply_list.json.jbuilder b/app/views/messages/reply_list.json.jbuilder index 2b7ef7178..b5c1ce256 100644 --- a/app/views/messages/reply_list.json.jbuilder +++ b/app/views/messages/reply_list.json.jbuilder @@ -1,6 +1,6 @@ json.partial! "commons/success" json.data do - json.user_course_identity @current_user.course_identity(@message.board.course) + json.user_course_identity @user_course_identity json.id @message.id json.total_count @messages.total_count json.total_replies_count @message.total_replies_count