2016-10-13 11:53:01 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe IssuePolicy do
|
2017-04-25 08:28:55 -04:00
|
|
|
let(:guest) { create(:user) }
|
|
|
|
let(:author) { create(:user) }
|
|
|
|
let(:assignee) { create(:user) }
|
|
|
|
let(:reporter) { create(:user) }
|
|
|
|
let(:group) { create(:group, :public) }
|
|
|
|
let(:reporter_from_group_link) { create(:user) }
|
|
|
|
|
|
|
|
def permissions(user, issue)
|
2017-04-06 17:09:58 -04:00
|
|
|
described_class.new(user, issue)
|
2017-04-25 08:28:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'a private project' do
|
|
|
|
let(:non_member) { create(:user) }
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project, :private) }
|
2017-05-04 16:55:36 -04:00
|
|
|
let(:issue) { create(:issue, project: project, assignees: [assignee], author: author) }
|
2017-04-25 08:28:55 -04:00
|
|
|
let(:issue_no_assignee) { create(:issue, project: project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.team << [guest, :guest]
|
|
|
|
project.team << [author, :guest]
|
|
|
|
project.team << [assignee, :guest]
|
|
|
|
project.team << [reporter, :reporter]
|
|
|
|
|
|
|
|
group.add_reporter(reporter_from_group_link)
|
|
|
|
|
|
|
|
create(:project_group_link, group: group, project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not allow non-members to read issues' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(non_member, issue)).to be_disallowed(:read_issue, :update_issue, :admin_issue)
|
|
|
|
expect(permissions(non_member, issue_no_assignee)).to be_disallowed(:read_issue, :update_issue, :admin_issue)
|
2017-04-25 08:28:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows guests to read issues' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(guest, issue)).to be_allowed(:read_issue)
|
|
|
|
expect(permissions(guest, issue)).to be_disallowed(:update_issue, :admin_issue)
|
2017-04-25 08:28:55 -04:00
|
|
|
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(guest, issue_no_assignee)).to be_allowed(:read_issue)
|
|
|
|
expect(permissions(guest, issue_no_assignee)).to be_disallowed(:update_issue, :admin_issue)
|
2017-04-25 08:28:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows reporters to read, update, and admin issues' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(reporter, issue)).to be_allowed(:read_issue, :update_issue, :admin_issue)
|
|
|
|
expect(permissions(reporter, issue_no_assignee)).to be_allowed(:read_issue, :update_issue, :admin_issue)
|
2017-04-25 08:28:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows reporters from group links to read, update, and admin issues' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(reporter_from_group_link, issue)).to be_allowed(:read_issue, :update_issue, :admin_issue)
|
|
|
|
expect(permissions(reporter_from_group_link, issue_no_assignee)).to be_allowed(:read_issue, :update_issue, :admin_issue)
|
2017-04-25 08:28:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows issue authors to read and update their issues' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(author, issue)).to be_allowed(:read_issue, :update_issue)
|
|
|
|
expect(permissions(author, issue)).to be_disallowed(:admin_issue)
|
2017-04-25 08:28:55 -04:00
|
|
|
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(author, issue_no_assignee)).to be_allowed(:read_issue)
|
|
|
|
expect(permissions(author, issue_no_assignee)).to be_disallowed(:update_issue, :admin_issue)
|
2017-04-25 08:28:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows issue assignees to read and update their issues' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(assignee, issue)).to be_allowed(:read_issue, :update_issue)
|
|
|
|
expect(permissions(assignee, issue)).to be_disallowed(:admin_issue)
|
2017-04-25 08:28:55 -04:00
|
|
|
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(assignee, issue_no_assignee)).to be_allowed(:read_issue)
|
|
|
|
expect(permissions(assignee, issue_no_assignee)).to be_disallowed(:update_issue, :admin_issue)
|
2017-04-25 08:28:55 -04:00
|
|
|
end
|
2016-10-13 11:53:01 -04:00
|
|
|
|
2017-04-25 08:28:55 -04:00
|
|
|
context 'with confidential issues' do
|
2017-05-04 16:55:36 -04:00
|
|
|
let(:confidential_issue) { create(:issue, :confidential, project: project, assignees: [assignee], author: author) }
|
2017-04-25 08:28:55 -04:00
|
|
|
let(:confidential_issue_no_assignee) { create(:issue, :confidential, project: project) }
|
2016-10-13 11:53:01 -04:00
|
|
|
|
2017-04-25 08:28:55 -04:00
|
|
|
it 'does not allow non-members to read confidential issues' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(non_member, confidential_issue)).to be_disallowed(:read_issue, :update_issue, :admin_issue)
|
|
|
|
expect(permissions(non_member, confidential_issue_no_assignee)).to be_disallowed(:read_issue, :update_issue, :admin_issue)
|
2017-04-25 08:28:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not allow guests to read confidential issues' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(guest, confidential_issue)).to be_disallowed(:read_issue, :update_issue, :admin_issue)
|
|
|
|
expect(permissions(guest, confidential_issue_no_assignee)).to be_disallowed(:read_issue, :update_issue, :admin_issue)
|
2017-04-25 08:28:55 -04:00
|
|
|
end
|
2016-10-13 11:53:01 -04:00
|
|
|
|
2017-04-25 08:28:55 -04:00
|
|
|
it 'allows reporters to read, update, and admin confidential issues' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(reporter, confidential_issue)).to be_allowed(:read_issue, :update_issue, :admin_issue)
|
|
|
|
expect(permissions(reporter, confidential_issue_no_assignee)).to be_allowed(:read_issue, :update_issue, :admin_issue)
|
2017-04-25 08:28:55 -04:00
|
|
|
end
|
2016-10-13 11:53:01 -04:00
|
|
|
|
2017-04-25 08:28:55 -04:00
|
|
|
it 'allows reporters from group links to read, update, and admin confidential issues' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(reporter_from_group_link, confidential_issue)).to be_allowed(:read_issue, :update_issue, :admin_issue)
|
|
|
|
expect(permissions(reporter_from_group_link, confidential_issue_no_assignee)).to be_allowed(:read_issue, :update_issue, :admin_issue)
|
2016-10-13 11:53:01 -04:00
|
|
|
end
|
|
|
|
|
2017-04-25 08:28:55 -04:00
|
|
|
it 'allows issue authors to read and update their confidential issues' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(author, confidential_issue)).to be_allowed(:read_issue, :update_issue)
|
|
|
|
expect(permissions(author, confidential_issue)).to be_disallowed(:admin_issue)
|
2016-10-13 11:53:01 -04:00
|
|
|
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(author, confidential_issue_no_assignee)).to be_disallowed(:read_issue, :update_issue, :admin_issue)
|
2017-04-25 08:28:55 -04:00
|
|
|
end
|
2016-10-13 11:53:01 -04:00
|
|
|
|
2017-04-25 08:28:55 -04:00
|
|
|
it 'allows issue assignees to read and update their confidential issues' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(assignee, confidential_issue)).to be_allowed(:read_issue, :update_issue)
|
|
|
|
expect(permissions(assignee, confidential_issue)).to be_disallowed(:admin_issue)
|
2016-10-13 11:53:01 -04:00
|
|
|
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(assignee, confidential_issue_no_assignee)).to be_disallowed(:read_issue, :update_issue, :admin_issue)
|
2016-10-13 11:53:01 -04:00
|
|
|
end
|
|
|
|
end
|
2017-04-25 08:28:55 -04:00
|
|
|
end
|
2016-10-13 11:53:01 -04:00
|
|
|
|
2017-04-25 08:28:55 -04:00
|
|
|
context 'a public project' do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project, :public) }
|
2017-05-04 16:55:36 -04:00
|
|
|
let(:issue) { create(:issue, project: project, assignees: [assignee], author: author) }
|
2017-04-25 08:28:55 -04:00
|
|
|
let(:issue_no_assignee) { create(:issue, project: project) }
|
2016-10-13 11:53:01 -04:00
|
|
|
|
2017-04-25 08:28:55 -04:00
|
|
|
before do
|
|
|
|
project.team << [guest, :guest]
|
|
|
|
project.team << [reporter, :reporter]
|
2016-10-13 11:53:01 -04:00
|
|
|
|
2017-04-25 08:28:55 -04:00
|
|
|
group.add_reporter(reporter_from_group_link)
|
2016-10-13 11:53:01 -04:00
|
|
|
|
2017-04-25 08:28:55 -04:00
|
|
|
create(:project_group_link, group: group, project: project)
|
|
|
|
end
|
2016-10-13 11:53:01 -04:00
|
|
|
|
2017-04-25 08:28:55 -04:00
|
|
|
it 'allows guests to read issues' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(guest, issue)).to be_allowed(:read_issue)
|
|
|
|
expect(permissions(guest, issue)).to be_disallowed(:update_issue, :admin_issue)
|
2017-04-25 08:28:55 -04:00
|
|
|
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(guest, issue_no_assignee)).to be_allowed(:read_issue)
|
|
|
|
expect(permissions(guest, issue_no_assignee)).to be_disallowed(:update_issue, :admin_issue)
|
2017-04-25 08:28:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows reporters to read, update, and admin issues' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(reporter, issue)).to be_allowed(:read_issue, :update_issue, :admin_issue)
|
|
|
|
expect(permissions(reporter, issue_no_assignee)).to be_allowed(:read_issue, :update_issue, :admin_issue)
|
2017-04-25 08:28:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows reporters from group links to read, update, and admin issues' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(reporter_from_group_link, issue)).to be_allowed(:read_issue, :update_issue, :admin_issue)
|
|
|
|
expect(permissions(reporter_from_group_link, issue_no_assignee)).to be_allowed(:read_issue, :update_issue, :admin_issue)
|
2017-04-25 08:28:55 -04:00
|
|
|
end
|
2016-10-13 11:53:01 -04:00
|
|
|
|
2017-04-25 08:28:55 -04:00
|
|
|
it 'allows issue authors to read and update their issues' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(author, issue)).to be_allowed(:read_issue, :update_issue)
|
|
|
|
expect(permissions(author, issue)).to be_disallowed(:admin_issue)
|
2016-10-13 11:53:01 -04:00
|
|
|
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(author, issue_no_assignee)).to be_allowed(:read_issue)
|
|
|
|
expect(permissions(author, issue_no_assignee)).to be_disallowed(:update_issue, :admin_issue)
|
2017-04-25 08:28:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows issue assignees to read and update their issues' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(assignee, issue)).to be_allowed(:read_issue, :update_issue)
|
|
|
|
expect(permissions(assignee, issue)).to be_disallowed(:admin_issue)
|
2016-10-13 11:53:01 -04:00
|
|
|
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(assignee, issue_no_assignee)).to be_allowed(:read_issue)
|
|
|
|
expect(permissions(assignee, issue_no_assignee)).to be_disallowed(:update_issue, :admin_issue)
|
2017-04-25 08:28:55 -04:00
|
|
|
end
|
2016-10-13 11:53:01 -04:00
|
|
|
|
2017-04-25 08:28:55 -04:00
|
|
|
context 'with confidential issues' do
|
2017-05-04 16:55:36 -04:00
|
|
|
let(:confidential_issue) { create(:issue, :confidential, project: project, assignees: [assignee], author: author) }
|
2017-04-25 08:28:55 -04:00
|
|
|
let(:confidential_issue_no_assignee) { create(:issue, :confidential, project: project) }
|
2016-10-13 11:53:01 -04:00
|
|
|
|
2017-04-25 08:28:55 -04:00
|
|
|
it 'does not allow guests to read confidential issues' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(guest, confidential_issue)).to be_disallowed(:read_issue, :update_issue, :admin_issue)
|
|
|
|
expect(permissions(guest, confidential_issue_no_assignee)).to be_disallowed(:read_issue, :update_issue, :admin_issue)
|
2016-10-13 11:53:01 -04:00
|
|
|
end
|
|
|
|
|
2017-04-25 08:28:55 -04:00
|
|
|
it 'allows reporters to read, update, and admin confidential issues' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(reporter, confidential_issue)).to be_allowed(:read_issue, :update_issue, :admin_issue)
|
|
|
|
expect(permissions(reporter, confidential_issue_no_assignee)).to be_allowed(:read_issue, :update_issue, :admin_issue)
|
2017-04-25 08:28:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows reporter from group links to read, update, and admin confidential issues' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(reporter_from_group_link, confidential_issue)).to be_allowed(:read_issue, :update_issue, :admin_issue)
|
|
|
|
expect(permissions(reporter_from_group_link, confidential_issue_no_assignee)).to be_allowed(:read_issue, :update_issue, :admin_issue)
|
2017-04-25 08:28:55 -04:00
|
|
|
end
|
2016-10-13 11:53:01 -04:00
|
|
|
|
2017-04-25 08:28:55 -04:00
|
|
|
it 'allows issue authors to read and update their confidential issues' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(author, confidential_issue)).to be_allowed(:read_issue, :update_issue)
|
|
|
|
expect(permissions(author, confidential_issue)).to be_disallowed(:admin_issue)
|
2017-04-25 08:28:55 -04:00
|
|
|
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(author, confidential_issue_no_assignee)).to be_disallowed(:read_issue, :update_issue, :admin_issue)
|
2017-04-25 08:28:55 -04:00
|
|
|
end
|
2016-10-13 11:53:01 -04:00
|
|
|
|
2017-04-25 08:28:55 -04:00
|
|
|
it 'allows issue assignees to read and update their confidential issues' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(assignee, confidential_issue)).to be_allowed(:read_issue, :update_issue)
|
|
|
|
expect(permissions(assignee, confidential_issue)).to be_disallowed(:admin_issue)
|
2016-10-13 11:53:01 -04:00
|
|
|
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(permissions(assignee, confidential_issue_no_assignee)).to be_disallowed(:read_issue, :update_issue, :admin_issue)
|
2016-10-13 11:53:01 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|