New mode for Wordpress: Filter ONLY posts liked by moderators
This commit is contained in:
parent
58d082d01e
commit
6cd6484b5e
|
@ -56,7 +56,7 @@ class TopicsController < ApplicationController
|
|||
def wordpress
|
||||
params.require(:best)
|
||||
params.require(:topic_id)
|
||||
params.permit(:min_trust_level, :min_score, :min_replies, :bypass_trust_level_score)
|
||||
params.permit(:min_trust_level, :min_score, :min_replies, :bypass_trust_level_score, :only_moderator_liked)
|
||||
|
||||
@topic_view = TopicView.new(
|
||||
params[:topic_id],
|
||||
|
@ -65,7 +65,8 @@ class TopicsController < ApplicationController
|
|||
min_trust_level: params[:min_trust_level].nil? ? 1 : params[:min_trust_level].to_i,
|
||||
min_score: params[:min_score].to_i,
|
||||
min_replies: params[:min_replies].to_i,
|
||||
bypass_trust_level_score: params[:bypass_trust_level_score].to_i # safe cause 0 means ignore
|
||||
bypass_trust_level_score: params[:bypass_trust_level_score].to_i, # safe cause 0 means ignore
|
||||
only_moderator_liked: params[:only_moderator_liked].to_s == "true"
|
||||
)
|
||||
|
||||
anonymous_etag(@topic_view.topic) do
|
||||
|
|
|
@ -199,6 +199,7 @@ Discourse::Application.routes.draw do
|
|||
|
||||
# Topic routes
|
||||
get 't/:slug/:topic_id/wordpress' => 'topics#wordpress', constraints: {topic_id: /\d+/}
|
||||
get 't/:slug/:topic_id/moderator-liked' => 'topics#moderator_liked', constraints: {topic_id: /\d+/}
|
||||
get 't/:topic_id/wordpress' => 'topics#wordpress', constraints: {topic_id: /\d+/}
|
||||
get 't/:slug/:topic_id/best_of' => 'topics#show', defaults: {best_of: true}, constraints: {topic_id: /\d+/, post_number: /\d+/}
|
||||
get 't/:topic_id/best_of' => 'topics#show', constraints: {topic_id: /\d+/, post_number: /\d+/}
|
||||
|
|
|
@ -161,12 +161,9 @@ class TopicView
|
|||
return
|
||||
end
|
||||
|
||||
@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)
|
||||
|
||||
|
||||
min_trust_level = opts[:min_trust_level]
|
||||
if min_trust_level && min_trust_level > 0
|
||||
|
||||
|
@ -187,6 +184,11 @@ class TopicView
|
|||
@posts = @posts.where('posts.score >= ?', min_score)
|
||||
end
|
||||
|
||||
if opts[:only_moderator_liked]
|
||||
liked_by_moderators = PostAction.where(post_id: @filtered_posts.pluck(:id), post_action_type_id: PostActionType.types[:like])
|
||||
liked_by_moderators = liked_by_moderators.joins(:user).where('users.moderator').pluck(:post_id)
|
||||
@posts = @posts.where(id: liked_by_moderators)
|
||||
end
|
||||
|
||||
@posts = @posts.to_a
|
||||
@posts.sort!{|a,b| a.post_number <=> b.post_number}
|
||||
|
|
|
@ -23,6 +23,9 @@ describe TopicView do
|
|||
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(:moderator) { Fabricate(:moderator) }
|
||||
let(:admin) { Fabricate(:admin)
|
||||
}
|
||||
it "it can find the best responses" do
|
||||
|
||||
best2 = TopicView.new(topic.id, coding_horror, best: 2)
|
||||
|
@ -61,6 +64,21 @@ describe TopicView do
|
|||
# 0 means ignore
|
||||
best = TopicView.new(topic.id, nil, best: 99, bypass_trust_level_score: 0, min_trust_level: coding_horror.trust_level + 1)
|
||||
best.posts.count.should == 0
|
||||
|
||||
# If we restrict to posts a moderator liked, return none
|
||||
best = TopicView.new(topic.id, nil, best: 99, only_moderator_liked: true)
|
||||
best.posts.count.should == 0
|
||||
|
||||
# It doesn't count likes from admins
|
||||
PostAction.act(admin, p3, PostActionType.types[:like])
|
||||
best = TopicView.new(topic.id, nil, best: 99, only_moderator_liked: true)
|
||||
best.posts.count.should == 0
|
||||
|
||||
# It should find the post liked by the moderator
|
||||
PostAction.act(moderator, p2, PostActionType.types[:like])
|
||||
best = TopicView.new(topic.id, nil, best: 99, only_moderator_liked: true)
|
||||
best.posts.count.should == 1
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ require 'spec_helper'
|
|||
describe TopicsController do
|
||||
|
||||
|
||||
|
||||
context 'wordpress' do
|
||||
let!(:user) { log_in(:moderator) }
|
||||
let(:p1) { Fabricate(:post, user: user) }
|
||||
|
|
Loading…
Reference in New Issue