diff options
author | Rémy Coutable <remy@rymai.me> | 2016-11-16 16:58:32 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-11-16 16:58:32 +0000 |
commit | 2e1fe59e373e4be404b19f4de3c8f44bb07fe91f (patch) | |
tree | effb75ede777da8702f1a0b27aa7018f11b1c1dd | |
parent | b5d3c3caa83d5777146023f40f5e2ebea65c1d3f (diff) | |
parent | 00d9d7678b9df3a25c4f4e8f210c9d17a798c9cd (diff) | |
download | gitlab-ce-2e1fe59e373e4be404b19f4de3c8f44bb07fe91f.tar.gz |
Merge branch 'patch-5' into 'master'
Fix issue where "Without projects" filter admin area shows 0 users incorrectly. Before this fix, if any outstanding group or project invitations exist the count show as 0.
Fixes #3367
See merge request !6611
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | app/models/user.rb | 2 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 22 |
3 files changed, 24 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 1893d5626df..c35175b4bbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -73,6 +73,7 @@ entry. - Fix applying GitHub-imported labels when importing job is interrupted - Allow to search for user by secondary email address in the admin interface(/admin/users) !7115 (YarNayar) - Updated commit SHA styling on the branches page. +- Fix "Without projects" filter. !6611 (Ben Bodenmiller) - Fix 404 when visit /projects page ## 8.13.5 (2016-11-08) diff --git a/app/models/user.rb b/app/models/user.rb index 3813df6684e..5a2b232c4ed 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -173,7 +173,7 @@ class User < ActiveRecord::Base scope :external, -> { where(external: true) } scope :active, -> { with_state(:active) } 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)') } + 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)) } def self.with_two_factor diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 54b23b02003..3159243553b 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -490,6 +490,28 @@ describe User, models: true do end end + describe '.without_projects' do + let!(:project) { create(:empty_project, :public) } + let!(:user) { create(:user) } + let!(:user_without_project) { create(:user) } + let!(:user_without_project2) { create(:user) } + + before do + # add user to project + project.team << [user, :master] + + # create invite to projet + create(:project_member, :developer, project: project, invite_token: '1234', invite_email: 'inviteduser1@example.com') + + # create request to join project + project.request_access(user_without_project2) + end + + it { expect(User.without_projects).not_to include user } + it { expect(User.without_projects).to include user_without_project } + it { expect(User.without_projects).to include user_without_project2 } + end + describe '.not_in_project' do before do User.delete_all |