From 2c75e15049526272041b6407333a61152442c6da Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 13 Jan 2014 14:40:21 +1100 Subject: [PATCH] FEATURE: query param for closed / archived / open ?status=closed for closed topics ?status=open for open topics ?status=archived for archived topics --- app/controllers/list_controller.rb | 1 + lib/topic_query.rb | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rb index e19fdefbc..f532c550f 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 f1aaf3825..6a3d40e96 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