summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2018-07-16 09:56:19 +0000
committerKamil Trzciński <ayufan@ayufan.eu>2018-07-16 09:56:19 +0000
commit6c237350b3967881cf9da50ec13a536e1a7e6755 (patch)
tree8ce3d51df9ce9e9716ef3ce8626b973d7f882547 /app
parentf73fb2444985155c5bbec4fc43de9fbfb6710825 (diff)
parentaf00a1591412655202a634fbca999b80b97a676e (diff)
downloadgitlab-ce-6c237350b3967881cf9da50ec13a536e1a7e6755.tar.gz
Merge branch 'fix/gb/rename-environments-stop-actions' into 'master'
Make it more explicit what environment stop actions are Closes #48672 See merge request gitlab-org/gitlab-ce!20587
Diffstat (limited to 'app')
-rw-r--r--app/models/deployment.rb4
-rw-r--r--app/models/environment.rb2
-rw-r--r--app/policies/environment_policy.rb5
-rw-r--r--app/serializers/environment_entity.rb2
-rw-r--r--app/services/ci/stop_environments_service.rb2
-rw-r--r--app/views/projects/environments/show.html.haml2
6 files changed, 7 insertions, 10 deletions
diff --git a/app/models/deployment.rb b/app/models/deployment.rb
index ac86e9e8de0..687246b47b2 100644
--- a/app/models/deployment.rb
+++ b/app/models/deployment.rb
@@ -92,10 +92,6 @@ class Deployment < ActiveRecord::Base
@stop_action ||= manual_actions.find_by(name: on_stop)
end
- def stop_action?
- stop_action.present?
- end
-
def formatted_deployment_time
created_at.to_time.in_time_zone.to_s(:medium)
end
diff --git a/app/models/environment.rb b/app/models/environment.rb
index 8d523dae324..4856d313318 100644
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -117,7 +117,7 @@ class Environment < ActiveRecord::Base
external_url.gsub(%r{\A.*?://}, '')
end
- def stop_action?
+ def stop_action_available?
available? && stop_action.present?
end
diff --git a/app/policies/environment_policy.rb b/app/policies/environment_policy.rb
index 978dc3a7c81..2d07311db72 100644
--- a/app/policies/environment_policy.rb
+++ b/app/policies/environment_policy.rb
@@ -2,11 +2,12 @@ class EnvironmentPolicy < BasePolicy
delegate { @subject.project }
condition(:stop_with_deployment_allowed) do
- @subject.stop_action? && can?(:create_deployment) && can?(:update_build, @subject.stop_action)
+ @subject.stop_action_available? &&
+ can?(:create_deployment) && can?(:update_build, @subject.stop_action)
end
condition(:stop_with_update_allowed) do
- !@subject.stop_action? && can?(:update_environment, @subject)
+ !@subject.stop_action_available? && can?(:update_environment, @subject)
end
rule { stop_with_deployment_allowed | stop_with_update_allowed }.enable :stop_environment
diff --git a/app/serializers/environment_entity.rb b/app/serializers/environment_entity.rb
index 0fc3f92b151..83558fc6659 100644
--- a/app/serializers/environment_entity.rb
+++ b/app/serializers/environment_entity.rb
@@ -7,7 +7,7 @@ class EnvironmentEntity < Grape::Entity
expose :external_url
expose :environment_type
expose :last_deployment, using: DeploymentEntity
- expose :stop_action?, as: :has_stop_action
+ expose :stop_action_available?, as: :has_stop_action
expose :metrics_path, if: -> (environment, _) { environment.has_metrics? } do |environment|
metrics_project_environment_path(environment.project, environment)
diff --git a/app/services/ci/stop_environments_service.rb b/app/services/ci/stop_environments_service.rb
index 43c9a065fcf..439746e82bd 100644
--- a/app/services/ci/stop_environments_service.rb
+++ b/app/services/ci/stop_environments_service.rb
@@ -8,7 +8,7 @@ module Ci
return unless @ref.present?
environments.each do |environment|
- next unless environment.stop_action?
+ next unless environment.stop_action_available?
next unless can?(current_user, :stop_environment, environment)
environment.stop_with_action!(current_user)
diff --git a/app/views/projects/environments/show.html.haml b/app/views/projects/environments/show.html.haml
index a33bc9d4ce6..c7890b37381 100644
--- a/app/views/projects/environments/show.html.haml
+++ b/app/views/projects/environments/show.html.haml
@@ -16,7 +16,7 @@
?
.modal-body
%p= s_('Environments|Are you sure you want to stop this environment?')
- - unless @environment.stop_action?
+ - unless @environment.stop_action_available?
.warning_message
%p= s_('Environments|Note that this action will stop the environment, but it will %{emphasis_start}not%{emphasis_end} have an effect on any existing deployment due to no “stop environment action” being defined in the %{ci_config_link_start}.gitlab-ci.yml%{ci_config_link_end} file.').html_safe % { emphasis_start: '<strong>'.html_safe,
emphasis_end: '</strong>'.html_safe,