summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/policies/environment_policy.rb13
-rw-r--r--app/services/ci/stop_environments_service.rb9
2 files changed, 14 insertions, 8 deletions
diff --git a/app/policies/environment_policy.rb b/app/policies/environment_policy.rb
index f4219569161..0b976e5664d 100644
--- a/app/policies/environment_policy.rb
+++ b/app/policies/environment_policy.rb
@@ -1,5 +1,16 @@
class EnvironmentPolicy < BasePolicy
+
+ alias_method :environment, :subject
+
def rules
- delegate! @subject.project
+ delegate! environment.project
+
+ if environment.stop_action?
+ delegate! environment.stop_action
+ end
+
+ if can?(:create_deployment) && can?(:play_build)
+ can! :stop_environment
+ end
end
end
diff --git a/app/services/ci/stop_environments_service.rb b/app/services/ci/stop_environments_service.rb
index bd9735fc0ac..43c9a065fcf 100644
--- a/app/services/ci/stop_environments_service.rb
+++ b/app/services/ci/stop_environments_service.rb
@@ -5,12 +5,11 @@ module Ci
def execute(branch_name)
@ref = branch_name
- return unless has_ref?
- return unless can?(current_user, :create_deployment, project)
+ return unless @ref.present?
environments.each do |environment|
next unless environment.stop_action?
- next unless can?(current_user, :play_build, environment.stop_action)
+ next unless can?(current_user, :stop_environment, environment)
environment.stop_with_action!(current_user)
end
@@ -18,10 +17,6 @@ module Ci
private
- def has_ref?
- @ref.present?
- end
-
def environments
@environments ||= EnvironmentsFinder
.new(project, current_user, ref: @ref, recently_updated: true)