Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
3e841cdd
Commit
3e841cdd
authored
Jul 14, 2020
by
Vitali Tatarintev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract operations settings data into a helper
parent
b89b1e30
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
17 deletions
+53
-17
app/helpers/operations_helper.rb
app/helpers/operations_helper.rb
+17
-0
app/views/projects/settings/operations/_incidents.html.haml
app/views/projects/settings/operations/_incidents.html.haml
+1
-12
spec/helpers/operations_helper_spec.rb
spec/helpers/operations_helper_spec.rb
+35
-5
No files found.
app/helpers/operations_helper.rb
View file @
3e841cdd
...
...
@@ -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'
)
app/views/projects/settings/operations/_incidents.html.haml
View file @
3e841cdd
-
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
}
spec/helpers/operations_helper_spec.rb
View file @
3e841cdd
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment