Commit 812fc268 authored by Sean McGivern's avatar Sean McGivern

Merge branch '37012-jira-dvcs-error' into 'master'

Fix JIRA DVCS retrieving repositories

Closes #37012

See merge request gitlab-org/gitlab!23180
parents 1965d323 77ed59ee
---
title: Fix JIRA DVCS retrieving repositories
merge_request: 23180
author:
type: fixed
...@@ -117,12 +117,14 @@ module API ...@@ -117,12 +117,14 @@ module API
namespace = Namespace.find_by_full_path(params[:namespace]) namespace = Namespace.find_by_full_path(params[:namespace])
not_found!('Namespace') unless namespace && licensed?(namespace) not_found!('Namespace') unless namespace && licensed?(namespace)
projects = Project.public_or_visible_to_user(current_user) projects = current_user.can_read_all_resources? ? Project.all : current_user.authorized_projects
.in_namespace(namespace.self_and_descendants) projects = projects.in_namespace(namespace.self_and_descendants)
.eager_load_namespace_and_owner
.with_route
present paginate(projects), projects_cte = Project.wrap_authorized_projects_with_cte(projects)
.eager_load_namespace_and_owner
.with_route
present paginate(projects_cte),
with: ::API::Github::Entities::Repository, with: ::API::Github::Entities::Repository,
root_namespace: namespace.root_ancestor root_namespace: namespace.root_ancestor
end end
......
...@@ -6,12 +6,10 @@ describe API::V3::Github do ...@@ -6,12 +6,10 @@ describe API::V3::Github do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:unauthorized_user) { create(:user) } let(:unauthorized_user) { create(:user) }
let(:admin) { create(:user, :admin) } let(:admin) { create(:user, :admin) }
let!(:project) { create(:project, :repository, creator: user) } let(:project) { create(:project, :repository, creator: user) }
let!(:project2) { create(:project, :repository, creator: user) }
before do before do
project.add_maintainer(user) project.add_maintainer(user)
project2.add_maintainer(user)
stub_licensed_features(jira_dev_panel_integration: true) stub_licensed_features(jira_dev_panel_integration: true)
end end
...@@ -199,6 +197,7 @@ describe API::V3::Github do ...@@ -199,6 +197,7 @@ describe API::V3::Github do
end end
describe 'repo pulls' do describe 'repo pulls' do
let(:project2) { create(:project, :repository, creator: user) }
let(:assignee) { create(:user) } let(:assignee) { create(:user) }
let(:assignee2) { create(:user) } let(:assignee2) { create(:user) }
let!(:merge_request) do let!(:merge_request) do
...@@ -208,6 +207,10 @@ describe API::V3::Github do ...@@ -208,6 +207,10 @@ describe API::V3::Github do
create(:merge_request, source_project: project2, target_project: project2, author: user, assignees: [assignee, assignee2]) create(:merge_request, source_project: project2, target_project: project2, author: user, assignees: [assignee, assignee2])
end end
before do
project2.add_maintainer(user)
end
describe 'GET /-/jira/pulls' do describe 'GET /-/jira/pulls' do
it 'returns an array of merge requests with github format' do it 'returns an array of merge requests with github format' do
jira_get v3_api('/repos/-/jira/pulls', user) jira_get v3_api('/repos/-/jira/pulls', user)
...@@ -283,23 +286,20 @@ describe API::V3::Github do ...@@ -283,23 +286,20 @@ describe API::V3::Github do
expect(json_response.size).to eq(projects.size) expect(json_response.size).to eq(projects.size)
end end
context 'when instance admin' do
let(:project) { create(:project, group: group) }
it 'returns an array of projects belonging to group with github format' do
expect_project_under_namespace([project], group, create(:user, :admin))
end
end
context 'group namespace' do context 'group namespace' do
let(:project) { create(:project, group: group) } let(:project) { create(:project, group: group) }
let!(:project2) { create(:project, :public, group: group) }
before do it 'returns an array of projects belonging to group excluding the ones user is not directly a member of, even when public' do
group.add_maintainer(user) expect_project_under_namespace([project], group, user)
end end
it 'returns an array of projects belonging to group with github format' do context 'when instance admin' do
expect_project_under_namespace([project], group, user) let(:user) { create(:user, :admin) }
it 'returns an array of projects belonging to group' do
expect_project_under_namespace([project, project2], group, user)
end
end 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