Commit 34ae179b authored by Tristan Read's avatar Tristan Read Committed by Peter Leitzen

Hide Create Incident button on incident list page

parent 38365cfa
......@@ -125,6 +125,7 @@ export default {
'authorUsernameQuery',
'assigneeUsernameQuery',
'slaFeatureAvailable',
'canCreateIncident',
],
apollo: {
incidents: {
......@@ -244,6 +245,9 @@ export default {
btnText: createIncidentBtnLabel,
};
},
isHeaderButtonVisible() {
return this.canCreateIncident && (!this.isEmpty || this.activeClosedTabHasNoIncidents);
},
},
methods: {
hasAssignees(assignees) {
......@@ -311,7 +315,7 @@ export default {
>
<template #header-actions>
<gl-button
v-if="!isEmpty || activeClosedTabHasNoIncidents"
v-if="isHeaderButtonVisible"
class="gl-my-3 gl-mr-5 create-incident-button"
data-testid="createIncidentBtn"
data-qa-selector="create_incident_button"
......
......@@ -21,6 +21,7 @@ export default () => {
authorUsernameQuery,
assigneeUsernameQuery,
slaFeatureAvailable,
canCreateIncident,
} = domEl.dataset;
const apolloProvider = new VueApollo({
......@@ -44,6 +45,7 @@ export default () => {
authorUsernameQuery,
assigneeUsernameQuery,
slaFeatureAvailable: parseBoolean(slaFeatureAvailable),
canCreateIncident: parseBoolean(canCreateIncident),
},
apolloProvider,
render(createElement) {
......
......@@ -11,7 +11,8 @@ module Projects::IncidentsHelper
'empty-list-svg-path' => image_path('illustrations/incident-empty-state.svg'),
'text-query': params[:search],
'author-username-query': params[:author_username],
'assignee-username-query': params[:assignee_username]
'assignee-username-query': params[:assignee_username],
'can-create-incident': create_issue_type_allowed?(project, :incident).to_s
}
end
end
......
......@@ -5,8 +5,8 @@ require 'spec_helper'
RSpec.describe Projects::IncidentsHelper do
include Gitlab::Routing.url_helpers
let_it_be_with_refind(:project) { create(:project) }
let(:project) { build_stubbed(:project) }
let(:user) { build_stubbed(:user) }
let(:project_path) { project.full_path }
let(:new_issue_path) { new_project_issue_path(project) }
let(:issue_path) { project_issues_path(project) }
......@@ -18,6 +18,13 @@ RSpec.describe Projects::IncidentsHelper do
}
end
before do
allow(helper).to receive(:current_user).and_return(user)
allow(helper).to receive(:can?)
.with(user, :create_incident, project)
.and_return(true)
end
describe '#incidents_data' do
let(:expected_incidents_data) do
{
......@@ -31,7 +38,8 @@ RSpec.describe Projects::IncidentsHelper do
'sla-feature-available' => 'false',
'text-query': 'search text',
'author-username-query': 'root',
'assignee-username-query': 'max.power'
'assignee-username-query': 'max.power',
'can-create-incident': 'true'
}
end
......
......@@ -4,52 +4,49 @@ require 'spec_helper'
RSpec.describe 'Incident Management index', :js do
let_it_be(:project) { create(:project) }
let_it_be(:developer) { create(:user) }
let_it_be(:reporter) { create(:user) }
let_it_be(:guest) { create(:user) }
let_it_be(:incident) { create(:incident, project: project) }
before_all do
project.add_developer(developer)
project.add_reporter(reporter)
project.add_guest(guest)
end
shared_examples 'create incident form' do
it 'shows the create new issue button' do
expect(page).to have_selector('.create-incident-button')
end
before do
sign_in(user)
it 'when clicked shows the create issue page with the Incident type pre-selected' do
find('.create-incident-button').click
wait_for_all_requests
visit project_incidents_path(project)
wait_for_all_requests
end
expect(page).to have_selector('.dropdown-menu-toggle')
expect(page).to have_selector('.js-issuable-type-filter-dropdown-wrap')
describe 'incident list is visited' do
context 'by reporter' do
let(:user) { reporter }
page.within('.js-issuable-type-filter-dropdown-wrap') do
expect(page).to have_content('Incident')
it 'shows the create new incident button' do
expect(page).to have_selector('.create-incident-button')
end
end
end
context 'when a developer displays the incident list' do
before do
sign_in(developer)
it 'when clicked shows the create issue page with the Incident type pre-selected' do
find('.create-incident-button').click
wait_for_all_requests
visit project_incidents_path(project)
wait_for_all_requests
end
expect(page).to have_selector('.dropdown-menu-toggle')
expect(page).to have_selector('.js-issuable-type-filter-dropdown-wrap')
it_behaves_like 'create incident form'
page.within('.js-issuable-type-filter-dropdown-wrap') do
expect(page).to have_content('Incident')
end
end
end
end
context 'when a guest displays the incident list' do
before do
sign_in(guest)
context 'by guest' do
let(:user) { guest }
visit project_incidents_path(project)
wait_for_all_requests
it 'does not show new incident button' do
expect(page).not_to have_selector('.create-incident-button')
end
it_behaves_like 'create incident form'
end
end
......@@ -5,7 +5,8 @@ require 'spec_helper'
RSpec.describe Projects::IncidentsHelper do
include Gitlab::Routing.url_helpers
let(:project) { create(:project) }
let(:user) { build_stubbed(:user) }
let(:project) { build_stubbed(:project) }
let(:project_path) { project.full_path }
let(:new_issue_path) { new_project_issue_path(project) }
let(:issue_path) { project_issues_path(project) }
......@@ -17,21 +18,43 @@ RSpec.describe Projects::IncidentsHelper do
}
end
before do
allow(helper).to receive(:current_user).and_return(user)
allow(helper).to receive(:can?)
.with(user, :create_incident, project)
.and_return(can_create_incident)
end
describe '#incidents_data' do
subject(:data) { helper.incidents_data(project, params) }
it 'returns frontend configuration' do
expect(data).to include(
'project-path' => project_path,
'new-issue-path' => new_issue_path,
'incident-template-name' => 'incident',
'incident-type' => 'incident',
'issue-path' => issue_path,
'empty-list-svg-path' => match_asset_path('/assets/illustrations/incident-empty-state.svg'),
'text-query': 'search text',
'author-username-query': 'root',
'assignee-username-query': 'max.power'
)
shared_examples 'frontend configuration' do
it 'returns frontend configuration' do
expect(data).to include(
'project-path' => project_path,
'new-issue-path' => new_issue_path,
'incident-template-name' => 'incident',
'incident-type' => 'incident',
'issue-path' => issue_path,
'empty-list-svg-path' => match_asset_path('/assets/illustrations/incident-empty-state.svg'),
'text-query': 'search text',
'author-username-query': 'root',
'assignee-username-query': 'max.power',
'can-create-incident': can_create_incident.to_s
)
end
end
context 'when user can create incidents' do
let(:can_create_incident) { true }
include_examples 'frontend configuration'
end
context 'when user cannot create incidents' do
let(:can_create_incident) { false }
include_examples 'frontend configuration'
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