From 16cca3a0ea7f4b95e99d7b3e8d4953334fa7bec7 Mon Sep 17 00:00:00 2001 From: Toon Claes Date: Fri, 17 Mar 2017 17:25:17 +0100 Subject: Expose if action is playable in JSON To avoid a manual build action being played (resulting in a 404), expose `playable?` in the JSON so the frontend can disable/hide the play button if it's not playable. --- app/assets/javascripts/environments/components/environment_item.js | 1 + app/serializers/build_action_entity.rb | 2 ++ app/serializers/build_entity.rb | 1 + spec/serializers/build_action_entity_spec.rb | 4 ++++ spec/serializers/build_entity_spec.rb | 4 ++++ 5 files changed, 12 insertions(+) diff --git a/app/assets/javascripts/environments/components/environment_item.js b/app/assets/javascripts/environments/components/environment_item.js index 93919d41c60..9d753b4f808 100644 --- a/app/assets/javascripts/environments/components/environment_item.js +++ b/app/assets/javascripts/environments/components/environment_item.js @@ -141,6 +141,7 @@ export default { const parsedAction = { name: gl.text.humanize(action.name), play_path: action.play_path, + playable: action.playable, }; return parsedAction; }); diff --git a/app/serializers/build_action_entity.rb b/app/serializers/build_action_entity.rb index 184f5fd4b52..184b4b7a681 100644 --- a/app/serializers/build_action_entity.rb +++ b/app/serializers/build_action_entity.rb @@ -11,4 +11,6 @@ class BuildActionEntity < Grape::Entity build.project, build) end + + expose :playable?, as: :playable end diff --git a/app/serializers/build_entity.rb b/app/serializers/build_entity.rb index 5bcbe285052..2c116102888 100644 --- a/app/serializers/build_entity.rb +++ b/app/serializers/build_entity.rb @@ -16,6 +16,7 @@ class BuildEntity < Grape::Entity path_to(:play_namespace_project_build, build) end + expose :playable?, as: :playable expose :created_at expose :updated_at diff --git a/spec/serializers/build_action_entity_spec.rb b/spec/serializers/build_action_entity_spec.rb index 0f7be8b2c39..54ac17447b1 100644 --- a/spec/serializers/build_action_entity_spec.rb +++ b/spec/serializers/build_action_entity_spec.rb @@ -17,5 +17,9 @@ describe BuildActionEntity do it 'contains path to the action play' do expect(subject[:path]).to include "builds/#{build.id}/play" end + + it 'contains whether it is playable' do + expect(subject[:playable]).to eq build.playable? + end end end diff --git a/spec/serializers/build_entity_spec.rb b/spec/serializers/build_entity_spec.rb index 60c9642ee2c..eed957fa5ef 100644 --- a/spec/serializers/build_entity_spec.rb +++ b/spec/serializers/build_entity_spec.rb @@ -18,6 +18,10 @@ describe BuildEntity do expect(subject).not_to include(/variables/) end + it 'contains whether it is playable' do + expect(subject[:playable]).to eq build.playable? + end + it 'contains timestamps' do expect(subject).to include(:created_at, :updated_at) end -- cgit v1.2.1 From 3db1b959f6488cf861a2bdf32f1c5ff336f7a881 Mon Sep 17 00:00:00 2001 From: Filipa Lacerda Date: Mon, 3 Apr 2017 17:54:16 +0100 Subject: Buttons will be disabled when playable key is false --- .../javascripts/environments/components/environment_actions.js | 6 +++++- .../vue_pipelines_index/components/pipelines_actions.js | 8 +++++--- changelogs/unreleased/tc-fix-unplayable-build-action-404.yml | 4 ++++ 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 changelogs/unreleased/tc-fix-unplayable-build-action-404.yml diff --git a/app/assets/javascripts/environments/components/environment_actions.js b/app/assets/javascripts/environments/components/environment_actions.js index 385085c03e2..49b3ae683d0 100644 --- a/app/assets/javascripts/environments/components/environment_actions.js +++ b/app/assets/javascripts/environments/components/environment_actions.js @@ -50,6 +50,7 @@ export default { template: `
diff --git a/changelogs/unreleased/tc-fix-unplayable-build-action-404.yml b/changelogs/unreleased/tc-fix-unplayable-build-action-404.yml new file mode 100644 index 00000000000..c5fb79a3936 --- /dev/null +++ b/changelogs/unreleased/tc-fix-unplayable-build-action-404.yml @@ -0,0 +1,4 @@ +--- +title: Disable pipeline +merge_request: 10052 +author: -- cgit v1.2.1 From d037a2e998b807d01585a48af90a3b3182eeebc5 Mon Sep 17 00:00:00 2001 From: Filipa Lacerda Date: Tue, 4 Apr 2017 09:14:46 +0100 Subject: Fix typo Adds tests --- .../environments/components/environment_actions.js | 2 +- .../components/pipelines_actions.js | 6 +++--- spec/factories/ci/builds.rb | 5 +++++ spec/factories/environments.rb | 5 +++++ .../projects/environments/environments_spec.rb | 15 +++++++++++++++ spec/features/projects/pipelines/pipelines_spec.rb | 18 ++++++++++++++++++ 6 files changed, 47 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/environments/components/environment_actions.js b/app/assets/javascripts/environments/components/environment_actions.js index 49b3ae683d0..b88b1c6556e 100644 --- a/app/assets/javascripts/environments/components/environment_actions.js +++ b/app/assets/javascripts/environments/components/environment_actions.js @@ -69,7 +69,7 @@ export default { type="button" @click="onClickAction(action.play_path)" class="js-manual-action-link no-btn btn" - :class="{ 'disabled': !actions.playable }" + :class="{ 'disabled': !action.playable }" :disabled="!action.playable"> ${playIconSvg} diff --git a/app/assets/javascripts/vue_pipelines_index/components/pipelines_actions.js b/app/assets/javascripts/vue_pipelines_index/components/pipelines_actions.js index 8e9850233ab..5eebda93b39 100644 --- a/app/assets/javascripts/vue_pipelines_index/components/pipelines_actions.js +++ b/app/assets/javascripts/vue_pipelines_index/components/pipelines_actions.js @@ -49,7 +49,7 @@ export default { data-toggle="dropdown" data-placement="top" aria-label="Manual job" - :disabled="isDisabled"> + :disabled="isLoading"> ${playIconSvg} @@ -60,9 +60,9 @@ export default { diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb index f78086211f7..87a0c95c4dc 100644 --- a/spec/factories/ci/builds.rb +++ b/spec/factories/ci/builds.rb @@ -192,5 +192,10 @@ FactoryGirl.define do trait :no_options do options { {} } end + + trait :non_playable do + status 'created' + self.when 'manual' + end end end diff --git a/spec/factories/environments.rb b/spec/factories/environments.rb index 0852dda6b29..3fbf24b5c7d 100644 --- a/spec/factories/environments.rb +++ b/spec/factories/environments.rb @@ -32,5 +32,10 @@ FactoryGirl.define do environment.update_attribute(:deployments, [deployment]) end end + + trait :non_playable do + status 'created' + self.when 'manual' + end end end diff --git a/spec/features/projects/environments/environments_spec.rb b/spec/features/projects/environments/environments_spec.rb index 641e2cf7402..4f78105cae1 100644 --- a/spec/features/projects/environments/environments_spec.rb +++ b/spec/features/projects/environments/environments_spec.rb @@ -115,6 +115,21 @@ feature 'Environments page', :feature, :js do .not_to change { Ci::Pipeline.count } end + scenario 'when action is non playable', js: true do + given(:action) do + create(:ci_build, :manual, :non_playable, + pipeline: pipeline, + name: 'close_app') + end + + it 'has disabled button to the manual action' do + find('.js-dropdown-play-icon-container').click + + expect(page).to have_button('close_app', disabled: true) + end + + end + scenario 'does show build name and id' do expect(page).to have_link("#{build.name} ##{build.id}") end diff --git a/spec/features/projects/pipelines/pipelines_spec.rb b/spec/features/projects/pipelines/pipelines_spec.rb index 2272b19bc8f..b0f6a4235e5 100644 --- a/spec/features/projects/pipelines/pipelines_spec.rb +++ b/spec/features/projects/pipelines/pipelines_spec.rb @@ -197,6 +197,24 @@ describe 'Pipelines', :feature, :js do end end + context 'with non playable manual action' do + let!(:manual) do + create(:ci_build, :manual, :non_playable, + pipeline: pipeline, + name: 'manual build', + stage: 'test', + commands: 'test') + end + + before { visit_project_pipelines } + + it 'has disabled button to the manual action' do + find('.js-pipeline-dropdown-manual-actions').click + + expect(page).to have_button('manual build', disabled: true) + end + end + context 'for generic statuses' do context 'when running' do let!(:running) do -- cgit v1.2.1 From 5197b011a97a86b1c57cff8d8de73c30914c8c76 Mon Sep 17 00:00:00 2001 From: Filipa Lacerda Date: Tue, 4 Apr 2017 14:14:15 +0100 Subject: Fixes broken lints Adds js unit tests --- .../environments/components/environment_actions.js | 23 +++++++++++++++++----- .../components/pipelines_actions.js | 21 ++++++++++++++++---- .../projects/environments/environments_spec.rb | 15 -------------- spec/features/projects/pipelines/pipelines_spec.rb | 18 ----------------- .../environments/environment_actions_spec.js | 15 ++++++++++++++ .../vue_pipelines_index/pipelines_actions_spec.js | 15 ++++++++++++++ 6 files changed, 65 insertions(+), 42 deletions(-) diff --git a/app/assets/javascripts/environments/components/environment_actions.js b/app/assets/javascripts/environments/components/environment_actions.js index b88b1c6556e..4bb7920bb5e 100644 --- a/app/assets/javascripts/environments/components/environment_actions.js +++ b/app/assets/javascripts/environments/components/environment_actions.js @@ -45,6 +45,14 @@ export default { new Flash('An error occured while making the request.'); }); }, + + isActionDisabled(action) { + if (action.playable === undefined) { + return false; + } + + return !action.playable; + }, }, template: ` @@ -59,18 +67,23 @@ export default { :disabled="isLoading"> - - +