debian-mirror-gitlab/spec/policies/issuable_policy_spec.rb

118 lines
4.1 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe IssuablePolicy, models: true do
2022-07-16 23:28:13 +05:30
let_it_be(:user) { create(:user) }
let_it_be(:guest) { create(:user) }
let_it_be(:reporter) { create(:user) }
let_it_be(:developer) { create(:user) }
let_it_be(:project) { create(:project, :public) }
2018-03-27 19:54:05 +05:30
let(:issue) { create(:issue, project: project) }
let(:policies) { described_class.new(user, issue) }
2022-07-16 23:28:13 +05:30
before do
project.add_developer(developer)
project.add_guest(guest)
project.add_reporter(reporter)
end
def permissions(user, issue)
described_class.new(user, issue)
end
2018-03-17 18:26:18 +05:30
describe '#rules' do
2019-01-03 12:48:30 +05:30
context 'when user is author of issuable' do
let(:merge_request) { create(:merge_request, source_project: project, author: user) }
let(:policies) { described_class.new(user, merge_request) }
2021-10-29 20:43:33 +05:30
it 'allows resolving notes' do
expect(policies).to be_allowed(:resolve_note)
end
2019-01-03 12:48:30 +05:30
context 'when user is able to read project' do
it 'enables user to read and update issuables' do
2019-07-07 11:18:12 +05:30
expect(policies).to be_allowed(:read_issue, :update_issue, :reopen_issue, :read_merge_request, :update_merge_request, :reopen_merge_request)
2019-01-03 12:48:30 +05:30
end
end
2022-07-16 23:28:13 +05:30
context 'Timeline events' do
it 'allows non-members to read time line events' do
expect(permissions(guest, issue)).to be_allowed(:read_incident_management_timeline_event)
end
it 'disallows reporters from managing timeline events' do
expect(permissions(reporter, issue)).to be_disallowed(:admin_incident_management_timeline_event)
end
it 'allows developers to manage timeline events' do
expect(permissions(developer, issue)).to be_allowed(:admin_incident_management_timeline_event)
end
end
2019-01-03 12:48:30 +05:30
context 'when project is private' do
let(:project) { create(:project, :private) }
context 'when user belongs to the projects team' do
it 'enables user to read and update issuables' do
project.add_maintainer(user)
2019-07-07 11:18:12 +05:30
expect(policies).to be_allowed(:read_issue, :update_issue, :reopen_issue, :read_merge_request, :update_merge_request, :reopen_merge_request)
2019-01-03 12:48:30 +05:30
end
end
it 'disallows user from reading and updating issuables from that project' do
2019-07-07 11:18:12 +05:30
expect(policies).to be_disallowed(:read_issue, :update_issue, :reopen_issue, :read_merge_request, :update_merge_request, :reopen_merge_request)
2019-01-03 12:48:30 +05:30
end
2022-07-16 23:28:13 +05:30
context 'Timeline events' do
it 'disallows non-members from reading timeline events' do
expect(permissions(user, issue)).to be_disallowed(:read_incident_management_timeline_event)
end
it 'allows guests to read time line events' do
expect(permissions(guest, issue)).to be_allowed(:read_incident_management_timeline_event)
end
it 'disallows reporters from managing timeline events' do
expect(permissions(reporter, issue)).to be_disallowed(:admin_incident_management_timeline_event)
end
it 'allows developers to manage timeline events' do
expect(permissions(developer, issue)).to be_allowed(:admin_incident_management_timeline_event)
end
end
2019-01-03 12:48:30 +05:30
end
end
2018-03-17 18:26:18 +05:30
context 'when discussion is locked for the issuable' do
let(:issue) { create(:issue, project: project, discussion_locked: true) }
context 'when the user is not a project member' do
2020-11-24 15:15:51 +05:30
it 'can not create a note nor award emojis' do
expect(policies).to be_disallowed(:create_note, :award_emoji)
2018-03-17 18:26:18 +05:30
end
2021-10-29 20:43:33 +05:30
it 'does not allow resolving note' do
expect(policies).to be_disallowed(:resolve_note)
end
2018-03-17 18:26:18 +05:30
end
context 'when the user is a project member' do
before do
2021-10-29 20:43:33 +05:30
project.add_developer(user)
2018-03-17 18:26:18 +05:30
end
2020-11-24 15:15:51 +05:30
it 'can create a note and award emojis' do
expect(policies).to be_allowed(:create_note, :award_emoji)
2018-03-17 18:26:18 +05:30
end
2021-10-29 20:43:33 +05:30
it 'allows resolving notes' do
expect(policies).to be_allowed(:resolve_note)
end
2018-03-17 18:26:18 +05:30
end
end
end
end