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
35383186
Commit
35383186
authored
Feb 12, 2021
by
Sean Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move common methods into base services
oncall schedules and rotations
parent
92757043
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
65 additions
and
111 deletions
+65
-111
ee/app/services/incident_management/oncall_rotations/base_service.rb
...ices/incident_management/oncall_rotations/base_service.rb
+27
-0
ee/app/services/incident_management/oncall_rotations/create_service.rb
...es/incident_management/oncall_rotations/create_service.rb
+5
-25
ee/app/services/incident_management/oncall_rotations/destroy_service.rb
...s/incident_management/oncall_rotations/destroy_service.rb
+2
-22
ee/app/services/incident_management/oncall_schedules/base_service.rb
...ices/incident_management/oncall_schedules/base_service.rb
+27
-0
ee/app/services/incident_management/oncall_schedules/create_service.rb
...es/incident_management/oncall_schedules/create_service.rb
+1
-21
ee/app/services/incident_management/oncall_schedules/destroy_service.rb
...s/incident_management/oncall_schedules/destroy_service.rb
+2
-22
ee/app/services/incident_management/oncall_schedules/update_service.rb
...es/incident_management/oncall_schedules/update_service.rb
+1
-21
No files found.
ee/app/services/incident_management/oncall_rotations/base_service.rb
0 → 100644
View file @
35383186
# frozen_string_literal: true
module
IncidentManagement
module
OncallRotations
class
BaseService
def
allowed?
user
&
.
can?
(
:admin_incident_management_oncall_schedule
,
project
)
end
def
available?
::
Gitlab
::
IncidentManagement
.
oncall_schedules_available?
(
project
)
end
def
error
(
message
)
ServiceResponse
.
error
(
message:
message
)
end
def
success
(
oncall_rotation
)
ServiceResponse
.
success
(
payload:
{
oncall_rotation:
oncall_rotation
})
end
def
error_no_license
error
(
_
(
'Your license does not support on-call rotations'
))
end
end
end
end
ee/app/services/incident_management/oncall_rotations/create_service.rb
View file @
35383186
...
@@ -2,12 +2,12 @@
...
@@ -2,12 +2,12 @@
module
IncidentManagement
module
IncidentManagement
module
OncallRotations
module
OncallRotations
class
CreateService
class
CreateService
<
BaseService
MAXIMUM_PARTICIPANTS
=
100
MAXIMUM_PARTICIPANTS
=
100
# @param schedule [IncidentManagement::OncallSchedule]
# @param schedule [IncidentManagement::OncallSchedule]
# @param project [Project]
# @param project [Project]
# @param
current_
user [User]
# @param user [User]
# @param params [Hash<Symbol,Any>]
# @param params [Hash<Symbol,Any>]
# @param params - name [String] The name of the on-call rotation.
# @param params - name [String] The name of the on-call rotation.
# @param params - length [Integer] The length of the rotation.
# @param params - length [Integer] The length of the rotation.
...
@@ -17,10 +17,10 @@ module IncidentManagement
...
@@ -17,10 +17,10 @@ module IncidentManagement
# @option opts - participant [User] The user who is part of the rotation
# @option opts - participant [User] The user who is part of the rotation
# @option opts - color_palette [String] The color palette to assign to the on-call user, for example: "blue".
# @option opts - color_palette [String] The color palette to assign to the on-call user, for example: "blue".
# @option opts - color_weight [String] The color weight to assign to for the on-call user, for example "500". Max 4 chars.
# @option opts - color_weight [String] The color weight to assign to for the on-call user, for example "500". Max 4 chars.
def
initialize
(
schedule
,
project
,
current_
user
,
params
)
def
initialize
(
schedule
,
project
,
user
,
params
)
@schedule
=
schedule
@schedule
=
schedule
@project
=
project
@project
=
project
@
current_user
=
current_
user
@
user
=
user
@rotation_params
=
params
.
except
(
:participants
)
@rotation_params
=
params
.
except
(
:participants
)
@participants_params
=
Array
(
params
[
:participants
])
@participants_params
=
Array
(
params
[
:participants
])
end
end
...
@@ -49,15 +49,7 @@ module IncidentManagement
...
@@ -49,15 +49,7 @@ module IncidentManagement
private
private
attr_reader
:schedule
,
:project
,
:current_user
,
:rotation_params
,
:participants_params
attr_reader
:schedule
,
:project
,
:user
,
:rotation_params
,
:participants_params
def
allowed?
Ability
.
allowed?
(
current_user
,
:admin_incident_management_oncall_schedule
,
project
)
end
def
available?
::
Gitlab
::
IncidentManagement
.
oncall_schedules_available?
(
project
)
end
def
duplicated_users?
def
duplicated_users?
users
=
participants_params
.
map
{
|
participant
|
participant
[
:user
]
}
users
=
participants_params
.
map
{
|
participant
|
participant
[
:user
]
}
...
@@ -98,14 +90,6 @@ module IncidentManagement
...
@@ -98,14 +90,6 @@ module IncidentManagement
OncallParticipant
.
insert_all
(
participant_rows
(
participants
))
OncallParticipant
.
insert_all
(
participant_rows
(
participants
))
end
end
def
error
(
message
)
ServiceResponse
.
error
(
message:
message
)
end
def
success
(
oncall_rotation
)
ServiceResponse
.
success
(
payload:
{
oncall_rotation:
oncall_rotation
})
end
def
error_participant_has_no_permission
def
error_participant_has_no_permission
error
(
'A participant has insufficient permissions to access the project'
)
error
(
'A participant has insufficient permissions to access the project'
)
end
end
...
@@ -122,10 +106,6 @@ module IncidentManagement
...
@@ -122,10 +106,6 @@ module IncidentManagement
error
(
_
(
'You have insufficient permissions to create an on-call rotation for this project'
))
error
(
_
(
'You have insufficient permissions to create an on-call rotation for this project'
))
end
end
def
error_no_license
error
(
_
(
'Your license does not support on-call rotations'
))
end
def
error_in_validation
(
object
)
def
error_in_validation
(
object
)
error
(
object
.
errors
.
full_messages
.
to_sentence
)
error
(
object
.
errors
.
full_messages
.
to_sentence
)
end
end
...
...
ee/app/services/incident_management/oncall_rotations/destroy_service.rb
View file @
35383186
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
module
IncidentManagement
module
IncidentManagement
module
OncallRotations
module
OncallRotations
class
DestroyService
class
DestroyService
<
BaseService
# @param oncall_schedule [IncidentManagement::OncallRotation]
# @param oncall_schedule [IncidentManagement::OncallRotation]
# @param user [User]
# @param user [User]
def
initialize
(
oncall_rotation
,
user
)
def
initialize
(
oncall_rotation
,
user
)
...
@@ -16,7 +16,7 @@ module IncidentManagement
...
@@ -16,7 +16,7 @@ module IncidentManagement
return
error_no_permissions
unless
allowed?
return
error_no_permissions
unless
allowed?
if
oncall_rotation
.
destroy
if
oncall_rotation
.
destroy
success
success
(
oncall_rotation
)
else
else
error
(
oncall_rotation
.
errors
.
full_messages
.
to_sentence
)
error
(
oncall_rotation
.
errors
.
full_messages
.
to_sentence
)
end
end
...
@@ -26,29 +26,9 @@ module IncidentManagement
...
@@ -26,29 +26,9 @@ module IncidentManagement
attr_reader
:oncall_rotation
,
:user
,
:project
attr_reader
:oncall_rotation
,
:user
,
:project
def
allowed?
user
&
.
can?
(
:admin_incident_management_oncall_schedule
,
project
)
end
def
available?
::
Gitlab
::
IncidentManagement
.
oncall_schedules_available?
(
project
)
end
def
error
(
message
)
ServiceResponse
.
error
(
message:
message
)
end
def
success
ServiceResponse
.
success
(
payload:
{
oncall_rotation:
oncall_rotation
})
end
def
error_no_permissions
def
error_no_permissions
error
(
_
(
'You have insufficient permissions to remove an on-call rotation from this project'
))
error
(
_
(
'You have insufficient permissions to remove an on-call rotation from this project'
))
end
end
def
error_no_license
error
(
_
(
'Your license does not support on-call rotations'
))
end
end
end
end
end
end
end
ee/app/services/incident_management/oncall_schedules/base_service.rb
0 → 100644
View file @
35383186
# frozen_string_literal: true
module
IncidentManagement
module
OncallSchedules
class
BaseService
def
allowed?
user
&
.
can?
(
:admin_incident_management_oncall_schedule
,
project
)
end
def
available?
::
Gitlab
::
IncidentManagement
.
oncall_schedules_available?
(
project
)
end
def
error
(
message
)
ServiceResponse
.
error
(
message:
message
)
end
def
success
(
oncall_schedule
)
ServiceResponse
.
success
(
payload:
{
oncall_schedule:
oncall_schedule
})
end
def
error_no_license
error
(
_
(
'Your license does not support on-call schedules'
))
end
end
end
end
ee/app/services/incident_management/oncall_schedules/create_service.rb
View file @
35383186
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
module
IncidentManagement
module
IncidentManagement
module
OncallSchedules
module
OncallSchedules
class
CreateService
class
CreateService
<
BaseService
# @param project [Project]
# @param project [Project]
# @param user [User]
# @param user [User]
# @param params [Hash]
# @param params [Hash]
...
@@ -26,30 +26,10 @@ module IncidentManagement
...
@@ -26,30 +26,10 @@ module IncidentManagement
attr_reader
:project
,
:user
,
:params
attr_reader
:project
,
:user
,
:params
def
allowed?
user
&
.
can?
(
:admin_incident_management_oncall_schedule
,
project
)
end
def
available?
::
Gitlab
::
IncidentManagement
.
oncall_schedules_available?
(
project
)
end
def
error
(
message
)
ServiceResponse
.
error
(
message:
message
)
end
def
success
(
oncall_schedule
)
ServiceResponse
.
success
(
payload:
{
oncall_schedule:
oncall_schedule
})
end
def
error_no_permissions
def
error_no_permissions
error
(
_
(
'You have insufficient permissions to create an on-call schedule for this project'
))
error
(
_
(
'You have insufficient permissions to create an on-call schedule for this project'
))
end
end
def
error_no_license
error
(
_
(
'Your license does not support on-call schedules'
))
end
def
error_in_create
(
oncall_schedule
)
def
error_in_create
(
oncall_schedule
)
error
(
oncall_schedule
.
errors
.
full_messages
.
to_sentence
)
error
(
oncall_schedule
.
errors
.
full_messages
.
to_sentence
)
end
end
...
...
ee/app/services/incident_management/oncall_schedules/destroy_service.rb
View file @
35383186
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
module
IncidentManagement
module
IncidentManagement
module
OncallSchedules
module
OncallSchedules
class
DestroyService
class
DestroyService
<
BaseService
# @param oncall_schedule [IncidentManagement::OncallSchedule]
# @param oncall_schedule [IncidentManagement::OncallSchedule]
# @param user [User]
# @param user [User]
def
initialize
(
oncall_schedule
,
user
)
def
initialize
(
oncall_schedule
,
user
)
...
@@ -16,7 +16,7 @@ module IncidentManagement
...
@@ -16,7 +16,7 @@ module IncidentManagement
return
error_no_permissions
unless
allowed?
return
error_no_permissions
unless
allowed?
if
oncall_schedule
.
destroy
if
oncall_schedule
.
destroy
success
success
(
oncall_schedule
)
else
else
error
(
oncall_schedule
.
errors
.
full_messages
.
to_sentence
)
error
(
oncall_schedule
.
errors
.
full_messages
.
to_sentence
)
end
end
...
@@ -26,29 +26,9 @@ module IncidentManagement
...
@@ -26,29 +26,9 @@ module IncidentManagement
attr_reader
:oncall_schedule
,
:user
,
:project
attr_reader
:oncall_schedule
,
:user
,
:project
def
allowed?
user
&
.
can?
(
:admin_incident_management_oncall_schedule
,
project
)
end
def
available?
::
Gitlab
::
IncidentManagement
.
oncall_schedules_available?
(
project
)
end
def
error
(
message
)
ServiceResponse
.
error
(
message:
message
)
end
def
success
ServiceResponse
.
success
(
payload:
{
oncall_schedule:
oncall_schedule
})
end
def
error_no_permissions
def
error_no_permissions
error
(
_
(
'You have insufficient permissions to remove an on-call schedule from this project'
))
error
(
_
(
'You have insufficient permissions to remove an on-call schedule from this project'
))
end
end
def
error_no_license
error
(
_
(
'Your license does not support on-call schedules'
))
end
end
end
end
end
end
end
ee/app/services/incident_management/oncall_schedules/update_service.rb
View file @
35383186
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
module
IncidentManagement
module
IncidentManagement
module
OncallSchedules
module
OncallSchedules
class
UpdateService
class
UpdateService
<
BaseService
# @param oncall_schedule [IncidentManagement::OncallSchedule]
# @param oncall_schedule [IncidentManagement::OncallSchedule]
# @param user [User]
# @param user [User]
# @param params [Hash]
# @param params [Hash]
...
@@ -28,29 +28,9 @@ module IncidentManagement
...
@@ -28,29 +28,9 @@ module IncidentManagement
attr_reader
:oncall_schedule
,
:user
,
:params
,
:project
attr_reader
:oncall_schedule
,
:user
,
:params
,
:project
def
allowed?
user
&
.
can?
(
:admin_incident_management_oncall_schedule
,
project
)
end
def
available?
::
Gitlab
::
IncidentManagement
.
oncall_schedules_available?
(
project
)
end
def
error
(
message
)
ServiceResponse
.
error
(
message:
message
)
end
def
success
(
oncall_schedule
)
ServiceResponse
.
success
(
payload:
{
oncall_schedule:
oncall_schedule
})
end
def
error_no_permissions
def
error_no_permissions
error
(
_
(
'You have insufficient permissions to update an on-call schedule for this project'
))
error
(
_
(
'You have insufficient permissions to update an on-call schedule for this project'
))
end
end
def
error_no_license
error
(
_
(
'Your license does not support on-call schedules'
))
end
end
end
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