Improve environment policy class

This commit is contained in:
Grzegorz Bizon 2017-05-03 15:42:29 +02:00
parent 88ace4a7ad
commit 83154f2154
1 changed files with 8 additions and 6 deletions

View File

@ -4,12 +4,14 @@ class EnvironmentPolicy < BasePolicy
def rules
delegate! environment.project
if environment.stop_action?
delegate! environment.stop_action
end
if can?(:create_deployment) && can?(:play_build)
can! :stop_environment
if can?(:create_deployment) && environment.stop_action?
can! :stop_environment if can_play_stop_action?
end
end
private
def can_play_stop_action?
Ability.allowed?(user, :play_build, environment.stop_action)
end
end