debian-mirror-gitlab/app/services/ci/pipeline_schedules/take_ownership_service.rb
2023-05-27 22:25:52 +05:30

34 lines
737 B
Ruby

# 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?(:admin_pipeline_schedule, schedule)
end
def forbidden
ServiceResponse.error(message: _('Failed to change the owner'), reason: :access_denied)
end
end
end
end