Skip to content

Commit

Permalink
FEATURE: query param for closed / archived / open
Browse files Browse the repository at this point in the history
?status=closed for closed topics
?status=open for open topics
?status=archived for archived topics
  • Loading branch information
SamSaffron committed Jan 13, 2014
1 parent e076682 commit 2c75e15
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/controllers/list_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def build_topic_list_options
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
Expand Down
14 changes: 13 additions & 1 deletion lib/topic_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -243,6 +244,17 @@ def default_results(options={})
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
Expand Down

0 comments on commit 2c75e15

Please sign in to comment.