diff --git a/app/assets/stylesheets/pages/settings.scss b/app/assets/stylesheets/pages/settings.scss index 716704f9346be5011fbc69f5e3b0d93c84fcdd49..0ef93a0ba045c8ef8f8677edab19d7b56d04bf1c 100644 --- a/app/assets/stylesheets/pages/settings.scss +++ b/app/assets/stylesheets/pages/settings.scss @@ -23,7 +23,10 @@ } .settings { - border-bottom: 1px solid $gray-darker; + // border-top for each item except the top one + + .settings { + border-top: 1px solid $border-color; + } &:first-of-type { margin-top: 10px; diff --git a/app/views/projects/settings/operations/_error_tracking.html.haml b/app/views/projects/settings/operations/_error_tracking.html.haml index 6b15331db01e1b74a3ecdb0772ef995a521f3c3b..451a79becc3ea1a94ac7e51c5821edc43a08b0eb 100644 --- a/app/views/projects/settings/operations/_error_tracking.html.haml +++ b/app/views/projects/settings/operations/_error_tracking.html.haml @@ -2,7 +2,7 @@ - setting = error_tracking_setting -%section.settings.expanded.border-0.no-animate +%section.settings.expanded.no-animate .settings-header %h4 = _('Error Tracking') diff --git a/app/views/projects/settings/operations/show.html.haml b/app/views/projects/settings/operations/show.html.haml index 2822debe426b80f3a68220d0a028fa404dd03183..6f777305a549a4b71081766fe07e368bea517af3 100644 --- a/app/views/projects/settings/operations/show.html.haml +++ b/app/views/projects/settings/operations/show.html.haml @@ -2,5 +2,6 @@ - page_title _('Operations Settings') - breadcrumb_title _('Operations Settings') += render_if_exists 'projects/settings/operations/incidents' = render 'projects/settings/operations/error_tracking', expanded: true = render_if_exists 'projects/settings/operations/tracing' diff --git a/ee/app/models/incident_management/project_incident_management_setting.rb b/ee/app/models/incident_management/project_incident_management_setting.rb index 0aa75ecf4f7e918253a4a49c86f69d7c95153755..1e9f70df9a72ff51eb4188a244883453d4b22a5f 100644 --- a/ee/app/models/incident_management/project_incident_management_setting.rb +++ b/ee/app/models/incident_management/project_incident_management_setting.rb @@ -6,6 +6,10 @@ module IncidentManagement validate :issue_template_exists, if: :create_issue? + def available_issue_templates + Gitlab::Template::IssueTemplate.all(project) + end + private def issue_template_exists diff --git a/ee/app/views/projects/settings/operations/_incidents.html.haml b/ee/app/views/projects/settings/operations/_incidents.html.haml new file mode 100644 index 0000000000000000000000000000000000000000..8790e27e48cf85fe353edec8b6238f74fc27d8c5 --- /dev/null +++ b/ee/app/views/projects/settings/operations/_incidents.html.haml @@ -0,0 +1,32 @@ +- return unless incident_management_available? + +- templates = [] +- setting = project_incident_management_setting +- templates = setting.available_issue_templates.map { |t| [t.name, t.key] } + +%section.settings.expanded.no-animate + .settings-header + %h4= _('Incidents') + %p + = _('Action to take when receiving an alert.') + = link_to help_page_path('user/project/integrations/prometheus', anchor: 'taking-action-on-an-alert-ultimate') do + = _('More information') + .settings-content + = form_for @project, url: project_settings_operations_path(@project), method: :patch do |f| + = form_errors(@project.incident_management_setting) + .form-group + = f.fields_for :incident_management_setting_attributes, setting do |form| + .form-group + = form.check_box :create_issue + = form.label :create_issue, _('Create an issue. Issues are created for each alert triggered.'), class: 'form-check-label' + .form-group.col-sm-8 + = form.label :issue_template_key, class: 'label-bold' do + = _('Issue template (optional)') + = link_to icon('question-circle'), help_page_path('user/project/description_templates', anchor: 'creating-issue-templates'), target: '_blank', rel: 'noopener noreferrer' + .select-wrapper + = form.select :issue_template_key, templates, {include_blank: 'No template selected'}, class: "form-control select-control" + = icon('chevron-down') + .form-group + = form.check_box :send_email + = form.label :send_email, _('Send an email notification to Developers.'), class: 'form-check-label' + = f.submit _('Save changes'), class: 'btn btn-success' diff --git a/ee/spec/features/projects/settings/operations_settings_spec.rb b/ee/spec/features/projects/settings/operations_settings_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..705883c7fc0334bac17a355a8f02162c55f824fc --- /dev/null +++ b/ee/spec/features/projects/settings/operations_settings_spec.rb @@ -0,0 +1,64 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'Projects > Settings' do + let(:user) { create(:user) } + let(:project) { create(:project, :repository, create_templates: :issue) } + let(:role) { :maintainer } + let(:create_issue) { 'Create an issue. Issues are created for each alert triggered.' } + let(:send_email) { 'Send an email notification to Developers.' } + + before do + create(:project_incident_management_setting, send_email: true, project: project) + sign_in(user) + project.add_role(user, role) + end + + describe 'Incidents' do + context 'with license' do + before do + stub_licensed_features(incident_management: true) + visit project_settings_operations_path(project) + end + + it 'renders form for incident management' do + expect(page).to have_selector('h4', text: 'Incidents') + end + + it 'sets correct default values' do + expect(find_field(create_issue)).not_to be_checked + expect(find_field(send_email)).to be_checked + end + + it 'updates form values' do + check(create_issue) + template_select = find_field('Issue template') + template_select.find(:xpath, 'option[2]').select_option + uncheck(send_email) + save_form + + expect(find_field(create_issue)).to be_checked + expect(page).to have_select('Issue template', selected: 'bug') + expect(find_field(send_email)).not_to be_checked + end + + def save_form + page.within "#edit_project_#{project.id}" do + click_on 'Save changes' + end + end + end + + context 'without license' do + before do + stub_licensed_features(incident_management: false) + visit project_settings_operations_path(project) + end + + it 'renders form for incident management' do + expect(page).not_to have_selector('h4', text: 'Incidents') + end + end + end +end diff --git a/ee/spec/views/projects/settings/operations/show.html.haml_spec.rb b/ee/spec/views/projects/settings/operations/show.html.haml_spec.rb index 9176ceb735c0d3711bbf0b5f15c11e646f95acf4..9193a010e312c380ea3286b5624444f9435ba7c5 100644 --- a/ee/spec/views/projects/settings/operations/show.html.haml_spec.rb +++ b/ee/spec/views/projects/settings/operations/show.html.haml_spec.rb @@ -11,7 +11,7 @@ describe 'projects/settings/operations/show' do assign(:repository, project.repository) allow(view).to receive(:current_ref).and_return('master') allow(view).to receive(:error_tracking_setting).and_return(error_tracking_setting) - + allow(view).to receive(:incident_management_available?) { false } stub_licensed_features(tracing: true) end diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 0174ab3bed5ac96dd7c33a0d9826d6a35664a06a..3ffc18ef91d55c4efc9f54273c8a6520db22992c 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -473,6 +473,9 @@ msgstr "" msgid "Account and limit" msgstr "" +msgid "Action to take when receiving an alert." +msgstr "" + msgid "Active" msgstr "" @@ -2966,6 +2969,9 @@ msgstr "" msgid "Create a personal access token on your account to pull or push via %{protocol}." msgstr "" +msgid "Create an issue. Issues are created for each alert triggered." +msgstr "" + msgid "Create branch" msgstr "" @@ -5486,6 +5492,9 @@ msgstr "" msgid "In the next step, you'll be able to select the projects you want to import." msgstr "" +msgid "Incidents" +msgstr "" + msgid "Include a Terms of Service agreement and Privacy Policy that all users must accept." msgstr "" @@ -5620,6 +5629,9 @@ msgstr "" msgid "Issue settings" msgstr "" +msgid "Issue template (optional)" +msgstr "" + msgid "IssueBoards|Board" msgstr "" @@ -8906,6 +8918,9 @@ msgstr "" msgid "Selecting a GitLab user will add a link to the GitLab user in the descriptions of issues and comments (e.g. \"By <a href=\"#\">@johnsmith</a>\"). It will also associate and/or assign these issues and comments with the selected user." msgstr "" +msgid "Send an email notification to Developers." +msgstr "" + msgid "Send email" msgstr "" diff --git a/spec/views/projects/settings/operations/show.html.haml_spec.rb b/spec/views/projects/settings/operations/show.html.haml_spec.rb index 1bca8bba940fc474b6a74688db9085d57e8adb03..6762fe3759bef63b64e0499a161067a3e4ff39e0 100644 --- a/spec/views/projects/settings/operations/show.html.haml_spec.rb +++ b/spec/views/projects/settings/operations/show.html.haml_spec.rb @@ -18,6 +18,7 @@ describe 'projects/settings/operations/show' do allow(view).to receive(:error_tracking_setting) .and_return(error_tracking_setting) allow(view).to receive(:current_user).and_return(user) + allow(view).to receive(:incident_management_available?) { false } end let!(:error_tracking_setting) do