Commit 3e841cdd authored by Vitali Tatarintev's avatar Vitali Tatarintev

Extract operations settings data into a helper

parent b89b1e30
......@@ -32,6 +32,23 @@ module OperationsHelper
'disabled' => disabled.to_s
}
end
def operations_settings_data
setting = project_incident_management_setting
templates = setting.available_issue_templates.map { |t| { key: t.key, name: t.name } }
{
operations_settings_endpoint: project_settings_operations_path(@project),
templates: templates.to_json,
create_issue: setting.create_issue.to_s,
issue_template_key: setting.issue_template_key.to_s,
send_email: setting.send_email.to_s,
pagerduty_active: setting.pagerduty_active.to_s,
pagerduty_token: setting.pagerduty_token.to_s,
pagerduty_webhook_url: project_incidents_pager_duty_url(@project, token: setting.pagerduty_token),
pagerduty_reset_key_path: reset_pagerduty_token_project_settings_operations_path(@project)
}
end
end
OperationsHelper.prepend_if_ee('EE::OperationsHelper')
- setting = project_incident_management_setting
- templates = setting.available_issue_templates.map { |t| { key: t.key, name: t.name } }
.js-incidents-settings{ data: { operations_settings_endpoint: project_settings_operations_path(@project),
templates: templates.to_json,
create_issue: setting.create_issue.to_s,
issue_template_key: setting.issue_template_key.to_s,
send_email: setting.send_email.to_s,
pagerduty_active: setting.pagerduty_active.to_s,
pagerduty_token: setting.pagerduty_token.to_s,
pagerduty_webhook_url: project_incidents_pager_duty_url(@project, token: setting.pagerduty_token),
pagerduty_reset_key_path: reset_pagerduty_token_project_settings_operations_path(@project) } }
.js-incidents-settings{ data: operations_settings_data }
......@@ -5,15 +5,18 @@ require 'spec_helper'
RSpec.describe OperationsHelper do
include Gitlab::Routing
describe '#alerts_settings_data' do
let_it_be(:user) { create(:user) }
let_it_be(:project, reload: true) { create(:project) }
let_it_be(:user) { create(:user) }
let_it_be(:project, reload: true) { create(:project) }
before do
helper.instance_variable_set(:@project, project)
allow(helper).to receive(:current_user) { user }
end
describe '#alerts_settings_data' do
subject { helper.alerts_settings_data }
before do
helper.instance_variable_set(:@project, project)
allow(helper).to receive(:current_user) { user }
allow(helper).to receive(:can?).with(user, :admin_operations, project) { true }
end
......@@ -127,4 +130,31 @@ RSpec.describe OperationsHelper do
end
end
end
describe '#operations_settings_data' do
let_it_be(:operations_settings) do
create(
:project_incident_management_setting,
project: project,
issue_template_key: 'template-key',
pagerduty_active: true
)
end
subject { helper.operations_settings_data }
it 'returns the correct set of data' do
is_expected.to eq(
operations_settings_endpoint: project_settings_operations_path(project),
templates: '[]',
create_issue: 'false',
issue_template_key: 'template-key',
send_email: 'false',
pagerduty_active: 'true',
pagerduty_token: operations_settings.pagerduty_token,
pagerduty_webhook_url: project_incidents_pager_duty_url(project, token: operations_settings.pagerduty_token),
pagerduty_reset_key_path: reset_pagerduty_token_project_settings_operations_path(project)
)
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