Add scope for human users.
This commit is contained in:
parent
6ebddc42d1
commit
4d4a1a1552
|
@ -35,12 +35,12 @@ class About
|
|||
|
||||
def moderators
|
||||
@moderators ||= User.where(moderator: true, admin: false)
|
||||
.where("id > 0")
|
||||
.human_users
|
||||
.order(:username_lower)
|
||||
end
|
||||
|
||||
def admins
|
||||
@admins ||= User.where(admin: true).where("id > 0").order(:username_lower)
|
||||
@admins ||= User.where(admin: true).human_users.order(:username_lower)
|
||||
end
|
||||
|
||||
def stats
|
||||
|
|
|
@ -124,8 +124,10 @@ class User < ActiveRecord::Base
|
|||
# set to true to optimize creation and save for imports
|
||||
attr_accessor :import_mode
|
||||
|
||||
scope :human_users, -> { where('users.id > 0') }
|
||||
|
||||
# excluding fake users like the system user or anonymous users
|
||||
scope :real, -> { where('users.id > 0').where('NOT EXISTS(
|
||||
scope :real, -> { human_users.where('NOT EXISTS(
|
||||
SELECT 1
|
||||
FROM user_custom_fields ucf
|
||||
WHERE
|
||||
|
|
|
@ -1485,4 +1485,12 @@ describe User do
|
|||
|
||||
end
|
||||
|
||||
describe '.human_users' do
|
||||
it 'should only return users with a positive primary key' do
|
||||
Fabricate(:user, id: -2)
|
||||
user = Fabricate(:user)
|
||||
|
||||
expect(User.human_users).to eq([user])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue