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
2e0ab3a2
Commit
2e0ab3a2
authored
Nov 22, 2020
by
Vitali Tatarintev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add update on-call schedule service
parent
9e5ede6e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
138 additions
and
0 deletions
+138
-0
ee/app/services/incident_management/oncall_schedules/update_service.rb
...es/incident_management/oncall_schedules/update_service.rb
+57
-0
ee/spec/services/incident_management/oncall_schedules/update_service_spec.rb
...cident_management/oncall_schedules/update_service_spec.rb
+81
-0
No files found.
ee/app/services/incident_management/oncall_schedules/update_service.rb
0 → 100644
View file @
2e0ab3a2
# frozen_string_literal: true
module
IncidentManagement
module
OncallSchedules
class
UpdateService
# @param oncall_schedule [IncidentManagement::OncallSchedule]
# @param user [User]
# @param params [Hash]
def
initialize
(
oncall_schedule
,
user
,
params
)
@oncall_schedule
=
oncall_schedule
@user
=
user
@params
=
params
@project
=
oncall_schedule
.
project
end
def
execute
return
error_no_license
unless
available?
return
error_no_permissions
unless
allowed?
if
oncall_schedule
.
update
(
params
)
success
(
oncall_schedule
)
else
error
(
oncall_schedule
.
errors
.
full_messages
.
to_sentence
)
end
end
private
attr_reader
:oncall_schedule
,
:user
,
:params
,
:project
def
allowed?
user
&
.
can?
(
:admin_incident_management_oncall_schedule
,
project
)
end
def
available?
Feature
.
enabled?
(
:oncall_schedules_mvc
,
project
)
&&
project
.
feature_available?
(
:oncall_schedules
)
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
error
(
_
(
'You have insufficient permissions to update an on-call schedule for this project'
))
end
def
error_no_license
error
(
_
(
'Your license does not support on-call schedules'
))
end
end
end
end
ee/spec/services/incident_management/oncall_schedules/update_service_spec.rb
0 → 100644
View file @
2e0ab3a2
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
IncidentManagement
::
OncallSchedules
::
UpdateService
do
let_it_be
(
:user_with_permissions
)
{
create
(
:user
)
}
let_it_be
(
:user_without_permissions
)
{
create
(
:user
)
}
let_it_be_with_refind
(
:project
)
{
create
(
:project
)
}
let!
(
:oncall_schedule
)
{
create
(
:incident_management_oncall_schedule
,
project:
project
)
}
let
(
:current_user
)
{
user_with_permissions
}
let
(
:params
)
{
{
name:
'Updated name'
,
description:
'Updated description'
,
timezone:
'America/New_York'
}
}
let
(
:service
)
{
described_class
.
new
(
oncall_schedule
,
current_user
,
params
)
}
before
do
stub_licensed_features
(
oncall_schedules:
true
)
project
.
add_maintainer
(
user_with_permissions
)
end
describe
'#execute'
do
shared_examples
'error response'
do
|
message
|
it
'has an informative message'
do
expect
(
execute
).
to
be_error
expect
(
execute
.
message
).
to
eq
(
message
)
end
end
subject
(
:execute
)
{
service
.
execute
}
context
'when the current_user is anonymous'
do
let
(
:current_user
)
{
nil
}
it_behaves_like
'error response'
,
'You have insufficient permissions to update an on-call schedule for this project'
end
context
'when the current_user does not have permissions to update on-call schedules'
do
let
(
:current_user
)
{
user_without_permissions
}
it_behaves_like
'error response'
,
'You have insufficient permissions to update an on-call schedule for this project'
end
context
'when feature is not available'
do
before
do
stub_licensed_features
(
oncall_schedules:
false
)
end
it_behaves_like
'error response'
,
'Your license does not support on-call schedules'
end
context
'when feature flag is disabled'
do
before
do
stub_feature_flags
(
oncall_schedules_mvc:
false
)
end
it_behaves_like
'error response'
,
'Your license does not support on-call schedules'
end
context
'when an on-call schedule witht the same name already exists'
do
before
do
create
(
:incident_management_oncall_schedule
,
project:
project
,
name:
params
[
:name
])
end
it_behaves_like
'error response'
,
'Name has already been taken'
end
context
'with valid params'
do
it
'successfully creates an on-call schedule'
do
response
=
execute
payload
=
response
.
payload
oncall_schedule
.
reload
expect
(
response
).
to
be_success
expect
(
payload
[
:oncall_schedule
]).
to
eq
(
oncall_schedule
)
expect
(
oncall_schedule
).
to
be_a
(
::
IncidentManagement
::
OncallSchedule
)
expect
(
oncall_schedule
.
name
).
to
eq
(
params
[
:name
])
expect
(
oncall_schedule
.
description
).
to
eq
(
params
[
:description
])
expect
(
oncall_schedule
.
timezone
).
to
eq
(
params
[
:timezone
])
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