Commit a3281912 authored by Clement Ho's avatar Clement Ho

Merge branch '66467-enable-error-tracking-only-user-can-read-sentry-logs' into 'master'

Display `more information` docs link on error tracking page when users do not have permissions to enable that feature

See merge request gitlab-org/gitlab-ce!32365
parents aadd1c8c dbca77e3
...@@ -38,6 +38,10 @@ export default { ...@@ -38,6 +38,10 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
userCanEnableErrorTracking: {
type: Boolean,
required: true,
},
}, },
computed: { computed: {
...mapState(['errors', 'externalUrl', 'loading']), ...mapState(['errors', 'externalUrl', 'loading']),
...@@ -111,7 +115,7 @@ export default { ...@@ -111,7 +115,7 @@ export default {
</gl-table> </gl-table>
</div> </div>
</div> </div>
<div v-else> <div v-else-if="userCanEnableErrorTracking">
<gl-empty-state <gl-empty-state
:title="__('Get started with error tracking')" :title="__('Get started with error tracking')"
:description="__('Monitor your errors by integrating with Sentry')" :description="__('Monitor your errors by integrating with Sentry')"
...@@ -120,5 +124,17 @@ export default { ...@@ -120,5 +124,17 @@ export default {
:svg-path="illustrationPath" :svg-path="illustrationPath"
/> />
</div> </div>
<div v-else>
<gl-empty-state :title="__('Get started with error tracking')" :svg-path="illustrationPath">
<template #description>
<div>
<span>{{ __('Monitor your errors by integrating with Sentry.') }}</span>
<a href="/help/user/project/operations/error_tracking.html">
{{ __('More information') }}
</a>
</div>
</template>
</gl-empty-state>
</div>
</div> </div>
</template> </template>
...@@ -14,9 +14,10 @@ export default () => { ...@@ -14,9 +14,10 @@ export default () => {
render(createElement) { render(createElement) {
const domEl = document.querySelector(this.$options.el); const domEl = document.querySelector(this.$options.el);
const { indexPath, enableErrorTrackingLink, illustrationPath } = domEl.dataset; const { indexPath, enableErrorTrackingLink, illustrationPath } = domEl.dataset;
let { errorTrackingEnabled } = domEl.dataset; let { errorTrackingEnabled, userCanEnableErrorTracking } = domEl.dataset;
errorTrackingEnabled = parseBoolean(errorTrackingEnabled); errorTrackingEnabled = parseBoolean(errorTrackingEnabled);
userCanEnableErrorTracking = parseBoolean(userCanEnableErrorTracking);
return createElement('error-tracking-list', { return createElement('error-tracking-list', {
props: { props: {
...@@ -24,6 +25,7 @@ export default () => { ...@@ -24,6 +25,7 @@ export default () => {
enableErrorTrackingLink, enableErrorTrackingLink,
errorTrackingEnabled, errorTrackingEnabled,
illustrationPath, illustrationPath,
userCanEnableErrorTracking,
}, },
}); });
}, },
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module Projects module Projects
module Settings module Settings
class OperationsController < Projects::ApplicationController class OperationsController < Projects::ApplicationController
before_action :authorize_update_environment! before_action :authorize_admin_operations!
helper_method :error_tracking_setting helper_method :error_tracking_setting
......
...@@ -16,7 +16,7 @@ module Types ...@@ -16,7 +16,7 @@ module Types
:create_deployment, :push_to_delete_protected_branch, :create_deployment, :push_to_delete_protected_branch,
:admin_wiki, :admin_project, :update_pages, :admin_wiki, :admin_project, :update_pages,
:admin_remote_mirror, :create_label, :update_wiki, :destroy_wiki, :admin_remote_mirror, :create_label, :update_wiki, :destroy_wiki,
:create_pages, :destroy_pages, :read_pages_content :create_pages, :destroy_pages, :read_pages_content, :admin_operations
end end
end end
end end
# frozen_string_literal: true # frozen_string_literal: true
module Projects::ErrorTrackingHelper module Projects::ErrorTrackingHelper
def error_tracking_data(project) def error_tracking_data(current_user, project)
error_tracking_enabled = !!project.error_tracking_setting&.enabled? error_tracking_enabled = !!project.error_tracking_setting&.enabled?
{ {
'index-path' => project_error_tracking_index_path(project, 'index-path' => project_error_tracking_index_path(project,
format: :json), format: :json),
'user-can-enable-error-tracking' => can?(current_user, :admin_operations, project).to_s,
'enable-error-tracking-link' => project_settings_operations_path(project), 'enable-error-tracking-link' => project_settings_operations_path(project),
'error-tracking-enabled' => error_tracking_enabled.to_s, 'error-tracking-enabled' => error_tracking_enabled.to_s,
'illustration-path' => image_path('illustrations/cluster_popover.svg') 'illustration-path' => image_path('illustrations/cluster_popover.svg')
......
...@@ -294,6 +294,7 @@ class ProjectPolicy < BasePolicy ...@@ -294,6 +294,7 @@ class ProjectPolicy < BasePolicy
enable :destroy_release enable :destroy_release
enable :destroy_artifacts enable :destroy_artifacts
enable :daily_statistics enable :daily_statistics
enable :admin_operations
end end
rule { (mirror_available & can?(:admin_project)) | admin }.enable :admin_remote_mirror rule { (mirror_available & can?(:admin_project)) | admin }.enable :admin_remote_mirror
......
- page_title _('Errors') - page_title _('Errors')
#js-error_tracking{ data: error_tracking_data(@project) } #js-error_tracking{ data: error_tracking_data(@current_user, @project) }
---
title: Display `more information` docs link on error tracking page when users do not have permissions to enable that feature
merge_request: 32365
author: Romain Maneschi
type: fixed
...@@ -7212,6 +7212,9 @@ msgstr "" ...@@ -7212,6 +7212,9 @@ msgstr ""
msgid "Monitor your errors by integrating with Sentry" msgid "Monitor your errors by integrating with Sentry"
msgstr "" msgstr ""
msgid "Monitor your errors by integrating with Sentry."
msgstr ""
msgid "Monitoring" msgid "Monitoring"
msgstr "" msgstr ""
......
...@@ -11,19 +11,24 @@ describe('ErrorTrackingList', () => { ...@@ -11,19 +11,24 @@ describe('ErrorTrackingList', () => {
let wrapper; let wrapper;
let actions; let actions;
function mountComponent({ errorTrackingEnabled = true } = {}) { function mountComponent({
errorTrackingEnabled = true,
userCanEnableErrorTracking = true,
stubs = {
'gl-link': GlLink,
},
} = {}) {
wrapper = shallowMount(ErrorTrackingList, { wrapper = shallowMount(ErrorTrackingList, {
localVue, localVue,
store, store,
propsData: { propsData: {
indexPath: '/path', indexPath: '/path',
enableErrorTrackingLink: '/link', enableErrorTrackingLink: '/link',
userCanEnableErrorTracking,
errorTrackingEnabled, errorTrackingEnabled,
illustrationPath: 'illustration/path', illustrationPath: 'illustration/path',
}, },
stubs: { stubs,
'gl-link': GlLink,
},
}); });
} }
...@@ -115,4 +120,23 @@ describe('ErrorTrackingList', () => { ...@@ -115,4 +120,23 @@ describe('ErrorTrackingList', () => {
expect(wrapper.find(GlButton).exists()).toBeFalsy(); expect(wrapper.find(GlButton).exists()).toBeFalsy();
}); });
}); });
describe('When error tracking is disabled and user is not allowed to enable it', () => {
beforeEach(() => {
mountComponent({
errorTrackingEnabled: false,
userCanEnableErrorTracking: false,
stubs: {
'gl-link': GlLink,
'gl-empty-state': GlEmptyState,
},
});
});
it('shows empty state', () => {
expect(wrapper.find('a').attributes('href')).toBe(
'/help/user/project/operations/error_tracking.html',
);
});
});
}); });
...@@ -6,21 +6,31 @@ describe Projects::ErrorTrackingHelper do ...@@ -6,21 +6,31 @@ describe Projects::ErrorTrackingHelper do
include Gitlab::Routing.url_helpers include Gitlab::Routing.url_helpers
set(:project) { create(:project) } set(:project) { create(:project) }
set(:current_user) { create(:user) }
describe '#error_tracking_data' do describe '#error_tracking_data' do
let(:can_enable_error_tracking) { true }
let(:setting_path) { project_settings_operations_path(project) } let(:setting_path) { project_settings_operations_path(project) }
let(:index_path) do let(:index_path) do
project_error_tracking_index_path(project, format: :json) project_error_tracking_index_path(project, format: :json)
end end
before do
allow(helper)
.to receive(:can?)
.with(current_user, :admin_operations, project)
.and_return(can_enable_error_tracking)
end
context 'without error_tracking_setting' do context 'without error_tracking_setting' do
it 'returns frontend configuration' do it 'returns frontend configuration' do
expect(error_tracking_data(project)).to eq( expect(helper.error_tracking_data(current_user, project)).to match(
'index-path' => index_path, 'index-path' => index_path,
'user-can-enable-error-tracking' => 'true',
'enable-error-tracking-link' => setting_path, 'enable-error-tracking-link' => setting_path,
'error-tracking-enabled' => 'false', 'error-tracking-enabled' => 'false',
"illustration-path" => "/images/illustrations/cluster_popover.svg" 'illustration-path' => match_asset_path('/assets/illustrations/cluster_popover.svg')
) )
end end
end end
...@@ -36,7 +46,7 @@ describe Projects::ErrorTrackingHelper do ...@@ -36,7 +46,7 @@ describe Projects::ErrorTrackingHelper do
end end
it 'show error tracking enabled' do it 'show error tracking enabled' do
expect(error_tracking_data(project)).to include( expect(helper.error_tracking_data(current_user, project)).to include(
'error-tracking-enabled' => 'true' 'error-tracking-enabled' => 'true'
) )
end end
...@@ -48,11 +58,21 @@ describe Projects::ErrorTrackingHelper do ...@@ -48,11 +58,21 @@ describe Projects::ErrorTrackingHelper do
end end
it 'show error tracking not enabled' do it 'show error tracking not enabled' do
expect(error_tracking_data(project)).to include( expect(helper.error_tracking_data(current_user, project)).to include(
'error-tracking-enabled' => 'false' 'error-tracking-enabled' => 'false'
) )
end end
end end
end end
context 'when user is not maintainer' do
let(:can_enable_error_tracking) { false }
it 'shows error tracking enablement as disabled' do
expect(helper.error_tracking_data(current_user, project)).to include(
'user-can-enable-error-tracking' => 'false'
)
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