Commit 5acec688 authored by charlie ablett's avatar charlie ablett

Merge branch '238569-fix-issuable-count-scope-graphql' into 'master'

Ensure issue status counts are scoped

Closes #238569

See merge request gitlab-org/gitlab!39914
parents fc6e83c2 a8f7cfc3
......@@ -7,7 +7,21 @@ module Resolvers
type Types::IssueStatusCountsType, null: true
def continue_issue_resolve(parent, finder, **args)
finder.params[parent_param(parent)] = parent if parent
apply_lookahead(Gitlab::IssuablesCountForState.new(finder, parent))
end
private
def parent_param(parent)
case parent
when Project
:project_id
when Group
:group_id
else
raise "Unexpected type of parent: #{parent.class}. Must be Project or Group"
end
end
end
end
---
title: Scope incident issue counts by given project or group
merge_request: 39914
author:
type: fixed
......@@ -7,14 +7,21 @@ RSpec.describe Resolvers::IssueStatusCountsResolver do
describe '#resolve' do
let_it_be(:current_user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:issue) { create(:issue, project: project, state: :opened, created_at: 3.hours.ago, updated_at: 3.hours.ago) }
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, group: group) }
let_it_be(:issue) { create(:issue, project: project, state: :opened, created_at: 3.hours.ago, updated_at: 3.hours.ago) }
let_it_be(:incident) { create(:incident, project: project, state: :closed, created_at: 1.hour.ago, updated_at: 1.hour.ago, closed_at: 1.hour.ago) }
# This issue should not be included in the counts
let_it_be(:other_project) { create(:project) }
let_it_be(:other_proj_issue) { create(:issue, state: :opened, project: other_project) }
let(:parent) { project }
let(:args) { {} }
before do
before_all do
project.add_developer(current_user)
other_project.add_developer(current_user)
end
subject { resolve_issue_status_counts(args) }
......@@ -22,12 +29,22 @@ RSpec.describe Resolvers::IssueStatusCountsResolver do
it { is_expected.to be_a(Gitlab::IssuablesCountForState) }
specify { expect(subject.project).to eq(project) }
it 'returns expected results' do
result = resolve_issue_status_counts
shared_examples 'returns expected results' do
it 'returns expected results', :aggregate_failures do
result = resolve_issue_status_counts
expect(result.all).to eq 2
expect(result.opened).to eq 1
expect(result.closed).to eq 1
expect(result.all).to eq 2
expect(result.opened).to eq 1
expect(result.closed).to eq 1
end
end
it_behaves_like 'returns expected results'
context 'group used as parent' do
let(:parent) { project.group }
it_behaves_like 'returns expected results'
end
it 'filters by search', :aggregate_failures do
......@@ -58,7 +75,7 @@ RSpec.describe Resolvers::IssueStatusCountsResolver do
private
def resolve_issue_status_counts(args = {}, context = { current_user: current_user })
resolve(described_class, obj: project, args: args, ctx: context)
resolve(described_class, obj: parent, args: args, ctx: context)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment