blob: 9b4001c74bdee02fc474be3bedeaaca7fdb0ad70 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# frozen_string_literal: true
module Ci
module PipelineSchedules
class TakeOwnershipService
def initialize(schedule, user)
@schedule = schedule
@user = user
end
def execute
return forbidden unless allowed?
if schedule.update(owner: user)
ServiceResponse.success(payload: schedule)
else
ServiceResponse.error(message: schedule.errors.full_messages)
end
end
private
attr_reader :schedule, :user
def allowed?
user.can?(:take_ownership_pipeline_schedule, schedule)
end
def forbidden
ServiceResponse.error(message: _('Failed to change the owner'), reason: :access_denied)
end
end
end
end
|