Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/ci/pipeline_schedules/update_service.rb')
-rw-r--r--app/services/ci/pipeline_schedules/update_service.rb19
1 files changed, 13 insertions, 6 deletions
diff --git a/app/services/ci/pipeline_schedules/update_service.rb b/app/services/ci/pipeline_schedules/update_service.rb
index 2412b5cbd81..28c22e0a868 100644
--- a/app/services/ci/pipeline_schedules/update_service.rb
+++ b/app/services/ci/pipeline_schedules/update_service.rb
@@ -12,7 +12,9 @@ module Ci
def execute
return forbidden unless allowed?
- if schedule.update(@params)
+ schedule.assign_attributes(params)
+
+ if schedule.save
ServiceResponse.success(payload: schedule)
else
ServiceResponse.error(message: schedule.errors.full_messages)
@@ -21,17 +23,22 @@ module Ci
private
- attr_reader :schedule, :user
+ attr_reader :schedule, :user, :params
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
- )
+ # 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
+ _('The current user is not authorized to update the pipeline schedule')
end
end
end