2016-03-01 11:56:14 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::SearchResults do
|
2017-09-29 04:04:50 -04:00
|
|
|
include ProjectForksHelper
|
|
|
|
|
2016-03-17 16:48:19 -04:00
|
|
|
let(:user) { create(:user) }
|
2017-08-02 15:55:11 -04:00
|
|
|
let!(:project) { create(:project, name: 'foo') }
|
2016-03-01 11:56:14 -05:00
|
|
|
let!(:issue) { create(:issue, project: project, title: 'foo') }
|
|
|
|
|
|
|
|
let!(:merge_request) do
|
|
|
|
create(:merge_request, source_project: project, title: 'foo')
|
|
|
|
end
|
|
|
|
|
|
|
|
let!(:milestone) { create(:milestone, project: project, title: 'foo') }
|
2016-03-17 16:48:19 -04:00
|
|
|
let(:results) { described_class.new(user, Project.all, 'foo') }
|
2016-03-01 11:56:14 -05:00
|
|
|
|
2016-11-22 05:25:04 -05:00
|
|
|
context 'as a user with access' do
|
|
|
|
before do
|
|
|
|
project.team << [user, :developer]
|
2016-03-01 11:56:14 -05:00
|
|
|
end
|
|
|
|
|
2016-11-22 05:25:04 -05:00
|
|
|
describe '#projects_count' do
|
|
|
|
it 'returns the total amount of projects' do
|
|
|
|
expect(results.projects_count).to eq(1)
|
|
|
|
end
|
2016-03-01 11:56:14 -05:00
|
|
|
end
|
|
|
|
|
2016-11-22 05:25:04 -05:00
|
|
|
describe '#issues_count' do
|
|
|
|
it 'returns the total amount of issues' do
|
|
|
|
expect(results.issues_count).to eq(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#merge_requests_count' do
|
|
|
|
it 'returns the total amount of merge requests' do
|
|
|
|
expect(results.merge_requests_count).to eq(1)
|
|
|
|
end
|
2016-03-01 11:56:14 -05:00
|
|
|
end
|
|
|
|
|
2016-11-22 05:25:04 -05:00
|
|
|
describe '#milestones_count' do
|
|
|
|
it 'returns the total amount of milestones' do
|
|
|
|
expect(results.milestones_count).to eq(1)
|
|
|
|
end
|
2016-03-01 11:56:14 -05:00
|
|
|
end
|
2016-11-29 08:47:43 -05:00
|
|
|
|
|
|
|
it 'includes merge requests from source and target projects' do
|
2017-09-29 04:04:50 -04:00
|
|
|
forked_project = fork_project(project, user)
|
2016-11-29 08:47:43 -05:00
|
|
|
merge_request_2 = create(:merge_request, target_project: project, source_project: forked_project, title: 'foo')
|
|
|
|
|
|
|
|
results = described_class.new(user, Project.where(id: forked_project.id), 'foo')
|
|
|
|
|
|
|
|
expect(results.objects('merge_requests')).to include merge_request_2
|
|
|
|
end
|
2016-03-01 11:56:14 -05:00
|
|
|
end
|
|
|
|
|
2016-11-22 05:25:04 -05:00
|
|
|
it 'does not list issues on private projects' do
|
2017-08-02 15:55:11 -04:00
|
|
|
private_project = create(:project, :private)
|
2016-11-22 05:25:04 -05:00
|
|
|
issue = create(:issue, project: private_project, title: 'foo')
|
|
|
|
|
|
|
|
expect(results.objects('issues')).not_to include issue
|
|
|
|
end
|
|
|
|
|
2016-03-17 16:48:19 -04:00
|
|
|
describe 'confidential issues' do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project_1) { create(:project, :internal) }
|
|
|
|
let(:project_2) { create(:project, :internal) }
|
|
|
|
let(:project_3) { create(:project, :internal) }
|
|
|
|
let(:project_4) { create(:project, :internal) }
|
2016-03-17 16:48:19 -04:00
|
|
|
let(:query) { 'issue' }
|
|
|
|
let(:limit_projects) { Project.where(id: [project_1.id, project_2.id, project_3.id]) }
|
|
|
|
let(:author) { create(:user) }
|
|
|
|
let(:assignee) { create(:user) }
|
|
|
|
let(:non_member) { create(:user) }
|
|
|
|
let(:member) { create(:user) }
|
|
|
|
let(:admin) { create(:admin) }
|
|
|
|
let!(:issue) { create(:issue, project: project_1, title: 'Issue 1') }
|
|
|
|
let!(:security_issue_1) { create(:issue, :confidential, project: project_1, title: 'Security issue 1', author: author) }
|
2017-05-04 08:11:15 -04:00
|
|
|
let!(:security_issue_2) { create(:issue, :confidential, title: 'Security issue 2', project: project_1, assignees: [assignee]) }
|
2016-03-17 16:48:19 -04:00
|
|
|
let!(:security_issue_3) { create(:issue, :confidential, project: project_2, title: 'Security issue 3', author: author) }
|
2017-05-04 08:11:15 -04:00
|
|
|
let!(:security_issue_4) { create(:issue, :confidential, project: project_3, title: 'Security issue 4', assignees: [assignee]) }
|
2016-03-17 16:48:19 -04:00
|
|
|
let!(:security_issue_5) { create(:issue, :confidential, project: project_4, title: 'Security issue 5') }
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'does not list confidential issues for non project members' do
|
2016-03-17 16:48:19 -04:00
|
|
|
results = described_class.new(non_member, limit_projects, query)
|
|
|
|
issues = results.objects('issues')
|
|
|
|
|
|
|
|
expect(issues).to include issue
|
|
|
|
expect(issues).not_to include security_issue_1
|
|
|
|
expect(issues).not_to include security_issue_2
|
|
|
|
expect(issues).not_to include security_issue_3
|
|
|
|
expect(issues).not_to include security_issue_4
|
|
|
|
expect(issues).not_to include security_issue_5
|
|
|
|
expect(results.issues_count).to eq 1
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'does not list confidential issues for project members with guest role' do
|
2016-06-06 15:13:31 -04:00
|
|
|
project_1.team << [member, :guest]
|
|
|
|
project_2.team << [member, :guest]
|
|
|
|
|
|
|
|
results = described_class.new(member, limit_projects, query)
|
|
|
|
issues = results.objects('issues')
|
|
|
|
|
|
|
|
expect(issues).to include issue
|
|
|
|
expect(issues).not_to include security_issue_1
|
|
|
|
expect(issues).not_to include security_issue_2
|
|
|
|
expect(issues).not_to include security_issue_3
|
|
|
|
expect(issues).not_to include security_issue_4
|
|
|
|
expect(issues).not_to include security_issue_5
|
|
|
|
expect(results.issues_count).to eq 1
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'lists confidential issues for author' do
|
2016-03-17 16:48:19 -04:00
|
|
|
results = described_class.new(author, limit_projects, query)
|
|
|
|
issues = results.objects('issues')
|
|
|
|
|
|
|
|
expect(issues).to include issue
|
|
|
|
expect(issues).to include security_issue_1
|
|
|
|
expect(issues).not_to include security_issue_2
|
|
|
|
expect(issues).to include security_issue_3
|
|
|
|
expect(issues).not_to include security_issue_4
|
|
|
|
expect(issues).not_to include security_issue_5
|
|
|
|
expect(results.issues_count).to eq 3
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'lists confidential issues for assignee' do
|
2016-03-17 16:48:19 -04:00
|
|
|
results = described_class.new(assignee, limit_projects, query)
|
|
|
|
issues = results.objects('issues')
|
|
|
|
|
|
|
|
expect(issues).to include issue
|
|
|
|
expect(issues).not_to include security_issue_1
|
|
|
|
expect(issues).to include security_issue_2
|
|
|
|
expect(issues).not_to include security_issue_3
|
|
|
|
expect(issues).to include security_issue_4
|
|
|
|
expect(issues).not_to include security_issue_5
|
|
|
|
expect(results.issues_count).to eq 3
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'lists confidential issues for project members' do
|
2016-03-17 16:48:19 -04:00
|
|
|
project_1.team << [member, :developer]
|
|
|
|
project_2.team << [member, :developer]
|
|
|
|
|
|
|
|
results = described_class.new(member, limit_projects, query)
|
|
|
|
issues = results.objects('issues')
|
|
|
|
|
|
|
|
expect(issues).to include issue
|
|
|
|
expect(issues).to include security_issue_1
|
|
|
|
expect(issues).to include security_issue_2
|
|
|
|
expect(issues).to include security_issue_3
|
|
|
|
expect(issues).not_to include security_issue_4
|
|
|
|
expect(issues).not_to include security_issue_5
|
|
|
|
expect(results.issues_count).to eq 4
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'lists all issues for admin' do
|
2016-03-17 16:48:19 -04:00
|
|
|
results = described_class.new(admin, limit_projects, query)
|
|
|
|
issues = results.objects('issues')
|
|
|
|
|
|
|
|
expect(issues).to include issue
|
|
|
|
expect(issues).to include security_issue_1
|
|
|
|
expect(issues).to include security_issue_2
|
|
|
|
expect(issues).to include security_issue_3
|
|
|
|
expect(issues).to include security_issue_4
|
|
|
|
expect(issues).not_to include security_issue_5
|
|
|
|
expect(results.issues_count).to eq 5
|
|
|
|
end
|
|
|
|
end
|
2016-11-29 08:47:43 -05:00
|
|
|
|
|
|
|
it 'does not list merge requests on projects with limited access' do
|
|
|
|
project.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
|
|
|
|
project.project_feature.update!(merge_requests_access_level: ProjectFeature::PRIVATE)
|
|
|
|
|
|
|
|
expect(results.objects('merge_requests')).not_to include merge_request
|
|
|
|
end
|
2016-03-01 11:56:14 -05:00
|
|
|
end
|