diff options
Diffstat (limited to 'app/services/ci/pipeline_schedules/update_service.rb')
-rw-r--r-- | app/services/ci/pipeline_schedules/update_service.rb | 34 |
1 files changed, 6 insertions, 28 deletions
diff --git a/app/services/ci/pipeline_schedules/update_service.rb b/app/services/ci/pipeline_schedules/update_service.rb index 28c22e0a868..2fd1173ecce 100644 --- a/app/services/ci/pipeline_schedules/update_service.rb +++ b/app/services/ci/pipeline_schedules/update_service.rb @@ -2,44 +2,22 @@ module Ci module PipelineSchedules - class UpdateService + class UpdateService < BaseSaveService + AUTHORIZE = :update_pipeline_schedule + def initialize(schedule, user, params) @schedule = schedule @user = user + @project = schedule.project @params = params end - def execute - return forbidden unless allowed? - - schedule.assign_attributes(params) - - if schedule.save - ServiceResponse.success(payload: schedule) - else - ServiceResponse.error(message: schedule.errors.full_messages) - end - end - private - attr_reader :schedule, :user, :params - - def allowed? - user.can?(:update_pipeline_schedule, schedule) - end - - def forbidden - # We add the error to the base object too - # because model errors are used in the API responses and the `form_errors` helper. - schedule.errors.add(:base, forbidden_message) - - ServiceResponse.error(message: [forbidden_message], reason: :forbidden) - end - - def forbidden_message + def authorize_message _('The current user is not authorized to update the pipeline schedule') end + strong_memoize_attr :authorize_message end end end |