debian-mirror-gitlab/app/services/ci/pipeline_schedules/update_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

39 lines
826 B
Ruby
Raw Normal View History

2023-04-23 21:23:45 +05:30
# frozen_string_literal: true
module Ci
module PipelineSchedules
class UpdateService
def initialize(schedule, user, params)
@schedule = schedule
@user = user
@params = params
end
def execute
return forbidden unless allowed?
if schedule.update(@params)
ServiceResponse.success(payload: schedule)
else
ServiceResponse.error(message: schedule.errors.full_messages)
end
end
private
attr_reader :schedule, :user
def allowed?
user.can?(:update_pipeline_schedule, schedule)
end
def forbidden
ServiceResponse.error(
message: _('The current user is not authorized to update the pipeline schedule'),
reason: :forbidden
)
end
end
end
end