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
4d709949
Commit
4d709949
authored
Mar 22, 2021
by
Sean Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update rotation active period after schedule changes
parent
8ecbfd78
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
1 deletion
+42
-1
ee/app/services/incident_management/oncall_schedules/update_service.rb
...es/incident_management/oncall_schedules/update_service.rb
+20
-1
ee/spec/services/incident_management/oncall_schedules/update_service_spec.rb
...cident_management/oncall_schedules/update_service_spec.rb
+22
-0
No files found.
ee/app/services/incident_management/oncall_schedules/update_service.rb
View file @
4d709949
...
...
@@ -8,6 +8,8 @@ module IncidentManagement
# @param params [Hash]
def
initialize
(
oncall_schedule
,
user
,
params
)
@oncall_schedule
=
oncall_schedule
@original_schedule_timezone
=
oncall_schedule
&
.
timezone
@oncall_rotations
=
oncall_schedule
&
.
rotations
@user
=
user
@params
=
params
@project
=
oncall_schedule
.
project
...
...
@@ -18,6 +20,7 @@ module IncidentManagement
return
error_no_permissions
unless
allowed?
if
oncall_schedule
.
update
(
params
)
update_rotation_active_periods
success
(
oncall_schedule
)
else
error
(
oncall_schedule
.
errors
.
full_messages
.
to_sentence
)
...
...
@@ -26,7 +29,23 @@ module IncidentManagement
private
attr_reader
:oncall_schedule
,
:user
,
:params
,
:project
attr_reader
:oncall_schedule
,
:original_schedule_timezone
,
:oncall_rotations
,
:user
,
:params
,
:project
def
update_rotation_active_periods
oncall_schedule
.
rotations
.
select
(
&
:has_shift_active_period?
).
each
do
|
rotation
|
rotation
.
update!
(
active_period_start:
new_rotation_active_period
(
rotation
.
active_period_start
).
strftime
(
'%H:%M'
),
active_period_end:
new_rotation_active_period
(
rotation
.
active_period_end
).
strftime
(
'%H:%M'
)
)
end
# TODO do we need to handle run update rotation job?
# Should the above be moved to update rotation job?
end
def
new_rotation_active_period
(
time_string
)
time_string
.
in_time_zone
(
original_schedule_timezone
).
in_time_zone
(
oncall_schedule
.
timezone
)
end
def
error_no_permissions
error
(
_
(
'You have insufficient permissions to update an on-call schedule for this project'
))
...
...
ee/spec/services/incident_management/oncall_schedules/update_service_spec.rb
View file @
4d709949
...
...
@@ -68,6 +68,28 @@ RSpec.describe IncidentManagement::OncallSchedules::UpdateService do
expect
(
oncall_schedule
.
description
).
to
eq
(
params
[
:description
])
expect
(
oncall_schedule
.
timezone
).
to
eq
(
params
[
:timezone
])
end
context
'schedule has a rotation'
do
# Setting fixed timezone for rotation active period updates
around
do
|
example
|
freeze_time
do
travel_to
Time
.
utc
(
2021
,
03
,
22
)
example
.
run
end
end
let_it_be_with_reload
(
:oncall_rotation
)
{
create
(
:incident_management_oncall_rotation
,
:with_active_period
,
schedule:
oncall_schedule
)
}
it
'updates the rotation active periods with new timezone'
do
expect
{
execute
}.
to
change
{
time_from_time_column
(
oncall_rotation
.
reload
.
active_period_start
)
}.
from
(
'08:00'
).
to
(
'03:00'
)
.
and
change
{
time_from_time_column
(
oncall_rotation
.
active_period_end
)
}.
from
(
'17:00'
).
to
(
'12:00'
)
end
end
def
time_from_time_column
(
attribute
)
attribute
.
strftime
(
'%H:%M'
)
end
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