Filter out archived projects from issue/mr count

Pass the 'non_archived' flag to finder methods
This commit is contained in:
Brett Walker 2018-09-14 14:56:56 -05:00
parent ccce7c7955
commit 50a62b479e
4 changed files with 40 additions and 2 deletions

View file

@ -1176,13 +1176,13 @@ class User < ActiveRecord::Base
def assigned_open_merge_requests_count(force: false)
Rails.cache.fetch(['users', id, 'assigned_open_merge_requests_count'], force: force, expires_in: 20.minutes) do
MergeRequestsFinder.new(self, assignee_id: self.id, state: 'opened').execute.count
MergeRequestsFinder.new(self, assignee_id: self.id, state: 'opened', non_archived: true).execute.count
end
end
def assigned_open_issues_count(force: false)
Rails.cache.fetch(['users', id, 'assigned_open_issues_count'], force: force, expires_in: 20.minutes) do
IssuesFinder.new(self, assignee_id: self.id, state: 'opened').execute.count
IssuesFinder.new(self, assignee_id: self.id, state: 'opened', non_archived: true).execute.count
end
end

View file

@ -0,0 +1,5 @@
---
title: Issue and MR count now ignores archived projects
merge_request: 21721
author:
type: fixed

View file

@ -0,0 +1,5 @@
---
title: No longer show open issues from archived projects in group issue board
merge_request: 21721
author:
type: fixed

View file

@ -2543,6 +2543,34 @@ describe User do
end
end
describe '#assigned_open_merge_requests_count' do
it 'returns number of open merge requests from non-archived projects' do
user = create(:user)
project = create(:project, :public)
archived_project = create(:project, :public, :archived)
create(:merge_request, source_project: project, author: user, assignee: user)
create(:merge_request, :closed, source_project: project, author: user, assignee: user)
create(:merge_request, source_project: archived_project, author: user, assignee: user)
expect(user.assigned_open_merge_requests_count(force: true)).to eq 1
end
end
describe '#assigned_open_issues_count' do
it 'returns number of open issues from non-archived projects' do
user = create(:user)
project = create(:project, :public)
archived_project = create(:project, :public, :archived)
create(:issue, project: project, author: user, assignees: [user])
create(:issue, :closed, project: project, author: user, assignees: [user])
create(:issue, project: archived_project, author: user, assignees: [user])
expect(user.assigned_open_issues_count(force: true)).to eq 1
end
end
describe '#personal_projects_count' do
it 'returns the number of personal projects using a single query' do
user = build(:user)