Elevate permission to create incident from guest to reporter

* Adjust issue build service spec when creating incidents as reporter
* Adjust issue create service spec when creating incidents as reporter
* Update create issue feature spec to match permission change
This commit is contained in:
Peter Leitzen 2021-09-01 16:06:49 +02:00
parent b773abc01a
commit 2809dd20d3
No known key found for this signature in database
GPG key ID: 97DE9D2E708A225E
6 changed files with 105 additions and 38 deletions

View file

@ -248,7 +248,7 @@ class ProjectPolicy < BasePolicy
enable :read_insights
end
rule { can?(:guest_access) & can?(:create_issue) }.enable :create_incident
rule { can?(:reporter_access) & can?(:create_issue) }.enable :create_incident
# These abilities are not allowed to admins that are not members of the project,
# that's why they are defined separately.

View file

@ -248,15 +248,21 @@
end
end
shared_examples 'type option is missing' do |label:, identifier:|
it "does not show #{identifier} option", :aggregate_failures do
page.within('[data-testid="issue-type-select-dropdown"]') do
expect(page).not_to have_selector(%([data-testid="issue-type-#{identifier}-icon"]))
expect(page).not_to have_content(label)
end
end
end
before do
page.within('.issue-form') do
click_button 'Issue'
end
end
it_behaves_like 'type option is visible', label: 'Issue', identifier: :issue
it_behaves_like 'type option is visible', label: 'Incident', identifier: :incident
context 'when user is guest' do
let_it_be(:guest) { create(:user) }
@ -266,6 +272,19 @@
project.add_guest(guest)
end
it_behaves_like 'type option is visible', label: 'Issue', identifier: :issue
it_behaves_like 'type option is missing', label: 'Incident', identifier: :incident
end
context 'when user is reporter' do
let_it_be(:reporter) { create(:user) }
let(:current_user) { reporter }
before_all do
project.add_reporter(reporter)
end
it_behaves_like 'type option is visible', label: 'Issue', identifier: :issue
it_behaves_like 'type option is visible', label: 'Incident', identifier: :incident
end

View file

@ -171,7 +171,7 @@
end
context 'form create handles issue creation by default' do
let(:project) { create(:project) }
let_it_be(:project) { create(:project) }
before do
visit new_project_issue_path(project)
@ -187,30 +187,22 @@
end
context 'form create handles incident creation' do
let(:project) { create(:project) }
let_it_be(:project) { create(:project) }
before do
visit new_project_issue_path(project, { issuable_template: 'incident', issue: { issue_type: 'incident' } })
end
it 'pre-fills the issue type dropdown with incident type' do
expect(find('.js-issuable-type-filter-dropdown-wrap .dropdown-toggle-text')).to have_content('Incident')
end
it 'hides the epic select' do
expect(page).not_to have_selector('.epic-dropdown-container')
it 'does not pre-fill the issue type dropdown with incident type' do
expect(find('.js-issuable-type-filter-dropdown-wrap .dropdown-toggle-text')).not_to have_content('Incident')
end
it 'shows the milestone select' do
expect(page).to have_selector('.qa-issuable-milestone-dropdown') # rubocop:disable QA/SelectorUsage
end
it 'hides the weight input' do
expect(page).not_to have_selector('.qa-issuable-weight-input') # rubocop:disable QA/SelectorUsage
end
it 'shows the incident help text' do
expect(page).to have_text('A modified issue to guide the resolution of incidents.')
it 'hides the incident help text' do
expect(page).not_to have_text('A modified issue to guide the resolution of incidents.')
end
end
@ -242,6 +234,44 @@
end
end
context 'when signed in as reporter', :js do
let_it_be(:project) { create(:project) }
before_all do
project.add_reporter(user)
end
before do
sign_in(user)
end
context 'form create handles incident creation' do
before do
visit new_project_issue_path(project, { issuable_template: 'incident', issue: { issue_type: 'incident' } })
end
it 'pre-fills the issue type dropdown with incident type' do
expect(find('.js-issuable-type-filter-dropdown-wrap .dropdown-toggle-text')).to have_content('Incident')
end
it 'hides the epic select' do
expect(page).not_to have_selector('.epic-dropdown-container')
end
it 'shows the milestone select' do
expect(page).to have_selector('.qa-issuable-milestone-dropdown') # rubocop:disable QA/SelectorUsage
end
it 'hides the weight input' do
expect(page).not_to have_selector('.qa-issuable-weight-input') # rubocop:disable QA/SelectorUsage
end
it 'shows the incident help text' do
expect(page).to have_text('A modified issue to guide the resolution of incidents.')
end
end
end
context "when signed in as user with special characters in their name" do
let(:user_special) { create(:user, name: "Jon O'Shea") }

