Commit dbca77e3 authored by Maneschi Romain's avatar Maneschi Romain Committed by Clement Ho

If user can't activate error tracking display a learn more button pointing

  to doc
parent aadd1c8c
......@@ -38,6 +38,10 @@ export default {
type: String,
required: true,
},
userCanEnableErrorTracking: {
type: Boolean,
required: true,
},
},
computed: {
...mapState(['errors', 'externalUrl', 'loading']),
......@@ -111,7 +115,7 @@ export default {
</gl-table>
</div>
</div>
<div v-else>
<div v-else-if="userCanEnableErrorTracking">
<gl-empty-state
:title="__('Get started with error tracking')"
:description="__('Monitor your errors by integrating with Sentry')"
......@@ -120,5 +124,17 @@ export default {
:svg-path="illustrationPath"
/>
</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>
</template>
......@@ -14,9 +14,10 @@ export default () => {
render(createElement) {
const domEl = document.querySelector(this.$options.el);
const { indexPath, enableErrorTrackingLink, illustrationPath } = domEl.dataset;
let { errorTrackingEnabled } = domEl.dataset;
let { errorTrackingEnabled, userCanEnableErrorTracking } = domEl.dataset;
errorTrackingEnabled = parseBoolean(errorTrackingEnabled);
userCanEnableErrorTracking = parseBoolean(userCanEnableErrorTracking);
return createElement('error-tracking-list', {
props: {
......@@ -24,6 +25,7 @@ export default () => {
enableErrorTrackingLink,
errorTrackingEnabled,
illustrationPath,
userCanEnableErrorTracking,
},
});
},
......
......@@ -3,7 +3,7 @@
module Projects
module Settings
class OperationsController < Projects::ApplicationController
before_action :authorize_update_environment!
before_action :authorize_admin_operations!
helper_method :error_tracking_setting
......
......@@ -16,7 +16,7 @@ module Types
:create_deployment, :push_to_delete_protected_branch,
:admin_wiki, :admin_project, :update_pages,
: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
# frozen_string_literal: true
module Projects::ErrorTrackingHelper
def error_tracking_data(project)
def error_tracking_data(current_user, project)
error_tracking_enabled = !!project.error_tracking_setting&.enabled?
{
'index-path' => project_error_tracking_index_path(project,
format: :json),
'user-can-enable-error-tracking' => can?(current_user, :admin_operations, project).to_s,
'enable-error-tracking-link' => project_settings_operations_path(project),
'error-tracking-enabled' => error_tracking_enabled.to_s,
'illustration-path' => image_path('illustrations/cluster_popover.svg')
......
......@@ -294,6 +294,7 @@ class ProjectPolicy < BasePolicy
enable :destroy_release
enable :destroy_artifacts
enable :daily_statistics
enable :admin_operations
end
rule { (mirror_available & can?(:admin_project)) | admin }.enable :admin_remote_mirror
......
- 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 ""
msgid "Monitor your errors by integrating with Sentry"
msgstr ""
msgid "Monitor your errors by integrating with Sentry."
msgstr ""
msgid "Monitoring"
msgstr ""
......
......@@ -11,19 +11,24 @@ describe('ErrorTrackingList', () => {
let wrapper;
let actions;
function mountComponent({ errorTrackingEnabled = true } = {}) {
function mountComponent({
errorTrackingEnabled = true,
userCanEnableErrorTracking = true,
stubs = {
'gl-link': GlLink,
},
} = {}) {
wrapper = shallowMount(ErrorTrackingList, {
localVue,
store,
propsData: {
indexPath: '/path',
enableErrorTrackingLink: '/link',
userCanEnableErrorTracking,
errorTrackingEnabled,
illustrationPath: 'illustration/path',
},
stubs: {
'gl-link': GlLink,
},
stubs,
});
}
......@@ -115,4 +120,23 @@ describe('ErrorTrackingList', () => {
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
include Gitlab::Routing.url_helpers
set(:project) { create(:project) }
set(:current_user) { create(:user) }
describe '#error_tracking_data' do
let(:can_enable_error_tracking) { true }
let(:setting_path) { project_settings_operations_path(project) }
let(:index_path) do
project_error_tracking_index_path(project, format: :json)
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
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,
'user-can-enable-error-tracking' => 'true',
'enable-error-tracking-link' => setting_path,
'error-tracking-enabled' => 'false',
"illustration-path" => "/images/illustrations/cluster_popover.svg"
'illustration-path' => match_asset_path('/assets/illustrations/cluster_popover.svg')
)
end
end
......@@ -36,7 +46,7 @@ describe Projects::ErrorTrackingHelper do
end
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'
)
end
......@@ -48,11 +58,21 @@ describe Projects::ErrorTrackingHelper do
end
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'
)
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
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