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

update_service.rb « pipeline_schedules « ci « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2412b5cbd813d818ac83219e9785e59e115ebf61 (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
35
36
37
38
# 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