debian-mirror-gitlab/app/policies/environment_policy.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

25 lines
660 B
Ruby
Raw Normal View History

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
2022-06-21 17:19:12 +05:30
@subject.stop_actions_available? &&
can?(:create_deployment) && can?(:update_build, @subject.stop_actions.last)
2018-11-18 11:00:15 +05:30
end
condition(:stop_with_update_allowed) do
2022-06-21 17:19:12 +05:30
!@subject.stop_actions_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
2021-06-08 01:23:25 +05:30
EnvironmentPolicy.prepend_mod_with('EnvironmentPolicy')