Commit a65e9062 authored by Vasilii Iakliushin's avatar Vasilii Iakliushin

Merge branch '355529-fix-auditor-permissions-for-devops-adoption-analytics' into 'master'

Allow auditor to view Devops adoption analytics

See merge request gitlab-org/gitlab!83731
parents 56c060a8 3aa656ad
...@@ -173,6 +173,7 @@ module EE ...@@ -173,6 +173,7 @@ module EE
rule { auditor }.policy do rule { auditor }.policy do
enable :view_productivity_analytics enable :view_productivity_analytics
enable :view_group_devops_adoption
end end
rule { owner | admin }.policy do rule { owner | admin }.policy do
......
...@@ -1731,6 +1731,7 @@ RSpec.describe GroupPolicy do ...@@ -1731,6 +1731,7 @@ RSpec.describe GroupPolicy do
:reporter | true :reporter | true
:guest | false :guest | false
:non_group_member | false :non_group_member | false
:auditor | true
end end
before do before do
......
...@@ -17,33 +17,59 @@ RSpec.describe Groups::Analytics::DevopsAdoptionController do ...@@ -17,33 +17,59 @@ RSpec.describe Groups::Analytics::DevopsAdoptionController do
get group_analytics_devops_adoption_path(group) get group_analytics_devops_adoption_path(group)
end end
before do context 'when user is not authorized to view devops adoption analytics' do
group.add_maintainer(current_user) before do
allow(Ability).to receive(:allowed?).and_call_original
expect(Ability).to receive(:allowed?).with(current_user, :read_group, group).and_return(true)
expect(Ability).to receive(:allowed?).with(current_user, :view_group_devops_adoption, group).and_return(false)
end
it 'renders 403, forbidden error' do
subject
expect(response).to have_gitlab_http_status(:forbidden)
end
end end
it 'renders the devops adoption page' do context 'when user is an auditor' do
subject let(:current_user) { create(:user, :auditor) }
it 'allows access' do
subject
expect(response).to render_template :show expect(response).to have_gitlab_http_status(:success)
end
end end
context 'when the feature is not available' do context 'when the user is a group maintainer' do
before do before do
stub_licensed_features(group_level_devops_adoption: false) group.add_maintainer(current_user)
end end
it 'renders forbidden' do it 'renders the devops adoption page' do
subject subject
expect(response).to have_gitlab_http_status(:forbidden) expect(response).to render_template :show
end end
end
it 'tracks devops_adoption usage event' do context 'when the feature is not available' do
expect(Gitlab::UsageDataCounters::HLLRedisCounter) before do
.to receive(:track_event).with('users_viewing_analytics_group_devops_adoption', values: kind_of(String)) stub_licensed_features(group_level_devops_adoption: false)
end
subject it 'renders forbidden' do
subject
expect(response).to have_gitlab_http_status(:forbidden)
end
end
it 'tracks devops_adoption usage event' do
expect(Gitlab::UsageDataCounters::HLLRedisCounter)
.to receive(:track_event).with('users_viewing_analytics_group_devops_adoption', values: kind_of(String))
subject
end
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