2019-12-26 22:10:19 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
RSpec.describe IssuePolicy, feature_category: :team_planning do
|
2022-08-27 11:52:29 +05:30
|
|
|
include_context 'ProjectPolicyTable context'
|
2019-07-07 11:18:12 +05:30
|
|
|
include ExternalAuthorizationServiceHelpers
|
2022-08-27 11:52:29 +05:30
|
|
|
include ProjectHelpers
|
2022-11-25 23:54:43 +05:30
|
|
|
include UserHelpers
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
let(:admin) { create(:user, :admin) }
|
2016-11-03 12:29:30 +05:30
|
|
|
let(:guest) { create(:user) }
|
|
|
|
let(:author) { create(:user) }
|
|
|
|
let(:assignee) { create(:user) }
|
|
|
|
let(:reporter) { create(:user) }
|
2023-03-04 22:38:38 +05:30
|
|
|
let(:maintainer) { create(:user) }
|
|
|
|
let(:owner) { create(:user) }
|
2016-11-03 12:29:30 +05:30
|
|
|
let(:group) { create(:group, :public) }
|
|
|
|
let(:reporter_from_group_link) { create(:user) }
|
2021-09-04 01:27:46 +05:30
|
|
|
let(:non_member) { create(:user) }
|
|
|
|
let(:support_bot) { User.support_bot }
|
2022-08-13 15:12:31 +05:30
|
|
|
let(:alert_bot) { User.alert_bot }
|
2016-11-03 12:29:30 +05:30
|
|
|
|
|
|
|
def permissions(user, issue)
|
2017-09-10 17:25:29 +05:30
|
|
|
described_class.new(user, issue)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
shared_examples 'support bot with service desk enabled' do
|
|
|
|
before do
|
|
|
|
allow(::Gitlab::IncomingEmail).to receive(:enabled?) { true }
|
|
|
|
allow(::Gitlab::IncomingEmail).to receive(:supports_wildcard?) { true }
|
|
|
|
|
|
|
|
project.update!(service_desk_enabled: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows support_bot to read issues, create and set metadata on new issues' do
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(support_bot, issue)).to be_allowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
|
|
|
expect(permissions(support_bot, issue_no_assignee)).to be_allowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
|
|
|
expect(permissions(support_bot, new_issue)).to be_allowed(:create_issue, :set_issue_metadata, :set_confidentiality)
|
2021-09-04 01:27:46 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'support bot with service desk disabled' do
|
2021-11-11 11:23:49 +05:30
|
|
|
it 'does not allow support_bot to read issues, create and set metadata on new issues' do
|
|
|
|
expect(permissions(support_bot, issue)).to be_disallowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
|
|
|
expect(permissions(support_bot, issue_no_assignee)).to be_disallowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
|
|
|
expect(permissions(support_bot, new_issue)).to be_disallowed(:create_issue, :set_issue_metadata, :set_confidentiality)
|
2021-09-04 01:27:46 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
shared_examples 'alert bot' do
|
|
|
|
it 'allows alert_bot to read and set metadata on issues' do
|
|
|
|
expect(permissions(alert_bot, issue)).to be_allowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
|
|
|
expect(permissions(alert_bot, issue_no_assignee)).to be_allowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
|
|
|
expect(permissions(alert_bot, new_issue)).to be_allowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
shared_examples 'grants the expected permissions' do |policy|
|
|
|
|
specify do
|
|
|
|
enable_admin_mode!(user) if admin_mode
|
|
|
|
update_feature_access_level(project, feature_access_level)
|
|
|
|
|
|
|
|
if expected_count == 1
|
|
|
|
expect(permissions(user, issue)).to be_allowed(policy)
|
|
|
|
else
|
|
|
|
expect(permissions(user, issue)).to be_disallowed(policy)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
context 'a private project' do
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:project) { create(:project, :private) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:issue) { create(:issue, project: project, assignees: [assignee], author: author) }
|
2016-11-03 12:29:30 +05:30
|
|
|
let(:issue_no_assignee) { create(:issue, project: project) }
|
2021-09-04 01:27:46 +05:30
|
|
|
let(:new_issue) { build(:issue, project: project, assignees: [assignee], author: author) }
|
2016-11-03 12:29:30 +05:30
|
|
|
|
|
|
|
before do
|
2018-03-17 18:26:18 +05:30
|
|
|
project.add_guest(guest)
|
|
|
|
project.add_guest(author)
|
|
|
|
project.add_guest(assignee)
|
|
|
|
project.add_reporter(reporter)
|
2016-11-03 12:29:30 +05:30
|
|
|
|
|
|
|
group.add_reporter(reporter_from_group_link)
|
|
|
|
|
|
|
|
create(:project_group_link, group: group, project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows guests to read issues' do
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(permissions(guest, issue)).to be_allowed(:read_issue, :read_issue_iid)
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(permissions(guest, issue)).to be_disallowed(:update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality, :mark_note_as_confidential)
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(permissions(guest, issue_no_assignee)).to be_allowed(:read_issue, :read_issue_iid)
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(guest, issue_no_assignee)).to be_disallowed(:update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
2021-09-04 01:27:46 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(guest, new_issue)).to be_allowed(:create_issue, :set_issue_metadata, :set_confidentiality)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
it 'allows reporters to read, update, admin and create confidential notes' do
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(reporter, issue)).to be_allowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
|
|
|
expect(permissions(reporter, issue_no_assignee)).to be_allowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(permissions(reporter, new_issue)).to be_allowed(:create_issue, :set_issue_metadata, :set_confidentiality, :mark_note_as_confidential)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows reporters from group links to read, update, and admin issues' do
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(reporter_from_group_link, issue)).to be_allowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
|
|
|
expect(permissions(reporter_from_group_link, new_issue)).to be_allowed(:create_issue, :set_issue_metadata, :set_confidentiality)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows issue authors to read and update their issues' do
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(permissions(author, issue)).to be_allowed(:read_issue, :read_issue_iid, :update_issue)
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(author, issue)).to be_disallowed(:admin_issue, :set_issue_metadata, :set_confidentiality)
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(permissions(author, issue_no_assignee)).to be_allowed(:read_issue, :read_issue_iid)
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(author, issue_no_assignee)).to be_disallowed(:update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
2021-09-04 01:27:46 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(author, new_issue)).to be_allowed(:create_issue, :set_issue_metadata, :set_confidentiality)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows issue assignees to read and update their issues' do
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(permissions(assignee, issue)).to be_allowed(:read_issue, :read_issue_iid, :update_issue)
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(assignee, issue)).to be_disallowed(:admin_issue, :set_issue_metadata, :set_confidentiality)
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(permissions(assignee, issue_no_assignee)).to be_allowed(:read_issue, :read_issue_iid)
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(assignee, issue_no_assignee)).to be_disallowed(:update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
2021-09-04 01:27:46 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(assignee, new_issue)).to be_allowed(:create_issue, :set_issue_metadata, :set_confidentiality)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
it 'does not allow non-members to read, update or create issues' do
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(non_member, issue)).to be_disallowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
|
|
|
expect(permissions(non_member, issue_no_assignee)).to be_disallowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
|
|
|
expect(permissions(non_member, new_issue)).to be_disallowed(:create_issue, :set_issue_metadata, :set_confidentiality)
|
2021-09-04 01:27:46 +05:30
|
|
|
end
|
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
it_behaves_like 'alert bot'
|
2021-09-04 01:27:46 +05:30
|
|
|
it_behaves_like 'support bot with service desk disabled'
|
|
|
|
it_behaves_like 'support bot with service desk enabled'
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
context 'with confidential issues' do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:confidential_issue) { create(:issue, :confidential, project: project, assignees: [assignee], author: author) }
|
2016-11-03 12:29:30 +05:30
|
|
|
let(:confidential_issue_no_assignee) { create(:issue, :confidential, project: project) }
|
|
|
|
|
|
|
|
it 'does not allow non-members to read confidential issues' do
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(permissions(non_member, confidential_issue)).to be_disallowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue)
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(non_member, confidential_issue_no_assignee)).to be_disallowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not allow guests to read confidential issues' do
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(permissions(guest, confidential_issue)).to be_disallowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue)
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(guest, confidential_issue_no_assignee)).to be_disallowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows reporters to read, update, and admin confidential issues' do
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(reporter, confidential_issue)).to be_allowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
|
|
|
expect(permissions(reporter, confidential_issue_no_assignee)).to be_allowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows reporters from group links to read, update, and admin confidential issues' do
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(reporter_from_group_link, confidential_issue)).to be_allowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
|
|
|
expect(permissions(reporter_from_group_link, confidential_issue_no_assignee)).to be_allowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows issue authors to read and update their confidential issues' do
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(permissions(author, confidential_issue)).to be_allowed(:read_issue, :read_issue_iid, :update_issue)
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(author, confidential_issue)).to be_disallowed(:admin_issue, :set_issue_metadata, :set_confidentiality)
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(permissions(author, confidential_issue_no_assignee)).to be_disallowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue)
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(author, confidential_issue_no_assignee)).to be_disallowed(:admin_issue, :set_issue_metadata, :set_confidentiality)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
2020-03-28 13:19:24 +05:30
|
|
|
it 'does not allow issue author to read or update confidential issue moved to an private project' do
|
2020-10-24 23:57:45 +05:30
|
|
|
confidential_issue.project = create(:project, :private)
|
2020-03-28 13:19:24 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(author, confidential_issue)).to be_disallowed(:read_issue, :read_issue_iid, :update_issue, :set_issue_metadata, :set_confidentiality)
|
2020-03-28 13:19:24 +05:30
|
|
|
end
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
it 'allows issue assignees to read and update their confidential issues' do
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(permissions(assignee, confidential_issue)).to be_allowed(:read_issue, :read_issue_iid, :update_issue)
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(assignee, confidential_issue)).to be_disallowed(:admin_issue, :set_issue_metadata, :set_confidentiality)
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(assignee, confidential_issue_no_assignee)).to be_disallowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
2020-03-28 13:19:24 +05:30
|
|
|
|
|
|
|
it 'does not allow issue assignees to read or update confidential issue moved to an private project' do
|
2020-10-24 23:57:45 +05:30
|
|
|
confidential_issue.project = create(:project, :private)
|
2020-03-28 13:19:24 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(assignee, confidential_issue)).to be_disallowed(:read_issue, :read_issue_iid, :update_issue, :set_issue_metadata, :set_confidentiality)
|
2020-03-28 13:19:24 +05:30
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'a public project' do
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:project) { create(:project, :public) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:issue) { create(:issue, project: project, assignees: [assignee], author: author) }
|
2016-11-03 12:29:30 +05:30
|
|
|
let(:issue_no_assignee) { create(:issue, project: project) }
|
2018-12-05 23:21:45 +05:30
|
|
|
let(:issue_locked) { create(:issue, :locked, project: project, author: author, assignees: [assignee]) }
|
2021-09-04 01:27:46 +05:30
|
|
|
let(:new_issue) { build(:issue, project: project) }
|
2016-11-03 12:29:30 +05:30
|
|
|
|
|
|
|
before do
|
2018-03-17 18:26:18 +05:30
|
|
|
project.add_guest(guest)
|
|
|
|
project.add_reporter(reporter)
|
2023-03-04 22:38:38 +05:30
|
|
|
project.add_maintainer(maintainer)
|
|
|
|
project.add_owner(owner)
|
2016-11-03 12:29:30 +05:30
|
|
|
|
|
|
|
group.add_reporter(reporter_from_group_link)
|
|
|
|
|
|
|
|
create(:project_group_link, group: group, project: project)
|
|
|
|
end
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
it 'does not allow anonymous user to create todos' do
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(permissions(nil, issue)).to be_allowed(:read_issue)
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(nil, issue)).to be_disallowed(:create_todo, :update_subscription, :set_issue_metadata, :set_confidentiality)
|
|
|
|
expect(permissions(nil, new_issue)).to be_disallowed(:create_issue, :set_issue_metadata, :set_confidentiality)
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
it 'allows guests to read issues' do
|
2021-09-04 01:27:46 +05:30
|
|
|
expect(permissions(guest, issue)).to be_allowed(:read_issue, :read_issue_iid, :create_todo, :update_subscription)
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(guest, issue)).to be_disallowed(:update_issue, :admin_issue, :reopen_issue, :set_issue_metadata, :set_confidentiality)
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(permissions(guest, issue_no_assignee)).to be_allowed(:read_issue, :read_issue_iid)
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(guest, issue_no_assignee)).to be_disallowed(:update_issue, :admin_issue, :reopen_issue, :set_issue_metadata, :set_confidentiality)
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
expect(permissions(guest, issue_locked)).to be_allowed(:read_issue, :read_issue_iid)
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(guest, issue_locked)).to be_disallowed(:update_issue, :admin_issue, :reopen_issue, :set_issue_metadata, :set_confidentiality)
|
2021-09-04 01:27:46 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(guest, new_issue)).to be_allowed(:create_issue, :set_issue_metadata, :set_confidentiality)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
it 'allows reporters to read, update, reopen, and admin issues' do
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(reporter, issue)).to be_allowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue, :reopen_issue, :set_issue_metadata, :set_confidentiality)
|
|
|
|
expect(permissions(reporter, issue_no_assignee)).to be_allowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue, :reopen_issue, :set_issue_metadata, :set_confidentiality)
|
|
|
|
expect(permissions(reporter, issue_locked)).to be_allowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
2018-11-20 20:47:30 +05:30
|
|
|
expect(permissions(reporter, issue_locked)).to be_disallowed(:reopen_issue)
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(reporter, new_issue)).to be_allowed(:create_issue, :set_issue_metadata, :set_confidentiality)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
it 'allows reporters from group links to read, update, reopen and admin issues' do
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(reporter_from_group_link, issue)).to be_allowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue, :reopen_issue, :set_issue_metadata, :set_confidentiality)
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(permissions(reporter_from_group_link, issue_no_assignee)).to be_allowed(:reopen_issue)
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(reporter_from_group_link, issue_locked)).to be_allowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
2018-11-20 20:47:30 +05:30
|
|
|
expect(permissions(reporter_from_group_link, issue_locked)).to be_disallowed(:reopen_issue)
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(reporter, new_issue)).to be_allowed(:create_issue, :set_issue_metadata, :set_confidentiality)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
it 'allows issue authors to read, reopen and update their issues' do
|
|
|
|
expect(permissions(author, issue)).to be_allowed(:read_issue, :read_issue_iid, :update_issue, :reopen_issue)
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(author, issue)).to be_disallowed(:admin_issue, :set_issue_metadata, :set_confidentiality)
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(permissions(author, issue_no_assignee)).to be_allowed(:read_issue, :read_issue_iid)
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(author, issue_no_assignee)).to be_disallowed(:update_issue, :admin_issue, :reopen_issue, :set_issue_metadata, :set_confidentiality)
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
expect(permissions(author, issue_locked)).to be_allowed(:read_issue, :read_issue_iid, :update_issue)
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(author, issue_locked)).to be_disallowed(:admin_issue, :reopen_issue, :set_issue_metadata, :set_confidentiality)
|
2021-09-04 01:27:46 +05:30
|
|
|
|
|
|
|
expect(permissions(author, new_issue)).to be_allowed(:create_issue)
|
|
|
|
expect(permissions(author, new_issue)).to be_disallowed(:set_issue_metadata)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
it 'allows issue assignees to read, reopen and update their issues' do
|
|
|
|
expect(permissions(assignee, issue)).to be_allowed(:read_issue, :read_issue_iid, :update_issue, :reopen_issue)
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(assignee, issue)).to be_disallowed(:admin_issue, :set_issue_metadata, :set_confidentiality)
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(permissions(assignee, issue_no_assignee)).to be_allowed(:read_issue, :read_issue_iid)
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(assignee, issue_no_assignee)).to be_disallowed(:update_issue, :admin_issue, :reopen_issue, :set_issue_metadata, :set_confidentiality)
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
expect(permissions(assignee, issue_locked)).to be_allowed(:read_issue, :read_issue_iid, :update_issue)
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(assignee, issue_locked)).to be_disallowed(:admin_issue, :reopen_issue, :set_issue_metadata, :set_confidentiality)
|
2021-09-04 01:27:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows non-members to read and create issues' do
|
|
|
|
expect(permissions(non_member, issue)).to be_allowed(:read_issue, :read_issue_iid)
|
|
|
|
expect(permissions(non_member, issue_no_assignee)).to be_allowed(:read_issue, :read_issue_iid)
|
|
|
|
expect(permissions(non_member, new_issue)).to be_allowed(:create_issue)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows non-members to read issues' do
|
|
|
|
expect(permissions(non_member, issue)).to be_allowed(:read_issue, :read_issue_iid)
|
|
|
|
expect(permissions(non_member, issue_no_assignee)).to be_allowed(:read_issue, :read_issue_iid)
|
|
|
|
end
|
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
it 'does not allow non-members to update, admin or set metadata except for set confidential flag' do
|
|
|
|
expect(permissions(non_member, issue)).to be_disallowed(:update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
|
|
|
expect(permissions(non_member, issue_no_assignee)).to be_disallowed(:update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
2021-09-04 01:27:46 +05:30
|
|
|
expect(permissions(non_member, new_issue)).to be_disallowed(:set_issue_metadata)
|
2021-11-11 11:23:49 +05:30
|
|
|
# this is allowed for non-members in a public project, as we want to let users report security issues
|
|
|
|
# see https://gitlab.com/gitlab-org/gitlab/-/issues/337665
|
|
|
|
expect(permissions(non_member, new_issue)).to be_allowed(:set_confidentiality)
|
2021-09-04 01:27:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows support_bot to read issues' do
|
|
|
|
# support_bot is still allowed read access in public projects through :public_access permission,
|
|
|
|
# see project_policy public_access rules policy (rule { can?(:public_access) }.policy {...})
|
|
|
|
expect(permissions(support_bot, issue)).to be_allowed(:read_issue, :read_issue_iid)
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(support_bot, issue)).to be_disallowed(:update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
2021-09-04 01:27:46 +05:30
|
|
|
|
|
|
|
expect(permissions(support_bot, issue_no_assignee)).to be_allowed(:read_issue, :read_issue_iid)
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(support_bot, issue_no_assignee)).to be_disallowed(:update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
2021-09-04 01:27:46 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(support_bot, new_issue)).to be_disallowed(:create_issue, :set_issue_metadata, :set_confidentiality)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
it_behaves_like 'alert bot'
|
2021-09-04 01:27:46 +05:30
|
|
|
it_behaves_like 'support bot with service desk enabled'
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
context 'when issues are private' do
|
|
|
|
before do
|
2020-10-24 23:57:45 +05:30
|
|
|
project.project_feature.update!(issues_access_level: ProjectFeature::PRIVATE)
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
2021-09-04 01:27:46 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
let(:issue) { create(:issue, project: project, author: author) }
|
|
|
|
let(:visitor) { create(:user) }
|
|
|
|
|
|
|
|
it 'forbids visitors from viewing issues' do
|
|
|
|
expect(permissions(visitor, issue)).to be_disallowed(:read_issue)
|
|
|
|
end
|
2022-08-27 11:52:29 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
it 'forbids visitors from commenting' do
|
|
|
|
expect(permissions(visitor, issue)).to be_disallowed(:create_note)
|
|
|
|
end
|
2022-08-27 11:52:29 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
it 'forbids visitors from subscribing' do
|
|
|
|
expect(permissions(visitor, issue)).to be_disallowed(:update_subscription)
|
|
|
|
end
|
2022-08-27 11:52:29 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
it 'allows guests to view' do
|
|
|
|
expect(permissions(guest, issue)).to be_allowed(:read_issue)
|
|
|
|
end
|
2022-08-27 11:52:29 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
it 'allows guests to comment' do
|
|
|
|
expect(permissions(guest, issue)).to be_allowed(:create_note)
|
|
|
|
end
|
2022-08-27 11:52:29 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
it 'allows guests to subscribe' do
|
|
|
|
expect(permissions(guest, issue)).to be_allowed(:update_subscription)
|
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
context 'when admin mode is enabled', :enable_admin_mode do
|
|
|
|
it 'allows admins to view' do
|
|
|
|
expect(permissions(admin, issue)).to be_allowed(:read_issue)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows admins to comment' do
|
|
|
|
expect(permissions(admin, issue)).to be_allowed(:create_note)
|
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
context 'when admin mode is disabled' do
|
|
|
|
it 'forbids admins to view' do
|
|
|
|
expect(permissions(admin, issue)).to be_disallowed(:read_issue)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'forbids admins to comment' do
|
|
|
|
expect(permissions(admin, issue)).to be_disallowed(:create_note)
|
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
2021-09-04 01:27:46 +05:30
|
|
|
|
|
|
|
it 'does not allow non-members to update or create issues' do
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(non_member, issue)).to be_disallowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
|
|
|
expect(permissions(non_member, issue_no_assignee)).to be_disallowed(:update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
|
|
|
expect(permissions(non_member, new_issue)).to be_disallowed(:create_issue, :set_issue_metadata, :set_confidentiality)
|
2021-09-04 01:27:46 +05:30
|
|
|
end
|
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
it_behaves_like 'alert bot'
|
2021-09-04 01:27:46 +05:30
|
|
|
it_behaves_like 'support bot with service desk disabled'
|
|
|
|
it_behaves_like 'support bot with service desk enabled'
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
context 'with confidential issues' do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:confidential_issue) { create(:issue, :confidential, project: project, assignees: [assignee], author: author) }
|
2016-11-03 12:29:30 +05:30
|
|
|
let(:confidential_issue_no_assignee) { create(:issue, :confidential, project: project) }
|
|
|
|
|
|
|
|
it 'does not allow guests to read confidential issues' do
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(permissions(guest, confidential_issue)).to be_disallowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue)
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(guest, confidential_issue_no_assignee)).to be_disallowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows reporters to read, update, and admin confidential issues' do
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(permissions(reporter, confidential_issue)).to be_allowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue)
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(reporter, confidential_issue_no_assignee)).to be_allowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows reporter from group links to read, update, and admin confidential issues' do
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(permissions(reporter_from_group_link, confidential_issue)).to be_allowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue)
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(reporter_from_group_link, confidential_issue_no_assignee)).to be_allowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows issue authors to read and update their confidential issues' do
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(permissions(author, confidential_issue)).to be_allowed(:read_issue, :read_issue_iid, :update_issue)
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(author, confidential_issue)).to be_disallowed(:admin_issue, :set_issue_metadata, :set_confidentiality)
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(author, confidential_issue_no_assignee)).to be_disallowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows issue assignees to read and update their confidential issues' do
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(permissions(assignee, confidential_issue)).to be_allowed(:read_issue, :read_issue_iid, :update_issue)
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(assignee, confidential_issue)).to be_disallowed(:admin_issue, :set_issue_metadata, :set_confidentiality)
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(permissions(assignee, confidential_issue_no_assignee)).to be_disallowed(:read_issue, :read_issue_iid, :update_issue, :admin_issue, :set_issue_metadata, :set_confidentiality)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
2023-03-04 22:38:38 +05:30
|
|
|
|
|
|
|
it 'allows admins to read confidential issues' do
|
|
|
|
expect(permissions(admin, confidential_issue)).to be_allowed(:read_issue)
|
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
2021-10-27 15:23:28 +05:30
|
|
|
|
|
|
|
context 'with a hidden issue' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:banned_user) { create(:user, :banned) }
|
|
|
|
let(:hidden_issue) { create(:issue, project: project, author: banned_user) }
|
|
|
|
|
|
|
|
it 'does not allow non-admin user to read the issue' do
|
|
|
|
expect(permissions(user, hidden_issue)).not_to be_allowed(:read_issue)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows admin to read the issue', :enable_admin_mode do
|
|
|
|
expect(permissions(admin, hidden_issue)).to be_allowed(:read_issue)
|
|
|
|
end
|
|
|
|
end
|
2023-03-04 22:38:38 +05:30
|
|
|
|
|
|
|
context 'when accounting for notes widget' do
|
|
|
|
let(:policy) { described_class.new(reporter, note) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
widgets_per_type = WorkItems::Type::WIDGETS_FOR_TYPE.dup
|
|
|
|
widgets_per_type[:task] = [::WorkItems::Widgets::Description]
|
|
|
|
stub_const('WorkItems::Type::WIDGETS_FOR_TYPE', widgets_per_type)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and notes widget is disabled for task' do
|
|
|
|
let(:task) { create(:work_item, :task, project: project) }
|
|
|
|
|
|
|
|
it 'does not allow accessing notes' do
|
|
|
|
# if notes widget is disabled not even maintainer can access notes
|
|
|
|
expect(permissions(maintainer, task)).to be_disallowed(:create_note, :read_note, :mark_note_as_confidential, :read_internal_note)
|
|
|
|
expect(permissions(admin, task)).to be_disallowed(:create_note, :read_note, :read_internal_note, :mark_note_as_confidential, :set_note_created_at)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and notes widget is enabled for issue' do
|
|
|
|
it 'allows accessing notes' do
|
|
|
|
# with notes widget enabled, even guests can access notes
|
|
|
|
expect(permissions(guest, issue)).to be_allowed(:create_note, :read_note)
|
|
|
|
expect(permissions(guest, issue)).to be_disallowed(:read_internal_note, :mark_note_as_confidential, :set_note_created_at)
|
|
|
|
expect(permissions(reporter, issue)).to be_allowed(:create_note, :read_note, :read_internal_note, :mark_note_as_confidential)
|
|
|
|
expect(permissions(maintainer, issue)).to be_allowed(:create_note, :read_note, :read_internal_note, :mark_note_as_confidential)
|
|
|
|
expect(permissions(owner, issue)).to be_allowed(:create_note, :read_note, :read_internal_note, :mark_note_as_confidential, :set_note_created_at)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
context 'with external authorization enabled' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project) { create(:project, :public) }
|
|
|
|
let(:issue) { create(:issue, project: project) }
|
|
|
|
let(:policies) { described_class.new(user, issue) }
|
|
|
|
|
|
|
|
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_issue_iid)
|
|
|
|
end
|
|
|
|
end
|
2022-05-07 20:08:51 +05:30
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
describe 'crm permissions' do
|
2022-05-07 20:08:51 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:subgroup) { create(:group, :crm_enabled, parent: create(:group, :crm_enabled)) }
|
|
|
|
let(:project) { create(:project, group: subgroup) }
|
|
|
|
let(:issue) { create(:issue, project: project) }
|
|
|
|
let(:policies) { described_class.new(user, issue) }
|
|
|
|
|
|
|
|
context 'when project reporter' do
|
|
|
|
it 'is disallowed' do
|
|
|
|
project.add_reporter(user)
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
expect(policies).to be_disallowed(:read_crm_contacts)
|
2022-05-07 20:08:51 +05:30
|
|
|
expect(policies).to be_disallowed(:set_issue_crm_contacts)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when subgroup reporter' do
|
|
|
|
it 'is allowed' do
|
|
|
|
subgroup.add_reporter(user)
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
expect(policies).to be_disallowed(:read_crm_contacts)
|
2022-05-07 20:08:51 +05:30
|
|
|
expect(policies).to be_disallowed(:set_issue_crm_contacts)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when root group reporter' do
|
|
|
|
it 'is allowed' do
|
|
|
|
subgroup.parent.add_reporter(user)
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
expect(policies).to be_allowed(:read_crm_contacts)
|
2022-05-07 20:08:51 +05:30
|
|
|
expect(policies).to be_allowed(:set_issue_crm_contacts)
|
|
|
|
end
|
|
|
|
end
|
2022-07-16 23:28:13 +05:30
|
|
|
|
|
|
|
context 'when crm disabled on subgroup' do
|
|
|
|
let(:subgroup) { create(:group, parent: create(:group, :crm_enabled)) }
|
|
|
|
|
|
|
|
it 'is disallowed' do
|
|
|
|
subgroup.parent.add_reporter(user)
|
|
|
|
|
|
|
|
expect(policies).to be_disallowed(:read_crm_contacts)
|
|
|
|
expect(policies).to be_disallowed(:set_issue_crm_contacts)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
context 'when personal namespace' do
|
2022-07-16 23:28:13 +05:30
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
|
|
|
it 'is disallowed' do
|
|
|
|
project.add_reporter(user)
|
|
|
|
|
|
|
|
expect(policies).to be_disallowed(:read_crm_contacts)
|
|
|
|
expect(policies).to be_disallowed(:set_issue_crm_contacts)
|
|
|
|
end
|
|
|
|
end
|
2022-05-07 20:08:51 +05:30
|
|
|
end
|
2022-08-27 11:52:29 +05:30
|
|
|
|
|
|
|
context 'when user is an inherited member from the group' do
|
|
|
|
let(:user) { create_user_from_membership(group, membership) }
|
|
|
|
let(:project) { create(:project, project_level, group: group) }
|
|
|
|
let(:issue) { create(:issue, project: project) }
|
|
|
|
|
|
|
|
context 'and policy allows guest access' do
|
|
|
|
where(:project_level, :feature_access_level, :membership, :admin_mode, :expected_count) do
|
|
|
|
permission_table_for_guest_feature_access
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
it_behaves_like 'grants the expected permissions', :read_issue
|
|
|
|
it_behaves_like 'grants the expected permissions', :read_issue_iid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and policy allows reporter access' do
|
|
|
|
where(:project_level, :feature_access_level, :membership, :admin_mode, :expected_count) do
|
|
|
|
permission_table_for_reporter_issue_access
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
it_behaves_like 'grants the expected permissions', :update_issue
|
|
|
|
it_behaves_like 'grants the expected permissions', :admin_issue
|
|
|
|
it_behaves_like 'grants the expected permissions', :set_issue_metadata
|
|
|
|
it_behaves_like 'grants the expected permissions', :set_confidentiality
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|