Commit 38365cfa authored by Tristan Read's avatar Tristan Read Committed by Peter Leitzen

Hide incident option in issue edit form

* Update issue detail spec to match new permission restriction
parent 2809dd20
......@@ -2,7 +2,7 @@
import { GlFormGroup, GlDropdown, GlDropdownItem, GlIcon } from '@gitlab/ui';
import { capitalize } from 'lodash';
import { __ } from '~/locale';
import { IssuableTypes } from '../../constants';
import { IssuableTypes, IncidentType } from '../../constants';
import getIssueStateQuery from '../../queries/get_issue_state.query.graphql';
import updateIssueStateMutation from '../../queries/update_issue_state.mutation.graphql';
......@@ -19,6 +19,14 @@ export default {
GlDropdown,
GlDropdownItem,
},
inject: {
canCreateIncident: {
default: false,
},
issueType: {
default: 'issue',
},
},
data() {
return {
issueState: {},
......@@ -36,6 +44,9 @@ export default {
} = this;
return capitalize(issueType);
},
shouldShowIncident() {
return this.issueType === IncidentType || this.canCreateIncident;
},
},
methods: {
updateIssueType(issueType) {
......@@ -47,6 +58,9 @@ export default {
},
});
},
isShown(type) {
return type.value !== IncidentType || this.shouldShowIncident;
},
},
};
</script>
......@@ -68,6 +82,7 @@ export default {
>
<gl-dropdown-item
v-for="type in $options.IssuableTypes"
v-show="isShown(type)"
:key="type.value"
:is-checked="issueState.issueType === type.value"
is-check-item
......
......@@ -2,7 +2,7 @@ import Vue from 'vue';
import { parseBoolean } from '~/lib/utils/common_utils';
import issuableApp from './components/app.vue';
import incidentTabs from './components/incidents/incident_tabs.vue';
import { issueState } from './constants';
import { issueState, IncidentType } from './constants';
import apolloProvider from './graphql';
import getIssueStateQuery from './queries/get_issue_state.query.graphql';
......@@ -21,6 +21,7 @@ export default function initIssuableApp(issuableData = {}) {
});
const {
canCreateIncident,
canUpdate,
iid,
projectNamespace,
......@@ -39,6 +40,8 @@ export default function initIssuableApp(issuableData = {}) {
issuableApp,
},
provide: {
issueType: IncidentType,
canCreateIncident,
canUpdate,
fullPath,
iid,
......
......@@ -25,17 +25,22 @@ export function initIssuableApp(issuableData, store) {
bootstrapApollo({ ...issueState, issueType: el.dataset.issueType });
const { canCreateIncident, ...issuableProps } = issuableData;
return new Vue({
el,
apolloProvider,
store,
provide: {
canCreateIncident,
},
computed: {
...mapGetters(['getNoteableData']),
},
render(createElement) {
return createElement(IssuableApp, {
props: {
...issuableData,
...issuableProps,
isConfidential: this.getNoteableData?.confidential,
isLocked: this.getNoteableData?.discussion_locked,
issuableStatus: this.getNoteableData?.state,
......
......@@ -257,7 +257,8 @@ module IssuablesHelper
zoomMeetingUrl: ZoomMeeting.canonical_meeting_url(issuable),
sentryIssueIdentifier: SentryIssue.find_by(issue: issuable)&.sentry_issue_identifier, # rubocop:disable CodeReuse/ActiveRecord
iid: issuable.iid.to_s,
isHidden: issue_hidden?(issuable)
isHidden: issue_hidden?(issuable),
canCreateIncident: create_issue_type_allowed?(issuable.project, :incident)
}
end
......
......@@ -3,8 +3,9 @@
require 'spec_helper'
RSpec.describe 'Issue Detail', :js do
let_it_be_with_refind(:project) { create(:project, :public) }
let(:user) { create(:user) }
let(:project) { create(:project, :public) }
let(:issue) { create(:issue, project: project, author: user) }
let(:incident) { create(:incident, project: project, author: user) }
......@@ -90,7 +91,13 @@ RSpec.describe 'Issue Detail', :js do
end
describe 'user updates `issue_type` via the issue type dropdown' do
context 'when an issue `issue_type` is edited by a signed in user' do
let_it_be(:reporter) { create(:user) }
before_all do
project.add_reporter(reporter)
end
describe 'when an issue `issue_type` is edited' do
before do
sign_in(user)
......@@ -98,18 +105,33 @@ RSpec.describe 'Issue Detail', :js do
wait_for_requests
end
it 'routes the user to the incident details page when the `issue_type` is set to incident' do
open_issue_edit_form
context 'by non-member author' do
it 'cannot see Incident option' do
open_issue_edit_form
page.within('[data-testid="issuable-form"]') do
expect(page).to have_content('Issue')
expect(page).not_to have_content('Incident')
end
end
end
context 'by reporter' do
let(:user) { reporter }
page.within('[data-testid="issuable-form"]') do
update_type_select('Issue', 'Incident')
it 'routes the user to the incident details page when the `issue_type` is set to incident' do
open_issue_edit_form
expect(page).to have_current_path(project_issues_incident_path(project, issue))
page.within('[data-testid="issuable-form"]') do
update_type_select('Issue', 'Incident')
expect(page).to have_current_path(project_issues_incident_path(project, issue))
end
end
end
end
context 'when an incident `issue_type` is edited by a signed in user' do
describe 'when an incident `issue_type` is edited' do
before do
sign_in(user)
......@@ -117,13 +139,29 @@ RSpec.describe 'Issue Detail', :js do
wait_for_requests
end
it 'routes the user to the issue details page when the `issue_type` is set to issue' do
open_issue_edit_form
context 'by non-member author' do
it 'routes the user to the issue details page when the `issue_type` is set to issue' do
open_issue_edit_form
page.within('[data-testid="issuable-form"]') do
update_type_select('Incident', 'Issue')
expect(page).to have_current_path(project_issue_path(project, incident))
end
end
end
context 'by reporter' do
let(:user) { reporter }
it 'routes the user to the issue details page when the `issue_type` is set to issue' do
open_issue_edit_form
page.within('[data-testid="issuable-form"]') do
update_type_select('Incident', 'Issue')
page.within('[data-testid="issuable-form"]') do
update_type_select('Incident', 'Issue')
expect(page).to have_current_path(project_issue_path(project, incident))
expect(page).to have_current_path(project_issue_path(project, incident))
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