2019-12-26 22:10:19 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe MergeRequestPolicy do
|
2019-07-07 11:18:12 +05:30
|
|
|
include ExternalAuthorizationServiceHelpers
|
|
|
|
|
2021-12-07 22:27:20 +05:30
|
|
|
let_it_be(:guest) { create(:user) }
|
|
|
|
let_it_be(:author) { create(:user) }
|
2022-10-11 01:57:18 +05:30
|
|
|
let_it_be(:reporter) { create(:user) }
|
2021-12-07 22:27:20 +05:30
|
|
|
let_it_be(:developer) { create(:user) }
|
|
|
|
let_it_be(:non_team_member) { create(:user) }
|
2023-03-04 22:38:38 +05:30
|
|
|
let_it_be(:bot) { create(:user, :project_bot) }
|
2021-12-07 22:27:20 +05:30
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
def permissions(user, merge_request)
|
|
|
|
described_class.new(user, merge_request)
|
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
mr_perms = %i[create_merge_request_in
|
2019-09-04 21:01:54 +05:30
|
|
|
create_merge_request_from
|
|
|
|
read_merge_request
|
2022-10-11 01:57:18 +05:30
|
|
|
update_merge_request
|
2021-01-29 00:20:46 +05:30
|
|
|
create_todo
|
2020-07-28 23:09:34 +05:30
|
|
|
approve_merge_request
|
2021-09-04 01:27:46 +05:30
|
|
|
create_note
|
|
|
|
update_subscription].freeze
|
2019-09-04 21:01:54 +05:30
|
|
|
|
|
|
|
shared_examples_for 'a denied user' do
|
|
|
|
let(:perms) { permissions(subject, merge_request) }
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
mr_perms.each do |thing|
|
2019-09-04 21:01:54 +05:30
|
|
|
it "cannot #{thing}" do
|
|
|
|
expect(perms).to be_disallowed(thing)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
shared_examples_for 'a user with reporter access' do
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
where(:policy, :is_allowed) do
|
|
|
|
:create_merge_request_in | true
|
|
|
|
:read_merge_request | true
|
|
|
|
:create_todo | true
|
|
|
|
:create_note | true
|
|
|
|
:update_subscription | true
|
|
|
|
:create_merge_request_from | false
|
|
|
|
:approve_merge_request | false
|
|
|
|
:update_merge_request | false
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
specify do
|
|
|
|
is_allowed ? (is_expected.to be_allowed(policy)) : (is_expected.to be_disallowed(policy))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'a user with full access' do
|
2019-09-04 21:01:54 +05:30
|
|
|
let(:perms) { permissions(subject, merge_request) }
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
mr_perms.each do |thing|
|
2019-09-04 21:01:54 +05:30
|
|
|
it "can #{thing}" do
|
|
|
|
expect(perms).to be_allowed(thing)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
context 'when user is a direct project member' do
|
|
|
|
let(:project) { create(:project, :public) }
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
before do
|
|
|
|
project.add_guest(guest)
|
|
|
|
project.add_guest(author)
|
|
|
|
project.add_developer(developer)
|
2023-03-04 22:38:38 +05:30
|
|
|
project.add_developer(bot)
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
2021-12-07 22:27:20 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
context 'when merge request is public' do
|
|
|
|
let(:merge_request) { create(:merge_request, source_project: project, target_project: project, author: user) }
|
|
|
|
let(:user) { author }
|
2021-12-07 22:27:20 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
context 'and user is author' do
|
|
|
|
subject { permissions(user, merge_request) }
|
2022-08-13 15:12:31 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
context 'and the user is a guest' do
|
|
|
|
let(:user) { guest }
|
2022-08-13 15:12:31 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
it do
|
|
|
|
is_expected.to be_allowed(:update_merge_request)
|
|
|
|
end
|
2022-08-13 15:12:31 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
it do
|
|
|
|
is_expected.to be_allowed(:reopen_merge_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.to be_allowed(:approve_merge_request)
|
|
|
|
end
|
2023-03-04 22:38:38 +05:30
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.to be_disallowed(:reset_merge_request_approvals)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and the user is a bot' do
|
|
|
|
let(:user) { bot }
|
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.to be_allowed(:reset_merge_request_approvals)
|
|
|
|
end
|
2022-08-13 15:12:31 +05:30
|
|
|
end
|
2021-12-07 22:27:20 +05:30
|
|
|
end
|
2022-10-11 01:57:18 +05:30
|
|
|
end
|
2021-12-07 22:27:20 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
context 'when merge requests have been disabled' do
|
|
|
|
let!(:merge_request) { create(:merge_request, source_project: project, target_project: project, author: author) }
|
2022-08-13 15:12:31 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
before do
|
|
|
|
project.project_feature.update!(merge_requests_access_level: ProjectFeature::DISABLED)
|
2021-12-07 22:27:20 +05:30
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
describe 'the author' do
|
|
|
|
subject { author }
|
2022-08-13 15:12:31 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
it_behaves_like 'a denied user'
|
|
|
|
end
|
2022-08-13 15:12:31 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
describe 'a guest' do
|
|
|
|
subject { guest }
|
2022-08-13 15:12:31 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
it_behaves_like 'a denied user'
|
2022-08-13 15:12:31 +05:30
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
describe 'a developer' do
|
|
|
|
subject { developer }
|
2022-08-13 15:12:31 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
it_behaves_like 'a denied user'
|
2021-12-07 22:27:20 +05:30
|
|
|
end
|
2023-03-04 22:38:38 +05:30
|
|
|
|
|
|
|
describe 'a bot' do
|
|
|
|
let(:subject) { permissions(bot, merge_request) }
|
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.to be_disallowed(:reset_merge_request_approvals)
|
|
|
|
end
|
|
|
|
end
|
2021-12-07 22:27:20 +05:30
|
|
|
end
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
context 'when merge requests are private' do
|
|
|
|
let!(:merge_request) { create(:merge_request, source_project: project, target_project: project, author: author) }
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
before do
|
|
|
|
project.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
|
|
|
|
project.project_feature.update!(merge_requests_access_level: ProjectFeature::PRIVATE)
|
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
describe 'the author' do
|
|
|
|
subject { author }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
it_behaves_like 'a denied user'
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'a developer' do
|
|
|
|
subject { developer }
|
|
|
|
|
|
|
|
it_behaves_like 'a user with full access'
|
|
|
|
end
|
2023-03-04 22:38:38 +05:30
|
|
|
|
|
|
|
describe 'a bot' do
|
|
|
|
let(:subject) { permissions(bot, merge_request) }
|
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.to be_allowed(:reset_merge_request_approvals)
|
|
|
|
end
|
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
context 'when merge request is unlocked' do
|
|
|
|
let(:merge_request) { create(:merge_request, :closed, source_project: project, target_project: project, author: author) }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
it 'allows author to reopen merge request' do
|
|
|
|
expect(permissions(author, merge_request)).to be_allowed(:reopen_merge_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows developer to reopen merge request' do
|
|
|
|
expect(permissions(developer, merge_request)).to be_allowed(:reopen_merge_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'prevents guest from reopening merge request' do
|
|
|
|
expect(permissions(guest, merge_request)).to be_disallowed(:reopen_merge_request)
|
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
context 'when merge request is locked' do
|
|
|
|
let(:merge_request_locked) { create(:merge_request, :closed, discussion_locked: true, source_project: project, target_project: project, author: author) }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
it 'prevents author from reopening merge request' do
|
|
|
|
expect(permissions(author, merge_request_locked)).to be_disallowed(:reopen_merge_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'prevents developer from reopening merge request' do
|
|
|
|
expect(permissions(developer, merge_request_locked)).to be_disallowed(:reopen_merge_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'prevents guests from reopening merge request' do
|
|
|
|
expect(permissions(guest, merge_request_locked)).to be_disallowed(:reopen_merge_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user is project member, with at least guest access' do
|
|
|
|
let(:user) { guest }
|
|
|
|
|
|
|
|
it 'can create a note' do
|
|
|
|
expect(permissions(user, merge_request_locked)).to be_allowed(:create_note)
|
|
|
|
end
|
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
context 'with external authorization enabled' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project) { create(:project, :public) }
|
|
|
|
let(:merge_request) { create(:merge_request, source_project: project) }
|
|
|
|
let(:policies) { described_class.new(user, merge_request) }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
before do
|
|
|
|
enable_external_authorization_service_check
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can read the issue iid without accessing the external service' do
|
|
|
|
expect(::Gitlab::ExternalAuthorization).not_to receive(:access_allowed?)
|
|
|
|
|
|
|
|
expect(policies).to be_allowed(:read_merge_request_iid)
|
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
context 'when user is an inherited member from the parent group' do
|
|
|
|
let_it_be(:group) { create(:group, :public) }
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
let(:merge_request) { create(:merge_request, source_project: project, target_project: project, author: author) }
|
|
|
|
|
|
|
|
before_all do
|
|
|
|
group.add_guest(guest)
|
|
|
|
group.add_guest(author)
|
|
|
|
group.add_reporter(reporter)
|
|
|
|
group.add_developer(developer)
|
2023-03-04 22:38:38 +05:30
|
|
|
group.add_developer(bot)
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
context 'when project is public' do
|
|
|
|
let(:project) { create(:project, :public, group: group) }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
describe 'the merge request author' do
|
|
|
|
subject { permissions(author, merge_request) }
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
it do
|
2022-10-11 01:57:18 +05:30
|
|
|
is_expected.to be_allowed(:approve_merge_request)
|
|
|
|
end
|
2023-03-04 22:38:38 +05:30
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.to be_disallowed(:reset_merge_request_approvals)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'a bot' do
|
|
|
|
subject { permissions(bot, merge_request) }
|
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.to be_allowed(:approve_merge_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.to be_allowed(:reset_merge_request_approvals)
|
|
|
|
end
|
2022-10-11 01:57:18 +05:30
|
|
|
end
|
2021-12-07 22:27:20 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
context 'and merge requests are private' do
|
|
|
|
before do
|
|
|
|
project.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
|
|
|
|
project.project_feature.update!(merge_requests_access_level: ProjectFeature::PRIVATE)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'a guest' do
|
|
|
|
subject { guest }
|
|
|
|
|
|
|
|
it_behaves_like 'a denied user'
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'a reporter' do
|
|
|
|
subject { permissions(reporter, merge_request) }
|
|
|
|
|
|
|
|
it_behaves_like 'a user with reporter access'
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'a developer' do
|
|
|
|
subject { developer }
|
|
|
|
|
|
|
|
it_behaves_like 'a user with full access'
|
|
|
|
end
|
2023-03-04 22:38:38 +05:30
|
|
|
|
|
|
|
describe 'a bot' do
|
|
|
|
let(:subject) { permissions(bot, merge_request) }
|
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.to be_allowed(:reset_merge_request_approvals)
|
|
|
|
end
|
|
|
|
end
|
2022-10-11 01:57:18 +05:30
|
|
|
end
|
2021-12-07 22:27:20 +05:30
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
context 'when project is private' do
|
|
|
|
let(:project) { create(:project, :private, group: group) }
|
|
|
|
|
|
|
|
describe 'a guest' do
|
|
|
|
subject { guest }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
it_behaves_like 'a denied user'
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'a reporter' do
|
|
|
|
subject { permissions(reporter, merge_request) }
|
|
|
|
|
|
|
|
it_behaves_like 'a user with reporter access'
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'a developer' do
|
|
|
|
subject { developer }
|
|
|
|
|
|
|
|
it_behaves_like 'a user with full access'
|
|
|
|
end
|
2023-03-04 22:38:38 +05:30
|
|
|
|
|
|
|
describe 'a bot' do
|
|
|
|
let(:subject) { permissions(bot, merge_request) }
|
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.to be_allowed(:reset_merge_request_approvals)
|
|
|
|
end
|
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
context 'when user is an inherited member from a shared group' do
|
|
|
|
let(:project) { create(:project, :public) }
|
|
|
|
let(:merge_request) { create(:merge_request, source_project: project, target_project: project, author: user) }
|
|
|
|
let(:user) { author }
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
before do
|
|
|
|
project.add_guest(author)
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
context 'and group is given developer access' do
|
|
|
|
let(:user) { non_team_member }
|
|
|
|
|
|
|
|
subject { permissions(user, merge_request) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
group = create(:group)
|
|
|
|
project.project_group_links.create!(
|
|
|
|
group: group,
|
|
|
|
group_access: Gitlab::Access::DEVELOPER)
|
|
|
|
|
|
|
|
group.add_guest(non_team_member)
|
2023-03-04 22:38:38 +05:30
|
|
|
group.add_guest(bot)
|
2022-10-11 01:57:18 +05:30
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
it do
|
2022-10-11 01:57:18 +05:30
|
|
|
is_expected.to be_allowed(:approve_merge_request)
|
|
|
|
end
|
2023-03-04 22:38:38 +05:30
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.to be_disallowed(:reset_merge_request_approvals)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and the user is a bot' do
|
|
|
|
let(:user) { bot }
|
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.to be_allowed(:approve_merge_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.to be_allowed(:reset_merge_request_approvals)
|
|
|
|
end
|
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
context 'when user is not a project member' do
|
|
|
|
let(:project) { create(:project, :public) }
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
context 'when merge request is public' do
|
|
|
|
let(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
subject { permissions(non_team_member, merge_request) }
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
it do
|
2022-10-11 01:57:18 +05:30
|
|
|
is_expected.not_to be_allowed(:approve_merge_request)
|
|
|
|
end
|
2023-03-04 22:38:38 +05:30
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.not_to be_allowed(:reset_merge_request_approvals)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and the user is a bot' do
|
|
|
|
subject { permissions(bot, merge_request) }
|
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.not_to be_allowed(:approve_merge_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.not_to be_allowed(:reset_merge_request_approvals)
|
|
|
|
end
|
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
context 'when merge requests are disabled' do
|
|
|
|
let!(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.project_feature.update!(merge_requests_access_level: ProjectFeature::DISABLED)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { non_team_member }
|
|
|
|
|
|
|
|
it_behaves_like 'a denied user'
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
context 'when merge requests are private' do
|
|
|
|
let!(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
before do
|
|
|
|
project.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
|
|
|
|
project.project_feature.update!(merge_requests_access_level: ProjectFeature::PRIVATE)
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
2022-10-11 01:57:18 +05:30
|
|
|
|
|
|
|
subject { non_team_member }
|
|
|
|
|
|
|
|
it_behaves_like 'a denied user'
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
context 'when merge request is locked' do
|
|
|
|
let(:merge_request) { create(:merge_request, :closed, discussion_locked: true, source_project: project, target_project: project) }
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
it 'cannot create a note' do
|
|
|
|
expect(permissions(non_team_member, merge_request)).to be_disallowed(:create_note)
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
context 'when user is anonymous' do
|
2019-07-07 11:18:12 +05:30
|
|
|
let(:project) { create(:project, :public) }
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
context 'when merge request is public' do
|
|
|
|
let(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
subject { permissions(nil, merge_request) }
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
specify do
|
|
|
|
is_expected.to be_disallowed(:create_todo, :update_subscription)
|
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
end
|
2023-03-17 16:20:25 +05:30
|
|
|
|
|
|
|
context 'when the author of the merge request is banned', feature_category: :insider_threat do
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:admin) { create(:user, :admin) }
|
|
|
|
let_it_be(:author) { create(:user, :banned) }
|
|
|
|
let_it_be(:project) { create(:project, :public) }
|
|
|
|
let_it_be(:hidden_merge_request) { create(:merge_request, source_project: project, author: author) }
|
|
|
|
|
|
|
|
it 'does not allow non-admin user to read the merge_request' do
|
|
|
|
expect(permissions(user, hidden_merge_request)).not_to be_allowed(:read_merge_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows admin to read the merge_request', :enable_admin_mode do
|
|
|
|
expect(permissions(admin, hidden_merge_request)).to be_allowed(:read_merge_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the `hide_merge_requests_from_banned_users` feature flag is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(hide_merge_requests_from_banned_users: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows non-admin users to read the merge_request' do
|
|
|
|
expect(permissions(user, hidden_merge_request)).to be_allowed(:read_merge_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows admin users to read the merge_request', :enable_admin_mode do
|
|
|
|
expect(permissions(admin, hidden_merge_request)).to be_allowed(:read_merge_request)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|