From 3b15e2e58e0a082b2a075499bb6f18c11a2183ed Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Thu, 22 Aug 2013 19:23:49 -0400 Subject: [PATCH] Banned users are not returned as pending review users --- app/models/user.rb | 1 + lib/admin_user_index_query.rb | 2 +- spec/components/admin_user_index_query_spec.rb | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index f83c2edd17d..a7f8af26548 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -68,6 +68,7 @@ class User < ActiveRecord::Base scope :blocked, -> { where(blocked: true) } # no index scope :banned, -> { where('banned_till IS NOT NULL AND banned_till > ?', Time.zone.now) } # no index + scope :not_banned, -> { where('banned_till IS NULL') } module NewTopicDuration ALWAYS = -1 diff --git a/lib/admin_user_index_query.rb b/lib/admin_user_index_query.rb index b574ba4ec9d..cf3c6e3e4db 100644 --- a/lib/admin_user_index_query.rb +++ b/lib/admin_user_index_query.rb @@ -30,7 +30,7 @@ class AdminUserIndexQuery when 'moderators' then @query.where('moderator = ?', true) when 'blocked' then @query.blocked when 'banned' then @query.banned - when 'pending' then @query.where('approved = false') + when 'pending' then @query.not_banned.where('approved = false') end end diff --git a/spec/components/admin_user_index_query_spec.rb b/spec/components/admin_user_index_query_spec.rb index 5f85c97b0a2..689de3cc1b0 100644 --- a/spec/components/admin_user_index_query_spec.rb +++ b/spec/components/admin_user_index_query_spec.rb @@ -46,6 +46,14 @@ describe AdminUserIndexQuery do expect(query.find_users.count).to eq(1) end + context 'and a banned pending user' do + let!(:banned_user) { Fabricate(:user, approved: false, banned_at: 1.hour.ago, banned_till: 20.years.from_now) } + it "doesn't return the banned user" do + query = ::AdminUserIndexQuery.new({ query: 'pending' }) + expect(query.find_users.count).to eq(1) + end + end + end describe "with an admin user" do