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
7e90bed5
Commit
7e90bed5
authored
Dec 08, 2020
by
Sean Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check participant limit in service
parent
8aafe8b4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
2 deletions
+23
-2
ee/app/services/incident_management/oncall_rotations/create_service.rb
...es/incident_management/oncall_rotations/create_service.rb
+12
-2
ee/spec/services/incident_management/oncall_rotations/create_service_spec.rb
...cident_management/oncall_rotations/create_service_spec.rb
+11
-0
No files found.
ee/app/services/incident_management/oncall_rotations/create_service.rb
View file @
7e90bed5
...
...
@@ -3,6 +3,8 @@
module
IncidentManagement
module
OncallRotations
class
CreateService
MAXIMUM_PARTICIPANTS
=
100
# @param schedule [IncidentManagement::OncallSchedule]
# @param project [Project]
# @param current_user [User]
...
...
@@ -26,11 +28,15 @@ module IncidentManagement
return
error_no_license
unless
available?
return
error_no_permissions
unless
allowed?
participant_params
=
Array
(
params
[
:participants
])
return
error_too_many_participants
if
participant_params
.
size
>
MAXIMUM_PARTICIPANTS
oncall_rotation
=
schedule
.
rotations
.
create
(
params
.
except
(
:participants
))
return
error_in_create
(
oncall_rotation
)
unless
oncall_rotation
.
persisted?
new_participants
=
Array
(
par
ams
[
:participants
]
).
map
do
|
participant
|
new_participants
=
Array
(
par
ticipant_params
).
map
do
|
participant
|
OncallParticipant
.
new
(
rotation:
oncall_rotation
,
user:
participant
[
:user
],
...
...
@@ -64,6 +70,10 @@ module IncidentManagement
ServiceResponse
.
success
(
payload:
{
oncall_rotation:
oncall_rotation
})
end
def
error_too_many_participants
error
(
"A maximum of
#{
MAXIMUM_PARTICIPANTS
}
participants can be added"
)
end
def
error_no_permissions
error
(
'You have insufficient permissions to create an on-call rotation for this project'
)
end
...
...
ee/spec/services/incident_management/oncall_rotations/create_service_spec.rb
View file @
7e90bed5
...
...
@@ -74,6 +74,17 @@ RSpec.describe IncidentManagement::OncallRotations::CreateService do
it_behaves_like
'error response'
,
'Name has already been taken'
end
context
'when too many participants'
do
before
do
stub_const
(
'IncidentManagement::OncallRotations::CreateService::MAXIMUM_PARTICIPANTS'
,
0
)
end
it
'has an informative error message'
do
expect
(
execute
).
to
be_error
expect
(
execute
.
message
).
to
eq
(
"A maximum of
#{
IncidentManagement
::
OncallRotations
::
CreateService
::
MAXIMUM_PARTICIPANTS
}
participants can be added"
)
end
end
context
'with valid params'
do
it
'successfully creates an on-call rotation'
do
expect
(
execute
).
to
be_success
...
...
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