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

reset_auto_stop_service.rb « environments « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 237629fda79965a39a108ce53b515c297898055b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# frozen_string_literal: true

module Environments
  class ResetAutoStopService < ::BaseService
    def execute(environment)
      return error(_('Failed to cancel auto stop because you do not have permission to update the environment.')) unless can_update_environment?(environment)
      return error(_('Failed to cancel auto stop because the environment is not set as auto stop.')) unless environment.auto_stop_at?

      if environment.reset_auto_stop
        success
      else
        error(_('Failed to cancel auto stop because failed to update the environment.'))
      end
    end

    private

    def can_update_environment?(environment)
      can?(current_user, :update_environment, environment)
    end
  end
end