summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/user.rb2
-rw-r--r--changelogs/unreleased/fix-user-count.yml4
-rw-r--r--spec/models/user_spec.rb12
3 files changed, 17 insertions, 1 deletions
diff --git a/app/models/user.rb b/app/models/user.rb
index 457ba05fb04..2d85bf8df26 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -197,7 +197,7 @@ class User < ActiveRecord::Base
scope :admins, -> { where(admin: true) }
scope :blocked, -> { with_states(:blocked, :ldap_blocked) }
scope :external, -> { where(external: true) }
- scope :active, -> { with_state(:active) }
+ scope :active, -> { with_state(:active).non_internal }
scope :not_in_project, ->(project) { project.users.present? ? where("id not in (:ids)", ids: project.users.map(&:id) ) : all }
scope :without_projects, -> { where('id NOT IN (SELECT DISTINCT(user_id) FROM members WHERE user_id IS NOT NULL AND requested_at IS NULL)') }
scope :todo_authors, ->(user_id, state) { where(id: Todo.where(user_id: user_id, state: state).select(:author_id)) }
diff --git a/changelogs/unreleased/fix-user-count.yml b/changelogs/unreleased/fix-user-count.yml
new file mode 100644
index 00000000000..217a3e47349
--- /dev/null
+++ b/changelogs/unreleased/fix-user-count.yml
@@ -0,0 +1,4 @@
+---
+title: Fix active user count to ignore internal users
+merge_request:
+author:
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 9de16c41e94..6af5ef1018c 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -1631,4 +1631,16 @@ describe User, models: true do
end
end
end
+
+ context '.active' do
+ before do
+ User.ghost
+ create(:user, name: 'user', state: 'active')
+ create(:user, name: 'user', state: 'blocked')
+ end
+
+ it 'only counts active and non internal users' do
+ expect(User.active.count).to eq(1)
+ end
+ end
end