remove moderator status posts from best feed

This commit is contained in:
Sam 2013-05-22 15:04:30 +10:00
parent 519bec6b04
commit c4d8085fc5
4 changed files with 11 additions and 4 deletions

View File

@ -28,7 +28,7 @@ class TopicsController < ApplicationController
opts = params.slice(:username_filters, :best_of, :page, :post_number, :posts_before, :posts_after, :best) opts = params.slice(:username_filters, :best_of, :page, :post_number, :posts_before, :posts_after, :best)
@topic_view = TopicView.new(params[:id] || params[:topic_id], current_user, opts) @topic_view = TopicView.new(params[:id] || params[:topic_id], current_user, opts)
raise Discourse::NotFound unless @topic_view.posts.present? || (request.format && request.format.json?) raise Discourse::NotFound if @topic_view.posts.blank? && !(opts[:best].to_i > 0)
anonymous_etag(@topic_view.topic) do anonymous_etag(@topic_view.topic) do
redirect_to_correct_topic && return if slugs_do_not_match redirect_to_correct_topic && return if slugs_do_not_match

View File

@ -177,6 +177,7 @@ class TopicView
@index_offset = 0 @index_offset = 0
@posts = @filtered_posts.order('percent_rank asc, sort_order asc').where("post_number > 1") @posts = @filtered_posts.order('percent_rank asc, sort_order asc').where("post_number > 1")
@posts = @posts.includes(:reply_to_user).includes(:topic).joins(:user).limit(max) @posts = @posts.includes(:reply_to_user).includes(:topic).joins(:user).limit(max)
@posts = @posts.where('posts.post_type <> ?', Post.types[:moderator_action])
@posts = @posts.to_a @posts = @posts.to_a
@posts.sort!{|a,b| a.post_number <=> b.post_number} @posts.sort!{|a,b| a.post_number <=> b.post_number}
@posts @posts

View File

@ -23,11 +23,19 @@ describe TopicView do
let!(:p2) { Fabricate(:post, topic: topic, user: coding_horror, percent_rank: 0.5 )} let!(:p2) { Fabricate(:post, topic: topic, user: coding_horror, percent_rank: 0.5 )}
let!(:p3) { Fabricate(:post, topic: topic, user: first_poster, percent_rank: 0 )} let!(:p3) { Fabricate(:post, topic: topic, user: first_poster, percent_rank: 0 )}
it "it can the best 2 responses" do it "it can find the best responses" do
best2 = TopicView.new(topic.id, nil, best: 2) best2 = TopicView.new(topic.id, nil, best: 2)
best2.posts.count.should == 2 best2.posts.count.should == 2
best2.posts[0].id.should == p2.id best2.posts[0].id.should == p2.id
best2.posts[1].id.should == p3.id best2.posts[1].id.should == p3.id
topic.update_status('closed', true, Fabricate(:admin))
topic.posts.count.should == 4
# should not get the status post
best = TopicView.new(topic.id, nil, best: 99)
best.posts.count.should == 2
end end

View File

@ -2,8 +2,6 @@ require 'spec_helper'
describe TopicsController do describe TopicsController do
context 'move_posts' do context 'move_posts' do
it 'needs you to be logged in' do it 'needs you to be logged in' do
lambda { xhr :post, :move_posts, topic_id: 111, title: 'blah', post_ids: [1,2,3] }.should raise_error(Discourse::NotLoggedIn) lambda { xhr :post, :move_posts, topic_id: 111, title: 'blah', post_ids: [1,2,3] }.should raise_error(Discourse::NotLoggedIn)