2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
class EnvironmentPolicy < BasePolicy
|
2017-09-10 17:25:29 +05:30
|
|
|
delegate { @subject.project }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
condition(:stop_with_deployment_allowed) do
|
|
|
|
@subject.stop_action_available? &&
|
|
|
|
can?(:create_deployment) && can?(:update_build, @subject.stop_action)
|
|
|
|
end
|
|
|
|
|
|
|
|
condition(:stop_with_update_allowed) do
|
|
|
|
!@subject.stop_action_available? && can?(:update_environment, @subject)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
condition(:stopped) do
|
|
|
|
@subject.stopped?
|
|
|
|
end
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
rule { stop_with_deployment_allowed | stop_with_update_allowed }.enable :stop_environment
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
rule { ~stopped }.prevent(:destroy_environment)
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
EnvironmentPolicy.prepend_if_ee('EE::EnvironmentPolicy')
|