View file

@ -7,12 +7,14 @@
let_it_be(:project) { create(:project, :repository) }
let_it_be(:developer) { create(:user) }
let_it_be(:reporter) { create(:user) }
let_it_be(:guest) { create(:user) }
let(:user) { developer }
before_all do
project.add_developer(developer)
project.add_reporter(reporter)
project.add_guest(guest)
end
@ -177,7 +179,8 @@ def build_issue(issue_params = {})
where(:issue_type, :current_user, :work_item_type_id, :resulting_issue_type) do
nil | ref(:guest) | ref(:type_issue_id) | 'issue'
'issue' | ref(:guest) | ref(:type_issue_id) | 'issue'
'incident' | ref(:guest) | ref(:type_incident_id) | 'incident'
'incident' | ref(:guest) | ref(:type_issue_id) | 'issue'
'incident' | ref(:reporter) | ref(:type_incident_id) | 'incident'
# update once support for test_case is enabled
'test_case' | ref(:guest) | ref(:type_issue_id) | 'issue'
# update once support for requirement is enabled

View file

@ -80,7 +80,7 @@
it_behaves_like 'not an incident issue'
context 'issue is incident type' do
context 'when issue is incident type' do
before do
opts.merge!(issue_type: 'incident')
end
@ -90,22 +90,36 @@
subject { issue }
it_behaves_like 'incident issue'
it_behaves_like 'has incident label'
context 'as reporter' do
let_it_be(:reporter) { create(:user) }
it 'does create an incident label' do
expect { subject }
.to change { Label.where(incident_label_attributes).count }.by(1)
let(:user) { reporter }
before_all do
project.add_reporter(reporter)
end
it_behaves_like 'incident issue'
it_behaves_like 'has incident label'
it 'does create an incident label' do
expect { subject }
.to change { Label.where(incident_label_attributes).count }.by(1)
end
context 'when invalid' do
before do
opts.merge!(title: '')
end
it 'does not apply an incident label prematurely' do
expect { subject }.to not_change(LabelLink, :count).and not_change(Issue, :count)
end
end
end
context 'when invalid' do
before do
opts.merge!(title: '')
end
it 'does not apply an incident label prematurely' do
expect { subject }.to not_change(LabelLink, :count).and not_change(Issue, :count)
end
context 'as guest' do
it_behaves_like 'not an incident issue'
end
end

View file

@ -15,7 +15,7 @@
let(:base_guest_permissions) do
%i[
award_emoji create_issue create_incident create_merge_request_in create_note
award_emoji create_issue create_merge_request_in create_note
create_project read_issue_board read_issue read_issue_iid read_issue_link
read_label read_issue_board_list read_milestone read_note read_project
read_project_for_iids read_project_member read_release read_snippet
@ -25,10 +25,11 @@
let(:base_reporter_permissions) do
%i[
admin_issue admin_issue_link admin_label admin_issue_board_list create_snippet
daily_statistics download_code download_wiki_code fork_project metrics_dashboard
read_build read_commit_status read_confidential_issues
read_container_image read_deployment read_environment read_merge_request
admin_issue admin_issue_link admin_label admin_issue_board_list
create_snippet create_incident daily_statistics download_code
download_wiki_code fork_project metrics_dashboard read_build
read_commit_status read_confidential_issues read_container_image
read_deployment read_environment read_merge_request
read_metrics_dashboard_annotation read_pipeline read_prometheus
read_sentry_issue update_issue
]