2018-07-24 06:00:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-18 13:40:39 -04:00
|
|
|
class EnvironmentPolicy < BasePolicy
|
2017-04-06 17:06:42 -04:00
|
|
|
delegate { @subject.project }
|
2017-05-01 07:38:57 -04:00
|
|
|
|
2018-07-10 04:11:04 -04:00
|
|
|
condition(:stop_with_deployment_allowed) do
|
2018-07-12 06:22:11 -04:00
|
|
|
@subject.stop_action_available? &&
|
|
|
|
can?(:create_deployment) && can?(:update_build, @subject.stop_action)
|
2017-05-03 09:42:29 -04:00
|
|
|
end
|
2017-05-01 07:38:57 -04:00
|
|
|
|
2018-07-10 04:11:04 -04:00
|
|
|
condition(:stop_with_update_allowed) do
|
2018-07-12 06:22:11 -04:00
|
|
|
!@subject.stop_action_available? && can?(:update_environment, @subject)
|
2018-07-10 04:11:04 -04:00
|
|
|
end
|
|
|
|
|
2020-03-25 05:08:11 -04:00
|
|
|
condition(:stopped) do
|
|
|
|
@subject.stopped?
|
|
|
|
end
|
|
|
|
|
2018-07-10 04:11:04 -04:00
|
|
|
rule { stop_with_deployment_allowed | stop_with_update_allowed }.enable :stop_environment
|
2020-03-25 05:08:11 -04:00
|
|
|
|
|
|
|
rule { ~stopped }.prevent(:destroy_environment)
|
2016-08-18 13:40:39 -04:00
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
EnvironmentPolicy.prepend_mod_with('EnvironmentPolicy')
|