diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rb index e19fdefbc61..f532c550ff5 100644 --- a/app/controllers/list_controller.rb +++ b/app/controllers/list_controller.rb @@ -156,6 +156,7 @@ class ListController < ApplicationController category: params[:category], sort_order: params[:sort_order], sort_descending: params[:sort_descending], + status: params[:status] } result[:no_subcategories] = true if params[:no_subcategories] == 'true' result diff --git a/lib/topic_query.rb b/lib/topic_query.rb index f1aaf3825c3..6a3d40e9672 100644 --- a/lib/topic_query.rb +++ b/lib/topic_query.rb @@ -18,7 +18,8 @@ class TopicQuery category sort_order no_subcategories - sort_descending).map(&:to_sym) + sort_descending + status).map(&:to_sym) # Maps `sort_order` to a columns in `topics` SORTABLE_MAPPING = { @@ -243,6 +244,17 @@ class TopicQuery result = result.where('topics.id in (?)', options[:topic_ids]).references(:topics) end + if status = options[:status] + case status + when 'open' + result = result.where('NOT topics.closed AND NOT topics.archived') + when 'closed' + result = result.where('topics.closed') + when 'archived' + result = result.where('topics.archived') + end + end + guardian = Guardian.new(@user) unless guardian.is_staff? allowed_ids = guardian.allowed_category_ids