summaryrefslogtreecommitdiff
path: root/app/policies/environment_policy.rb
blob: 72db6d31764905bca1885562a82f2b990e562502 (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
# frozen_string_literal: true

class EnvironmentPolicy < BasePolicy
  delegate { @subject.project }

  condition(:stop_with_deployment_allowed) do
    @subject.stop_actions_available? &&
      can?(:create_deployment) && can?(:update_build, @subject.stop_actions.last)
  end

  condition(:stop_with_update_allowed) do
    !@subject.stop_actions_available? && can?(:update_environment, @subject)
  end

  condition(:stopped) do
    @subject.stopped?
  end

  rule { stop_with_deployment_allowed | stop_with_update_allowed }.enable :stop_environment

  rule { ~stopped }.prevent(:destroy_environment)
end

EnvironmentPolicy.prepend_mod_with('EnvironmentPolicy')