mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
FEATURE: Add ?status=deleted querystring
Add tests around the ?status=deleted querystring
This commit is contained in:
parent
22fa46b1f2
commit
0d6e5470d4
2 changed files with 20 additions and 1 deletions
|
@ -233,7 +233,7 @@ class TopicQuery
|
|||
options.reverse_merge!(per_page: SiteSetting.topics_per_page)
|
||||
|
||||
# Start with a list of all topics
|
||||
result = Topic
|
||||
result = Topic.unscoped
|
||||
|
||||
if @user
|
||||
result = result.joins("LEFT OUTER JOIN topic_users AS tu ON (topics.id = tu.topic_id AND tu.user_id = #{@user.id.to_i})")
|
||||
|
@ -286,6 +286,7 @@ class TopicQuery
|
|||
notification_level = ?)', @user.id, level)
|
||||
end
|
||||
|
||||
require_deleted_clause = true
|
||||
if status = options[:status]
|
||||
case status
|
||||
when 'open'
|
||||
|
@ -298,9 +299,16 @@ class TopicQuery
|
|||
result = result.where('topics.visible')
|
||||
when 'invisible'
|
||||
result = result.where('NOT topics.visible')
|
||||
when 'deleted'
|
||||
guardian = Guardian.new(@user)
|
||||
if guardian.is_staff?
|
||||
result = result.where('topics.deleted_at IS NOT NULL')
|
||||
require_deleted_clause = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
result = result.where('topics.deleted_at IS NULL') if require_deleted_clause
|
||||
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?
|
||||
|
||||
|
|
|
@ -40,6 +40,17 @@ describe TopicQuery do
|
|||
|
||||
end
|
||||
|
||||
context 'deleted filter' do
|
||||
it "filters deleted topics correctly" do
|
||||
topic = Fabricate(:topic, deleted_at: 1.year.ago)
|
||||
|
||||
TopicQuery.new(admin, status: 'deleted').list_latest.topics.size.should == 1
|
||||
TopicQuery.new(moderator, status: 'deleted').list_latest.topics.size.should == 1
|
||||
TopicQuery.new(user, status: 'deleted').list_latest.topics.size.should == 0
|
||||
TopicQuery.new(nil, status: 'deleted').list_latest.topics.size.should == 0
|
||||
end
|
||||
end
|
||||
|
||||
context 'category filter' do
|
||||
let(:category) { Fabricate(:category) }
|
||||
|
||||
|
|
Loading…
Reference in a new issue