From 6b3d5c734880b609487cc8ef73ea386d23aef72f Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Thu, 5 Jun 2014 15:30:24 +0200 Subject: [PATCH] add min_posts, max_posts to filter the topic list queries superseeds #2412 --- app/controllers/list_controller.rb | 2 ++ lib/topic_query.rb | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rb index 11adede2cb6..91f653fe76e 100644 --- a/app/controllers/list_controller.rb +++ b/app/controllers/list_controller.rb @@ -267,6 +267,8 @@ class ListController < ApplicationController category: params[:category], order: params[:order], ascending: params[:ascending], + min_posts: params[:min_posts], + max_posts: params[:max_posts], status: params[:status] } options[:no_subcategories] = true if params[:no_subcategories] == 'true' diff --git a/lib/topic_query.rb b/lib/topic_query.rb index 318c53d6ab9..2456c99bb6a 100644 --- a/lib/topic_query.rb +++ b/lib/topic_query.rb @@ -13,6 +13,8 @@ class TopicQuery limit page per_page + min_posts + max_posts topic_ids visible category @@ -266,6 +268,9 @@ class TopicQuery end end + result = result.where('topics.posts_count <= ?', options[:max_posts]) if options[:max_posts].present? + result = result.where('topics.posts_count >= ?', options[:min_posts]) if options[:min_posts].present? + guardian = Guardian.new(@user) if !guardian.is_admin? allowed_ids = guardian.allowed_category_ids