Commit 71e3d907 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch '355531-fix-auditor-permissions-for-contribution-analytics' into 'master'

Allow auditor to read group contribution analytics

See merge request gitlab-org/gitlab!83722
parents d13e07de 448b87a8
......@@ -175,6 +175,7 @@ module EE
enable :view_productivity_analytics
enable :view_group_devops_adoption
enable :read_group_repository_analytics
enable :read_group_contribution_analytics
end
rule { owner | admin }.policy do
......
......@@ -35,20 +35,29 @@ RSpec.describe Groups::ContributionAnalyticsController do
end
describe '#authorize_read_contribution_analytics!' do
before do
group.add_user(guest_user, GroupMember::GUEST)
sign_in(guest_user)
end
let(:request) { get :show, params: { group_id: group.path } }
context 'when feature is available to the group' do
before do
stub_licensed_features(contribution_analytics: true)
end
context 'when user is an auditor' do
let(:auditor) { create(:user, :auditor) }
it 'allows access' do
sign_in(auditor)
context 'when user has access to the group' do
let(:request) { get :show, params: { group_id: group.path } }
request
expect(response).to have_gitlab_http_status(:success)
end
end
context 'when feature is available to the group' do
context 'when user has access to the group' do
before do
allow(License).to receive(:feature_available?).and_call_original
allow(License).to receive(:feature_available?)
.with(:contribution_analytics)
.and_return(true)
group.add_user(guest_user, GroupMember::GUEST)
sign_in(guest_user)
allow(Ability).to receive(:allowed?).and_call_original
allow(Ability).to receive(:allowed?)
......
......@@ -182,6 +182,14 @@ RSpec.describe GroupPolicy do
it { is_expected.not_to be_allowed(:read_group_contribution_analytics) }
end
context 'when user has an auditor role' do
before do
allow(current_user).to receive(:auditor?).and_return(true)
end
it { is_expected.to be_allowed(:read_group_contribution_analytics) }
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