From 94daf8d429922fae5c761eaf86e1b431e556497e Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 27 Jun 2019 14:56:28 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=AF=84=E8=AE=BA=E9=9A=90=E8=97=8F?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E5=88=B0=E6=96=B0=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/discusses_controller.rb | 15 ++++++++++++--- app/models/discuss.rb | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/controllers/discusses_controller.rb b/app/controllers/discusses_controller.rb index 6e9c1427e..abedca8ba 100644 --- a/app/controllers/discusses_controller.rb +++ b/app/controllers/discusses_controller.rb @@ -7,9 +7,18 @@ class DiscussesController < ApplicationController page = params[:page].to_i offset = page * LIMIT # 总数,分页使用 - @disscuss_count = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s, :root_id => nil).count - @discusses = Discuss.limit(LIMIT).where(:dis_id => @container.id, :dis_type => @container.class.to_s, :root_id => nil). - includes(:user, :praise_tread).offset(offset) + if current_user.admin? + @disscuss_count = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s, :root_id => nil).count + @discusses = Discuss.limit(LIMIT).where(:dis_id => dis_id, :dis_type => dis_type, + :root_id => nil).includes(:user, :praise_tread).offset(offset) + else + disscusses = Discuss.where("dis_id = :dis_id and dis_type = :dis_type and root_id is null and + (hidden = :hidden or user_id = :user_id)", + {dis_id: dis_id, dis_type: dis_type, hidden: false, user_id: current_user.id}) + @disscuss_count = disscusses.count + @discusses = disscusses.limit(LIMIT).includes(:user, :praise_tread).offset(offset) + end + @current_user = current_user end diff --git a/app/models/discuss.rb b/app/models/discuss.rb index 602813e66..c1b08718c 100644 --- a/app/models/discuss.rb +++ b/app/models/discuss.rb @@ -36,7 +36,7 @@ class Discuss < ApplicationRecord def contents(shixun, user) return content unless hidden? - shixun.has_manager?(user) ? content : '违规评论已被屏蔽!' + shixun.has_manager?(user) ? content : '' end private From cea5187439158c5452463cc840e93d3e17505fad Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 27 Jun 2019 14:59:19 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E6=94=B9=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/discusses_controller.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/discusses_controller.rb b/app/controllers/discusses_controller.rb index abedca8ba..93cf90780 100644 --- a/app/controllers/discusses_controller.rb +++ b/app/controllers/discusses_controller.rb @@ -32,8 +32,10 @@ class DiscussesController < ApplicationController def create begin - @discuss = Discuss.create!(:dis_id => params[:container_id], :dis_type => params[:container_type], :content => params[:content].gsub(" \;", "").strip, - :user_id => current_user.id, :praise_count => 0, :position => params[:position], :challenge_id => params[:challenge_id]) + @discuss = Discuss.create!(:dis_id => params[:container_id], :dis_type => params[:container_type], + :content => params[:content].gsub(" \;", "").strip, :user_id => current_user.id, + :praise_count => 0, :position => params[:position], :challenge_id => params[:challenge_id], + :hidden => current_user.admin?) rescue Exception => e uid_logger_error("create discuss failed : #{e.message}") raise Educoder::TipException.new("评论异常")