Rename environments stop action method
This makes it more explicit that an environment is not a stop action, but instead is merely contains a stop action.
This commit is contained in:
parent
66c3007ccb
commit
e270366d84
8 changed files with 27 additions and 17 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -104,7 +104,7 @@ describe('Environment item', () => {
|
|||
},
|
||||
],
|
||||
},
|
||||
'stop_action?': true,
|
||||
has_stop_action: true,
|
||||
environment_path: 'root/ci-folders/environments/31',
|
||||
created_at: '2016-11-07T11:11:16.525Z',
|
||||
updated_at: '2016-11-10T15:55:58.778Z',
|
||||
|
|
|
@ -7,7 +7,7 @@ export const environmentsList = [
|
|||
external_url: null,
|
||||
environment_type: null,
|
||||
last_deployment: null,
|
||||
'stop_action?': false,
|
||||
has_stop_action: false,
|
||||
environment_path: '/root/review-app/environments/7',
|
||||
stop_path: '/root/review-app/environments/7/stop',
|
||||
created_at: '2017-01-31T10:53:46.894Z',
|
||||
|
@ -22,7 +22,7 @@ export const environmentsList = [
|
|||
external_url: null,
|
||||
environment_type: 'build',
|
||||
last_deployment: null,
|
||||
'stop_action?': false,
|
||||
has_stop_action: false,
|
||||
environment_path: '/root/review-app/environments/12',
|
||||
stop_path: '/root/review-app/environments/12/stop',
|
||||
created_at: '2017-02-01T19:42:18.400Z',
|
||||
|
@ -41,7 +41,7 @@ export const serverData = [
|
|||
external_url: null,
|
||||
environment_type: null,
|
||||
last_deployment: null,
|
||||
'stop_action?': false,
|
||||
has_stop_action: false,
|
||||
environment_path: '/root/review-app/environments/7',
|
||||
stop_path: '/root/review-app/environments/7/stop',
|
||||
created_at: '2017-01-31T10:53:46.894Z',
|
||||
|
@ -58,7 +58,7 @@ export const serverData = [
|
|||
external_url: null,
|
||||
environment_type: 'build',
|
||||
last_deployment: null,
|
||||
'stop_action?': false,
|
||||
has_stop_action: false,
|
||||
environment_path: '/root/review-app/environments/12',
|
||||
stop_path: '/root/review-app/environments/12/stop',
|
||||
created_at: '2017-02-01T19:42:18.400Z',
|
||||
|
@ -77,7 +77,7 @@ export const environment = {
|
|||
external_url: null,
|
||||
environment_type: null,
|
||||
last_deployment: null,
|
||||
'stop_action?': false,
|
||||
has_stop_action: false,
|
||||
environment_path: '/root/review-app/environments/7',
|
||||
stop_path: '/root/review-app/environments/7/stop',
|
||||
created_at: '2017-01-31T10:53:46.894Z',
|
||||
|
@ -95,7 +95,7 @@ export const folder = {
|
|||
external_url: null,
|
||||
environment_type: 'build',
|
||||
last_deployment: null,
|
||||
'stop_action?': false,
|
||||
has_stop_action: false,
|
||||
environment_path: '/root/review-app/environments/12',
|
||||
stop_path: '/root/review-app/environments/12/stop',
|
||||
created_at: '2017-02-01T19:42:18.400Z',
|
||||
|
|
|
@ -170,8 +170,8 @@ describe Environment do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#stop_action?' do
|
||||
subject { environment.stop_action? }
|
||||
describe '#stop_action_available?' do
|
||||
subject { environment.stop_action_available? }
|
||||
|
||||
context 'when no other actions' do
|
||||
it { is_expected.to be_falsey }
|
||||
|
@ -179,8 +179,17 @@ describe Environment do
|
|||
|
||||
context 'when matching action is defined' do
|
||||
let(:build) { create(:ci_build) }
|
||||
let!(:deployment) { create(:deployment, environment: environment, deployable: build, on_stop: 'close_app') }
|
||||
let!(:close_action) { create(:ci_build, :manual, pipeline: build.pipeline, name: 'close_app') }
|
||||
|
||||
let!(:deployment) do
|
||||
create(:deployment, environment: environment,
|
||||
deployable: build,
|
||||
on_stop: 'close_app')
|
||||
end
|
||||
|
||||
let!(:close_action) do
|
||||
create(:ci_build, :manual, pipeline: build.pipeline,
|
||||
name: 'close_app')
|
||||
end
|
||||
|
||||
context 'when environment is available' do
|
||||
before do
|
||||
|
|
Loading…
Reference in a new issue