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
9729ea36
Commit
9729ea36
authored
Jan 24, 2022
by
Sarah Yasonik
Committed by
Luke Duncalfe
Jan 24, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Swap OncallSchedule services to inherit from BaseProjectService
parent
0201fca5
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
26 additions
and
64 deletions
+26
-64
ee/app/graphql/mutations/incident_management/oncall_schedule/create.rb
...l/mutations/incident_management/oncall_schedule/create.rb
+3
-3
ee/app/graphql/mutations/incident_management/oncall_schedule/destroy.rb
.../mutations/incident_management/oncall_schedule/destroy.rb
+3
-3
ee/app/graphql/mutations/incident_management/oncall_schedule/update.rb
...l/mutations/incident_management/oncall_schedule/update.rb
+4
-4
ee/app/services/incident_management/oncall_schedules/base_service.rb
...ices/incident_management/oncall_schedules/base_service.rb
+2
-2
ee/app/services/incident_management/oncall_schedules/create_service.rb
...es/incident_management/oncall_schedules/create_service.rb
+0
-11
ee/app/services/incident_management/oncall_schedules/destroy_service.rb
...s/incident_management/oncall_schedules/destroy_service.rb
+1
-11
ee/app/services/incident_management/oncall_schedules/update_service.rb
...es/incident_management/oncall_schedules/update_service.rb
+8
-25
ee/spec/services/incident_management/oncall_schedules/create_service_spec.rb
...cident_management/oncall_schedules/create_service_spec.rb
+1
-1
ee/spec/services/incident_management/oncall_schedules/destroy_service_spec.rb
...ident_management/oncall_schedules/destroy_service_spec.rb
+2
-2
ee/spec/services/incident_management/oncall_schedules/update_service_spec.rb
...cident_management/oncall_schedules/update_service_spec.rb
+2
-2
No files found.
ee/app/graphql/mutations/incident_management/oncall_schedule/create.rb
View file @
9729ea36
...
...
@@ -28,9 +28,9 @@ module Mutations
project
=
authorized_find!
(
args
[
:project_path
])
response
::
IncidentManagement
::
OncallSchedules
::
CreateService
.
new
(
project
,
current_user
,
args
.
slice
(
:name
,
:description
,
:timezone
)
project
:
project
,
current_user
:
current_user
,
params:
args
.
slice
(
:name
,
:description
,
:timezone
)
).
execute
end
end
...
...
ee/app/graphql/mutations/incident_management/oncall_schedule/destroy.rb
View file @
9729ea36
...
...
@@ -18,9 +18,9 @@ module Mutations
oncall_schedule
=
authorized_find!
(
project_path:
project_path
,
iid:
iid
)
response
::
IncidentManagement
::
OncallSchedules
::
DestroyService
.
new
(
oncall_schedule
,
current_user
).
execute
project:
oncall_schedule
.
project
,
current_user
:
current_user
).
execute
(
oncall_schedule
)
end
end
end
...
...
ee/app/graphql/mutations/incident_management/oncall_schedule/update.rb
View file @
9729ea36
...
...
@@ -30,10 +30,10 @@ module Mutations
oncall_schedule
=
authorized_find!
(
project_path:
args
[
:project_path
],
iid:
args
[
:iid
])
response
::
IncidentManagement
::
OncallSchedules
::
UpdateService
.
new
(
oncall_schedule
,
current_user
,
args
.
slice
(
:name
,
:description
,
:timezone
)
).
execute
project:
oncall_schedule
.
project
,
current_user
:
current_user
,
params:
args
.
slice
(
:name
,
:description
,
:timezone
)
).
execute
(
oncall_schedule
)
end
end
end
...
...
ee/app/services/incident_management/oncall_schedules/base_service.rb
View file @
9729ea36
...
...
@@ -2,9 +2,9 @@
module
IncidentManagement
module
OncallSchedules
class
BaseService
class
BaseService
<
::
BaseProjectService
def
allowed?
user
&
.
can?
(
:admin_incident_management_oncall_schedule
,
project
)
current_
user
&
.
can?
(
:admin_incident_management_oncall_schedule
,
project
)
end
def
available?
...
...
ee/app/services/incident_management/oncall_schedules/create_service.rb
View file @
9729ea36
...
...
@@ -3,15 +3,6 @@
module
IncidentManagement
module
OncallSchedules
class
CreateService
<
OncallSchedules
::
BaseService
# @param project [Project]
# @param user [User]
# @param params [Hash]
def
initialize
(
project
,
user
,
params
)
@project
=
project
@user
=
user
@params
=
params
end
def
execute
return
error_no_license
unless
available?
return
error_no_permissions
unless
allowed?
...
...
@@ -24,8 +15,6 @@ module IncidentManagement
private
attr_reader
:project
,
:user
,
:params
def
error_no_permissions
error
(
_
(
'You have insufficient permissions to create an on-call schedule for this project'
))
end
...
...
ee/app/services/incident_management/oncall_schedules/destroy_service.rb
View file @
9729ea36
...
...
@@ -3,15 +3,7 @@
module
IncidentManagement
module
OncallSchedules
class
DestroyService
<
OncallSchedules
::
BaseService
# @param oncall_schedule [IncidentManagement::OncallSchedule]
# @param user [User]
def
initialize
(
oncall_schedule
,
user
)
@oncall_schedule
=
oncall_schedule
@user
=
user
@project
=
oncall_schedule
.
project
end
def
execute
def
execute
(
oncall_schedule
)
return
error_no_license
unless
available?
return
error_no_permissions
unless
allowed?
...
...
@@ -24,8 +16,6 @@ module IncidentManagement
private
attr_reader
:oncall_schedule
,
:user
,
:project
def
error_no_permissions
error
(
_
(
'You have insufficient permissions to remove an on-call schedule from this project'
))
end
...
...
ee/app/services/incident_management/oncall_schedules/update_service.rb
View file @
9729ea36
...
...
@@ -3,24 +3,13 @@
module
IncidentManagement
module
OncallSchedules
class
UpdateService
<
OncallSchedules
::
BaseService
# @param oncall_schedule [IncidentManagement::OncallSchedule]
# @param user [User]
# @param params [Hash]
def
initialize
(
oncall_schedule
,
user
,
params
)
@oncall_schedule
=
oncall_schedule
@original_schedule_timezone
=
oncall_schedule
.
timezone
@user
=
user
@params
=
params
@project
=
oncall_schedule
.
project
end
def
execute
def
execute
(
oncall_schedule
)
return
error_no_license
unless
available?
return
error_no_permissions
unless
allowed?
IncidentManagement
::
OncallSchedule
.
transaction
do
oncall_schedule
.
update!
(
params
)
update_rotations!
update_rotations!
(
oncall_schedule
)
end
success
(
oncall_schedule
)
...
...
@@ -32,22 +21,16 @@ module IncidentManagement
private
attr_reader
:oncall_schedule
,
:original_schedule_timezone
,
:user
,
:params
,
:project
def
update_rotations!
return
if
same_schedule_timezone?
update_rotation_active_periods!
end
def
update_rotations!
(
oncall_schedule
)
return
unless
oncall_schedule
.
timezone_previously_changed?
def
same_schedule_timezone?
original_schedule_timezone
==
oncall_schedule
.
timezone
update_rotation_active_periods!
(
oncall_schedule
)
end
# Converts & updates the active period to the new timezone
# Ex: 8:00 - 17:00 Europe/Berlin becomes 6:00 - 15:00 UTC
def
update_rotation_active_periods!
original_schedule_current_time
=
Time
.
current
.
in_time_zone
(
o
riginal_schedule_timezone
)
def
update_rotation_active_periods!
(
oncall_schedule
)
original_schedule_current_time
=
Time
.
current
.
in_time_zone
(
o
ncall_schedule
.
timezone_previously_was
)
oncall_schedule
.
rotations
.
with_active_period
.
each
do
|
rotation
|
active_period
=
rotation
.
active_period
.
for_date
(
original_schedule_current_time
)
...
...
@@ -55,7 +38,7 @@ module IncidentManagement
service
=
IncidentManagement
::
OncallRotations
::
EditService
.
new
(
rotation
,
user
,
current_
user
,
{
active_period_start:
new_start_time
,
active_period_end:
new_end_time
...
...
ee/spec/services/incident_management/oncall_schedules/create_service_spec.rb
View file @
9729ea36
...
...
@@ -9,7 +9,7 @@ RSpec.describe IncidentManagement::OncallSchedules::CreateService do
let
(
:current_user
)
{
user_with_permissions
}
let
(
:params
)
{
{
name:
'On-call schedule'
,
description:
'On-call schedule description'
,
timezone:
'Europe/Berlin'
}
}
let
(
:service
)
{
described_class
.
new
(
project
,
current_user
,
params
)
}
let
(
:service
)
{
described_class
.
new
(
project
:
project
,
current_user:
current_user
,
params:
params
)
}
before
do
stub_licensed_features
(
oncall_schedules:
true
)
...
...
ee/spec/services/incident_management/oncall_schedules/destroy_service_spec.rb
View file @
9729ea36
...
...
@@ -10,7 +10,7 @@ RSpec.describe IncidentManagement::OncallSchedules::DestroyService do
let!
(
:oncall_schedule
)
{
create
(
:incident_management_oncall_schedule
,
project:
project
)
}
let
(
:current_user
)
{
user_with_permissions
}
let
(
:params
)
{
{}
}
let
(
:service
)
{
described_class
.
new
(
oncall_schedule
,
current_user
)
}
let
(
:service
)
{
described_class
.
new
(
project:
project
,
current_user:
current_user
)
}
before
do
stub_licensed_features
(
oncall_schedules:
true
)
...
...
@@ -25,7 +25,7 @@ RSpec.describe IncidentManagement::OncallSchedules::DestroyService do
end
end
subject
(
:execute
)
{
service
.
execute
}
subject
(
:execute
)
{
service
.
execute
(
oncall_schedule
)
}
context
'when the current_user is anonymous'
do
let
(
:current_user
)
{
nil
}
...
...
ee/spec/services/incident_management/oncall_schedules/update_service_spec.rb
View file @
9729ea36
...
...
@@ -11,7 +11,7 @@ RSpec.describe IncidentManagement::OncallSchedules::UpdateService do
let
(
:current_user
)
{
user_with_permissions
}
let
(
:new_timezone
)
{
'America/New_York'
}
let
(
:params
)
{
{
name:
'Updated name'
,
description:
'Updated description'
,
timezone:
new_timezone
}
}
let
(
:service
)
{
described_class
.
new
(
oncall_schedule
,
current_user
,
params
)
}
let
(
:service
)
{
described_class
.
new
(
project:
project
,
current_user:
current_user
,
params:
params
)
}
before
do
stub_licensed_features
(
oncall_schedules:
true
)
...
...
@@ -26,7 +26,7 @@ RSpec.describe IncidentManagement::OncallSchedules::UpdateService do
end
end
subject
(
:execute
)
{
service
.
execute
}
subject
(
:execute
)
{
service
.
execute
(
oncall_schedule
)
}
context
'when the current_user is anonymous'
do
let
(
:current_user
)
{
nil
}
...
...
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