Commit 53067cd7 authored by Takuya Noguchi's avatar Takuya Noguchi

Do not show pipeline schedule button for non-member

parent 4daa6da5
...@@ -12,9 +12,10 @@ ...@@ -12,9 +12,10 @@
- schedule_path_proc = ->(scope) { pipeline_schedules_path(@project, scope: scope) } - schedule_path_proc = ->(scope) { pipeline_schedules_path(@project, scope: scope) }
= render "tabs", schedule_path_proc: schedule_path_proc, all_schedules: @all_schedules, scope: @scope = render "tabs", schedule_path_proc: schedule_path_proc, all_schedules: @all_schedules, scope: @scope
.nav-controls - if can?(current_user, :create_pipeline_schedule, @project)
= link_to new_project_pipeline_schedule_path(@project), class: 'btn btn-create' do .nav-controls
%span= _('New schedule') = link_to new_project_pipeline_schedule_path(@project), class: 'btn btn-create' do
%span= _('New schedule')
- if @schedules.present? - if @schedules.present?
%ul.content-list %ul.content-list
......
---
title: Do not show pipeline schedule button for non-member
merge_request: 12757
author: Takuya Noguchi
...@@ -9,188 +9,222 @@ feature 'Pipeline Schedules', :feature, js: true do ...@@ -9,188 +9,222 @@ feature 'Pipeline Schedules', :feature, js: true do
let(:scope) { nil } let(:scope) { nil }
let!(:user) { create(:user) } let!(:user) { create(:user) }
before do context 'logged in as master' do
project.add_master(user)
sign_in(user)
end
describe 'GET /projects/pipeline_schedules' do
before do before do
visit_pipelines_schedules project.add_master(user)
gitlab_sign_in(user)
end end
describe 'The view' do describe 'GET /projects/pipeline_schedules' do
it 'displays the required information description' do before do
page.within('.pipeline-schedule-table-row') do visit_pipelines_schedules
expect(page).to have_content('pipeline schedule')
expect(find(".next-run-cell time")['data-original-title'])
.to include(pipeline_schedule.real_next_run.strftime('%b %-d, %Y'))
expect(page).to have_link('master')
expect(page).to have_link("##{pipeline.id}")
end
end end
it 'creates a new scheduled pipeline' do describe 'The view' do
click_link 'New schedule' it 'displays the required information description' do
page.within('.pipeline-schedule-table-row') do
expect(page).to have_content('pipeline schedule')
expect(find(".next-run-cell time")['data-original-title'])
.to include(pipeline_schedule.real_next_run.strftime('%b %-d, %Y'))
expect(page).to have_link('master')
expect(page).to have_link("##{pipeline.id}")
end
end
expect(page).to have_content('Schedule a new pipeline') it 'creates a new scheduled pipeline' do
end click_link 'New schedule'
it 'changes ownership of the pipeline' do expect(page).to have_content('Schedule a new pipeline')
click_link 'Take ownership'
page.within('.pipeline-schedule-table-row') do
expect(page).not_to have_content('No owner')
expect(page).to have_link('John Doe')
end end
end
it 'edits the pipeline' do it 'changes ownership of the pipeline' do
page.within('.pipeline-schedule-table-row') do click_link 'Take ownership'
click_link 'Edit' page.within('.pipeline-schedule-table-row') do
expect(page).not_to have_content('No owner')
expect(page).to have_link('John Doe')
end
end end
expect(page).to have_content('Edit Pipeline Schedule') it 'edits the pipeline' do
page.within('.pipeline-schedule-table-row') do
click_link 'Edit'
end
expect(page).to have_content('Edit Pipeline Schedule')
end
it 'deletes the pipeline' do
click_link 'Delete'
expect(page).not_to have_css(".pipeline-schedule-table-row")
end
end end
it 'deletes the pipeline' do context 'when ref is nil' do
click_link 'Delete' before do
pipeline_schedule.update_attribute(:ref, nil)
visit_pipelines_schedules
end
expect(page).not_to have_css(".pipeline-schedule-table-row") it 'shows a list of the pipeline schedules with empty ref column' do
expect(first('.branch-name-cell').text).to eq('')
end
end end
end end
context 'when ref is nil' do describe 'POST /projects/pipeline_schedules/new' do
before do before do
pipeline_schedule.update_attribute(:ref, nil) visit_new_pipeline_schedule
visit_pipelines_schedules
end end
it 'shows a list of the pipeline schedules with empty ref column' do it 'sets defaults for timezone and target branch' do
expect(first('.branch-name-cell').text).to eq('') expect(page).to have_button('master')
expect(page).to have_button('UTC')
end end
end
end
describe 'POST /projects/pipeline_schedules/new' do it 'it creates a new scheduled pipeline' do
before do fill_in_schedule_form
visit_new_pipeline_schedule save_pipeline_schedule
end
it 'sets defaults for timezone and target branch' do expect(page).to have_content('my fancy description')
expect(page).to have_button('master') end
expect(page).to have_button('UTC')
end
it 'it creates a new scheduled pipeline' do it 'it prevents an invalid form from being submitted' do
fill_in_schedule_form save_pipeline_schedule
save_pipeline_schedule
expect(page).to have_content('my fancy description') expect(page).to have_content('This field is required')
end
end end
it 'it prevents an invalid form from being submitted' do describe 'PATCH /projects/pipelines_schedules/:id/edit' do
save_pipeline_schedule before do
edit_pipeline_schedule
end
expect(page).to have_content('This field is required') it 'it displays existing properties' do
end description = find_field('schedule_description').value
end expect(description).to eq('pipeline schedule')
expect(page).to have_button('master')
expect(page).to have_button('UTC')
end
describe 'PATCH /projects/pipelines_schedules/:id/edit' do it 'edits the scheduled pipeline' do
before do fill_in 'schedule_description', with: 'my brand new description'
edit_pipeline_schedule
end
it 'it displays existing properties' do save_pipeline_schedule
description = find_field('schedule_description').value
expect(description).to eq('pipeline schedule')
expect(page).to have_button('master')
expect(page).to have_button('UTC')
end
it 'edits the scheduled pipeline' do expect(page).to have_content('my brand new description')
fill_in 'schedule_description', with: 'my brand new description' end
save_pipeline_schedule context 'when ref is nil' do
before do
pipeline_schedule.update_attribute(:ref, nil)
edit_pipeline_schedule
end
expect(page).to have_content('my brand new description') it 'shows the pipeline schedule with default ref' do
page.within('.js-target-branch-dropdown') do
expect(first('.dropdown-toggle-text').text).to eq('master')
end
end
end
end end
context 'when ref is nil' do context 'when user creates a new pipeline schedule with variables' do
before do background do
pipeline_schedule.update_attribute(:ref, nil) visit_pipelines_schedules
edit_pipeline_schedule click_link 'New schedule'
fill_in_schedule_form
all('[name="schedule[variables_attributes][][key]"]')[0].set('AAA')
all('[name="schedule[variables_attributes][][value]"]')[0].set('AAA123')
all('[name="schedule[variables_attributes][][key]"]')[1].set('BBB')
all('[name="schedule[variables_attributes][][value]"]')[1].set('BBB123')
save_pipeline_schedule
end end
it 'shows the pipeline schedule with default ref' do scenario 'user sees the new variable in edit window' do
page.within('.js-target-branch-dropdown') do find(".content-list .pipeline-schedule-table-row:nth-child(1) .btn-group a[title='Edit']").click
expect(first('.dropdown-toggle-text').text).to eq('master') page.within('.pipeline-variable-list') do
expect(find(".pipeline-variable-row:nth-child(1) .pipeline-variable-key-input").value).to eq('AAA')
expect(find(".pipeline-variable-row:nth-child(1) .pipeline-variable-value-input").value).to eq('AAA123')
expect(find(".pipeline-variable-row:nth-child(2) .pipeline-variable-key-input").value).to eq('BBB')
expect(find(".pipeline-variable-row:nth-child(2) .pipeline-variable-value-input").value).to eq('BBB123')
end end
end end
end end
end
context 'when user creates a new pipeline schedule with variables' do context 'when user edits a variable of a pipeline schedule' do
background do background do
visit_pipelines_schedules create(:ci_pipeline_schedule, project: project, owner: user).tap do |pipeline_schedule|
click_link 'New schedule' create(:ci_pipeline_schedule_variable, key: 'AAA', value: 'AAA123', pipeline_schedule: pipeline_schedule)
fill_in_schedule_form end
all('[name="schedule[variables_attributes][][key]"]')[0].set('AAA')
all('[name="schedule[variables_attributes][][value]"]')[0].set('AAA123')
all('[name="schedule[variables_attributes][][key]"]')[1].set('BBB')
all('[name="schedule[variables_attributes][][value]"]')[1].set('BBB123')
save_pipeline_schedule
end
scenario 'user sees the new variable in edit window' do visit_pipelines_schedules
find(".content-list .pipeline-schedule-table-row:nth-child(1) .btn-group a[title='Edit']").click find(".content-list .pipeline-schedule-table-row:nth-child(1) .btn-group a[title='Edit']").click
page.within('.pipeline-variable-list') do all('[name="schedule[variables_attributes][][key]"]')[0].set('foo')
expect(find(".pipeline-variable-row:nth-child(1) .pipeline-variable-key-input").value).to eq('AAA') all('[name="schedule[variables_attributes][][value]"]')[0].set('bar')
expect(find(".pipeline-variable-row:nth-child(1) .pipeline-variable-value-input").value).to eq('AAA123') click_button 'Save pipeline schedule'
expect(find(".pipeline-variable-row:nth-child(2) .pipeline-variable-key-input").value).to eq('BBB')
expect(find(".pipeline-variable-row:nth-child(2) .pipeline-variable-value-input").value).to eq('BBB123')
end end
end
end
context 'when user edits a variable of a pipeline schedule' do scenario 'user sees the updated variable in edit window' do
background do find(".content-list .pipeline-schedule-table-row:nth-child(1) .btn-group a[title='Edit']").click
create(:ci_pipeline_schedule, project: project, owner: user).tap do |pipeline_schedule| page.within('.pipeline-variable-list') do
create(:ci_pipeline_schedule_variable, key: 'AAA', value: 'AAA123', pipeline_schedule: pipeline_schedule) expect(find(".pipeline-variable-row:nth-child(1) .pipeline-variable-key-input").value).to eq('foo')
expect(find(".pipeline-variable-row:nth-child(1) .pipeline-variable-value-input").value).to eq('bar')
end
end end
visit_pipelines_schedules
find(".content-list .pipeline-schedule-table-row:nth-child(1) .btn-group a[title='Edit']").click
all('[name="schedule[variables_attributes][][key]"]')[0].set('foo')
all('[name="schedule[variables_attributes][][value]"]')[0].set('bar')
click_button 'Save pipeline schedule'
end end
scenario 'user sees the updated variable in edit window' do context 'when user removes a variable of a pipeline schedule' do
find(".content-list .pipeline-schedule-table-row:nth-child(1) .btn-group a[title='Edit']").click background do
page.within('.pipeline-variable-list') do create(:ci_pipeline_schedule, project: project, owner: user).tap do |pipeline_schedule|
expect(find(".pipeline-variable-row:nth-child(1) .pipeline-variable-key-input").value).to eq('foo') create(:ci_pipeline_schedule_variable, key: 'AAA', value: 'AAA123', pipeline_schedule: pipeline_schedule)
expect(find(".pipeline-variable-row:nth-child(1) .pipeline-variable-value-input").value).to eq('bar') end
visit_pipelines_schedules
find(".content-list .pipeline-schedule-table-row:nth-child(1) .btn-group a[title='Edit']").click
find('.pipeline-variable-list .pipeline-variable-row-remove-button').click
click_button 'Save pipeline schedule'
end
scenario 'user does not see the removed variable in edit window' do
find(".content-list .pipeline-schedule-table-row:nth-child(1) .btn-group a[title='Edit']").click
page.within('.pipeline-variable-list') do
expect(find(".pipeline-variable-row:nth-child(1) .pipeline-variable-key-input").value).to eq('')
expect(find(".pipeline-variable-row:nth-child(1) .pipeline-variable-value-input").value).to eq('')
end
end end
end end
end end
context 'when user removes a variable of a pipeline schedule' do context 'logged in as non-member' do
background do before do
create(:ci_pipeline_schedule, project: project, owner: user).tap do |pipeline_schedule| gitlab_sign_in(user)
create(:ci_pipeline_schedule_variable, key: 'AAA', value: 'AAA123', pipeline_schedule: pipeline_schedule) end
describe 'GET /projects/pipeline_schedules' do
before do
visit_pipelines_schedules
end end
visit_pipelines_schedules describe 'The view' do
find(".content-list .pipeline-schedule-table-row:nth-child(1) .btn-group a[title='Edit']").click it 'does not show create schedule button' do
find('.pipeline-variable-list .pipeline-variable-row-remove-button').click expect(page).not_to have_link('New schedule')
click_button 'Save pipeline schedule' end
end
end end
end
context 'not logged in' do
describe 'GET /projects/pipeline_schedules' do
before do
visit_pipelines_schedules
end
scenario 'user does not see the removed variable in edit window' do describe 'The view' do
find(".content-list .pipeline-schedule-table-row:nth-child(1) .btn-group a[title='Edit']").click it 'does not show create schedule button' do
page.within('.pipeline-variable-list') do expect(page).not_to have_link('New schedule')
expect(find(".pipeline-variable-row:nth-child(1) .pipeline-variable-key-input").value).to eq('') end
expect(find(".pipeline-variable-row:nth-child(1) .pipeline-variable-value-input").value).to eq('')
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment