FEATURE: query param for closed / archived / open

?status=closed for closed topics
?status=open for open topics
?status=archived for archived topics
This commit is contained in:
Sam 2014-01-13 14:40:21 +11:00
parent e076682bc6
commit 2c75e15049
2 changed files with 14 additions and 1 deletions

View file

@ -156,6 +156,7 @@ class ListController < ApplicationController
category: params[:category], category: params[:category],
sort_order: params[:sort_order], sort_order: params[:sort_order],
sort_descending: params[:sort_descending], sort_descending: params[:sort_descending],
status: params[:status]
} }
result[:no_subcategories] = true if params[:no_subcategories] == 'true' result[:no_subcategories] = true if params[:no_subcategories] == 'true'
result result

View file

@ -18,7 +18,8 @@ class TopicQuery
category category
sort_order sort_order
no_subcategories no_subcategories
sort_descending).map(&:to_sym) sort_descending
status).map(&:to_sym)
# Maps `sort_order` to a columns in `topics` # Maps `sort_order` to a columns in `topics`
SORTABLE_MAPPING = { SORTABLE_MAPPING = {
@ -243,6 +244,17 @@ class TopicQuery
result = result.where('topics.id in (?)', options[:topic_ids]).references(:topics) result = result.where('topics.id in (?)', options[:topic_ids]).references(:topics)
end 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) guardian = Guardian.new(@user)
unless guardian.is_staff? unless guardian.is_staff?
allowed_ids = guardian.allowed_category_ids allowed_ids = guardian.allowed_category_ids