2017-08-30 10:57:50 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2019-03-04 13:37:08 -05:00
|
|
|
describe NotePolicy do
|
2017-08-30 10:57:50 -04:00
|
|
|
describe '#rules' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project) { create(:project, :public) }
|
|
|
|
let(:issue) { create(:issue, project: project) }
|
2019-03-04 13:37:08 -05:00
|
|
|
let(:noteable) { issue }
|
|
|
|
let(:policy) { described_class.new(user, note) }
|
|
|
|
let(:note) { create(:note, noteable: noteable, author: user, project: project) }
|
2017-08-30 10:57:50 -04:00
|
|
|
|
2018-11-28 14:04:15 -05:00
|
|
|
shared_examples_for 'a discussion with a private noteable' do
|
|
|
|
context 'when the note author can no longer see the noteable' do
|
|
|
|
it 'can not edit nor read the note' do
|
|
|
|
expect(policy).to be_disallowed(:admin_note)
|
|
|
|
expect(policy).to be_disallowed(:resolve_note)
|
|
|
|
expect(policy).to be_disallowed(:read_note)
|
2019-01-15 03:21:28 -05:00
|
|
|
expect(policy).to be_disallowed(:award_emoji)
|
2018-11-28 14:04:15 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the note author can still see the noteable' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can edit the note' do
|
|
|
|
expect(policy).to be_allowed(:admin_note)
|
|
|
|
expect(policy).to be_allowed(:resolve_note)
|
|
|
|
expect(policy).to be_allowed(:read_note)
|
2019-01-15 03:21:28 -05:00
|
|
|
expect(policy).to be_allowed(:award_emoji)
|
2018-11-28 14:04:15 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-04 13:37:08 -05:00
|
|
|
context 'when the noteable is a commit' do
|
|
|
|
let(:commit) { project.repository.head_commit }
|
|
|
|
let(:note) { create(:note_on_commit, commit_id: commit.id, author: user, project: project) }
|
|
|
|
|
|
|
|
context 'when the project is private' do
|
|
|
|
let(:project) { create(:project, :private, :repository) }
|
|
|
|
|
|
|
|
it_behaves_like 'a discussion with a private noteable'
|
|
|
|
end
|
2018-11-28 14:04:15 -05:00
|
|
|
|
2019-03-04 13:37:08 -05:00
|
|
|
context 'when the project is public' do
|
|
|
|
context 'when repository access level is private' do
|
|
|
|
let(:project) { create(:project, :public, :repository, :repository_private) }
|
|
|
|
|
|
|
|
it_behaves_like 'a discussion with a private noteable'
|
2018-11-28 14:04:15 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-30 10:57:50 -04:00
|
|
|
context 'when the project is public' do
|
|
|
|
context 'when the note author is not a project member' do
|
|
|
|
it 'can edit a note' do
|
2019-03-04 13:37:08 -05:00
|
|
|
expect(policy).to be_allowed(:admin_note)
|
|
|
|
expect(policy).to be_allowed(:resolve_note)
|
|
|
|
expect(policy).to be_allowed(:read_note)
|
2017-08-30 10:57:50 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-28 14:04:15 -05:00
|
|
|
context 'when the noteable is a project snippet' do
|
2019-03-04 13:37:08 -05:00
|
|
|
let(:noteable) { create(:project_snippet, :public, project: project) }
|
2018-11-28 14:04:15 -05:00
|
|
|
|
2019-03-04 13:37:08 -05:00
|
|
|
it 'can edit note' do
|
|
|
|
expect(policy).to be_allowed(:admin_note)
|
|
|
|
expect(policy).to be_allowed(:resolve_note)
|
|
|
|
expect(policy).to be_allowed(:read_note)
|
2018-11-28 14:04:15 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when it is private' do
|
2019-03-04 13:37:08 -05:00
|
|
|
let(:noteable) { create(:project_snippet, :private, project: project) }
|
|
|
|
|
|
|
|
it_behaves_like 'a discussion with a private noteable'
|
2018-11-28 14:04:15 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the noteable is a personal snippet' do
|
2019-03-04 13:37:08 -05:00
|
|
|
let(:noteable) { create(:personal_snippet, :public) }
|
2017-09-01 08:03:57 -04:00
|
|
|
|
2019-03-04 13:37:08 -05:00
|
|
|
it 'can edit note' do
|
|
|
|
expect(policy).to be_allowed(:admin_note)
|
|
|
|
expect(policy).to be_allowed(:resolve_note)
|
|
|
|
expect(policy).to be_allowed(:read_note)
|
2017-09-01 08:03:57 -04:00
|
|
|
end
|
2018-11-28 14:04:15 -05:00
|
|
|
|
|
|
|
context 'when it is private' do
|
2019-03-04 13:37:08 -05:00
|
|
|
let(:noteable) { create(:personal_snippet, :private) }
|
2018-11-28 14:04:15 -05:00
|
|
|
|
2019-03-04 13:37:08 -05:00
|
|
|
it 'can not edit nor read the note' do
|
|
|
|
expect(policy).to be_disallowed(:admin_note)
|
|
|
|
expect(policy).to be_disallowed(:resolve_note)
|
|
|
|
expect(policy).to be_disallowed(:read_note)
|
2018-11-28 14:04:15 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a discussion is confidential' do
|
|
|
|
before do
|
|
|
|
issue.update_attribute(:confidential, true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a discussion with a private noteable'
|
2017-09-01 08:03:57 -04:00
|
|
|
end
|
|
|
|
|
2017-08-30 10:57:50 -04:00
|
|
|
context 'when a discussion is locked' do
|
|
|
|
before do
|
|
|
|
issue.update_attribute(:discussion_locked, true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the note author is a project member' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
2017-09-01 08:03:57 -04:00
|
|
|
it 'can edit a note' do
|
2019-03-04 13:37:08 -05:00
|
|
|
expect(policy).to be_allowed(:admin_note)
|
|
|
|
expect(policy).to be_allowed(:resolve_note)
|
|
|
|
expect(policy).to be_allowed(:read_note)
|
2017-08-30 10:57:50 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the note author is not a project member' do
|
|
|
|
it 'can not edit a note' do
|
2019-03-04 13:37:08 -05:00
|
|
|
expect(policy).to be_disallowed(:admin_note)
|
|
|
|
expect(policy).to be_disallowed(:resolve_note)
|
2017-08-30 10:57:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'can read a note' do
|
2019-03-04 13:37:08 -05:00
|
|
|
expect(policy).to be_allowed(:read_note)
|
2017-08-30 10:57:50 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|