Commit e7f6ecfb authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Allow guests to comment on epics

Previously only reporters and above were allowed
parent 99a00859
...@@ -8,7 +8,7 @@ class EpicPolicy < BasePolicy ...@@ -8,7 +8,7 @@ class EpicPolicy < BasePolicy
enable :read_note enable :read_note
end end
rule { can?(:update_epic) }.policy do rule { can?(:read_epic) & ~anonymous }.policy do
enable :create_note enable :create_note
end end
......
---
title: Allow guests to comment on epics
merge_request: 9783
author:
type: added
...@@ -2,137 +2,136 @@ require 'spec_helper' ...@@ -2,137 +2,136 @@ require 'spec_helper'
describe EpicPolicy do describe EpicPolicy do
include ExternalAuthorizationServiceHelpers include ExternalAuthorizationServiceHelpers
let(:user) { create(:user) } let(:user) { create(:user) }
let(:epic) { create(:epic, group: group) }
def permissions(user, group) subject { described_class.new(user, epic) }
epic = create(:epic, group: group)
described_class.new(user, epic) shared_examples 'can comment on epics' do
it { is_expected.to be_allowed(:create_note, :award_emoji) }
end end
context 'when epics feature is disabled' do shared_examples 'cannot comment on epics' do
let(:group) { create(:group, :public) } it { is_expected.to be_disallowed(:create_note, :award_emoji) }
it 'no one can read epics' do
group.add_owner(user)
expect(permissions(user, group))
.to be_disallowed(:read_epic, :read_epic_iid, :update_epic, :destroy_epic, :admin_epic, :create_epic)
end
end end
context 'when epics feature is enabled' do shared_examples 'can only read epics' do
before do it do
stub_licensed_features(epics: true) is_expected.to be_allowed(:read_epic, :read_epic_iid)
is_expected.to be_disallowed(:update_epic, :destroy_epic, :admin_epic, :create_epic)
end
end end
context 'when an epic is in a private group' do shared_examples 'can manage epics' do
let(:group) { create(:group, :private) } it { is_expected.to be_allowed(:read_epic, :read_epic_iid, :update_epic, :admin_epic, :create_epic) }
it 'anonymous user can not read epics' do
expect(permissions(nil, group))
.to be_disallowed(:read_epic, :read_epic_iid, :update_epic, :destroy_epic, :admin_epic, :create_epic)
end end
it 'user who is not a group member can not read epics' do shared_examples 'all epic permissions disabled' do
expect(permissions(user, group)) it { is_expected.to be_disallowed(:read_epic, :read_epic_iid, :update_epic, :destroy_epic, :admin_epic, :create_epic, :create_note, :award_emoji) }
.to be_disallowed(:read_epic, :read_epic_iid, :update_epic, :destroy_epic, :admin_epic, :create_epic)
end end
it 'guest group member can only read epics' do shared_examples 'group member permissions' do
context 'guest group member' do
before do
group.add_guest(user) group.add_guest(user)
end
expect(permissions(user, group)).to be_allowed(:read_epic, :read_epic_iid) it_behaves_like 'can only read epics'
expect(permissions(user, group)).to be_disallowed(:update_epic, :destroy_epic, :admin_epic, :create_epic) it_behaves_like 'can comment on epics'
end end
it 'reporter group member can manage epics' do context 'reporter group member' do
before do
group.add_reporter(user) group.add_reporter(user)
expect(permissions(user, group)).to be_disallowed(:destroy_epic)
expect(permissions(user, group))
.to be_allowed(:read_epic, :read_epic_iid, :update_epic, :admin_epic, :create_epic)
end end
it 'only group owner can destroy epics' do it_behaves_like 'can manage epics'
group.add_owner(user) it_behaves_like 'can comment on epics'
expect(permissions(user, group)) it 'cannot destroy epics' do
.to be_allowed(:read_epic, :read_epic_iid, :update_epic, :destroy_epic, :admin_epic, :create_epic) is_expected.to be_disallowed(:destroy_epic)
end end
end end
context 'when an epic is in an internal group' do context 'group owner' do
let(:group) { create(:group, :internal) } before do
group.add_owner(user)
it 'anonymous user can not read epics' do
expect(permissions(nil, group))
.to be_disallowed(:read_epic, :read_epic_iid, :update_epic, :destroy_epic, :admin_epic, :create_epic)
end end
it 'user who is not a group member can only read epics' do it_behaves_like 'can manage epics'
expect(permissions(user, group)).to be_allowed(:read_epic, :read_epic_iid) it_behaves_like 'can comment on epics'
expect(permissions(user, group)).to be_disallowed(:update_epic, :destroy_epic, :admin_epic, :create_epic)
it 'can destroy epics' do
is_expected.to be_allowed(:destroy_epic)
end
end
end end
it 'guest group member can only read epics' do context 'when epics feature is disabled' do
group.add_guest(user) let(:group) { create(:group, :public) }
expect(permissions(user, group)).to be_allowed(:read_epic, :read_epic_iid) before do
expect(permissions(user, group)).to be_disallowed(:update_epic, :destroy_epic, :admin_epic, :create_epic) group.add_owner(user)
end end
it 'reporter group member can manage epics' do it_behaves_like 'all epic permissions disabled'
group.add_reporter(user) end
expect(permissions(user, group)).to be_disallowed(:destroy_epic) context 'when epics feature is enabled' do
expect(permissions(user, group)) before do
.to be_allowed(:read_epic, :read_epic_iid, :update_epic, :admin_epic, :create_epic) stub_licensed_features(epics: true)
end end
it 'only group owner can destroy epics' do context 'when an epic is in a private group' do
group.add_owner(user) let(:group) { create(:group, :private) }
expect(permissions(user, group)) context 'anonymous user' do
.to be_allowed(:read_epic, :read_epic_iid, :update_epic, :destroy_epic, :admin_epic, :create_epic) let(:user) { nil }
end
end
context 'when an epic is in a public group' do it_behaves_like 'all epic permissions disabled'
let(:group) { create(:group, :public) } end
it 'anonymous user can only read epics' do context 'user who is not a group member' do
expect(permissions(nil, group)).to be_allowed(:read_epic, :read_epic_iid) it_behaves_like 'all epic permissions disabled'
expect(permissions(nil, group)).to be_disallowed(:update_epic, :destroy_epic, :admin_epic, :create_epic)
end end
it 'user who is not a group member can only read epics' do it_behaves_like 'group member permissions'
expect(permissions(user, group)).to be_allowed(:read_epic, :read_epic_iid)
expect(permissions(user, group)).to be_disallowed(:update_epic, :destroy_epic, :admin_epic, :create_epic)
end end
it 'guest group member can only read epics' do context 'when an epic is in an internal group' do
group.add_guest(user) let(:group) { create(:group, :internal) }
context 'anonymous user' do
let(:user) { nil }
expect(permissions(user, group)).to be_allowed(:read_epic, :read_epic_iid) it_behaves_like 'all epic permissions disabled'
expect(permissions(user, group)).to be_disallowed(:update_epic, :destroy_epic, :admin_epic, :create_epic)
end end
it 'reporter group member can manage epics' do context 'user who is not a group member' do
group.add_reporter(user) it_behaves_like 'can only read epics'
it_behaves_like 'can comment on epics'
end
expect(permissions(user, group)).to be_disallowed(:destroy_epic) it_behaves_like 'group member permissions'
expect(permissions(user, group))
.to be_allowed(:read_epic, :read_epic_iid, :update_epic, :admin_epic, :create_epic)
end end
it 'only group owner can destroy epics' do context 'when an epic is in a public group' do
group.add_owner(user) let(:group) { create(:group, :public) }
expect(permissions(user, group)) context 'anonymous user' do
.to be_allowed(:read_epic, :read_epic_iid, :update_epic, :destroy_epic, :admin_epic, :create_epic) let(:user) { nil }
it_behaves_like 'can only read epics'
it_behaves_like 'cannot comment on epics'
end end
context 'user who is not a group member' do
it_behaves_like 'can only read epics'
it_behaves_like 'can comment on epics'
end end
it_behaves_like 'group member permissions'
end end
context 'when external authorization is enabled' do context 'when external authorization is enabled' do
...@@ -143,12 +142,13 @@ describe EpicPolicy do ...@@ -143,12 +142,13 @@ describe EpicPolicy do
group.add_owner(user) group.add_owner(user)
end end
it 'does not allow any epic permissions' do it 'does not call external authorization service' do
expect(EE::Gitlab::ExternalAuthorization).not_to receive(:access_allowed?) expect(EE::Gitlab::ExternalAuthorization).not_to receive(:access_allowed?)
expect(permissions(user, group)) subject
.not_to be_allowed(:read_epic, :read_epic_iid, :update_epic, end
:destroy_epic, :admin_epic, :create_epic)
it_behaves_like 'all epic permissions disabled'
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment