Commit d049e9e9 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch '267939-create-incident-guest' into 'master'

Support incident creation as guest

See merge request gitlab-org/gitlab!45244
parents cc958f49 ac9fc0ca
...@@ -64,20 +64,26 @@ module Issues ...@@ -64,20 +64,26 @@ module Issues
private private
def whitelisted_issue_params def allowed_issue_base_params
base_params = [:title, :description, :confidential] [:title, :description, :confidential, :issue_type]
admin_params = [:milestone_id, :issue_type] end
def allowed_issue_admin_params
[:milestone_id]
end
def allowed_issue_params
if can?(current_user, :admin_issue, project) if can?(current_user, :admin_issue, project)
params.slice(*(base_params + admin_params)) params.slice(*(allowed_issue_base_params + allowed_issue_admin_params))
else else
params.slice(*base_params) params.slice(*allowed_issue_base_params)
end end
end end
def build_issue_params def build_issue_params
{ author: current_user }.merge(issue_params_with_info_from_discussions) { author: current_user }
.merge(whitelisted_issue_params) .merge(issue_params_with_info_from_discussions)
.merge(allowed_issue_params)
end end
end end
end end
......
- return unless issuable.supports_issue_type? && can?(current_user, :admin_issue, @project) - return unless issuable.supports_issue_type? && can?(current_user, :create_issue, @project)
.form-group.row.gl-mb-0 .form-group.row.gl-mb-0
= form.label :type, 'Type', class: 'col-form-label col-sm-2' = form.label :type, 'Type', class: 'col-form-label col-sm-2'
......
...@@ -19,6 +19,20 @@ module EE ...@@ -19,6 +19,20 @@ module EE
def build_issue_params def build_issue_params
issue_params_from_template.merge(super) issue_params_from_template.merge(super)
end end
override :allowed_issue_base_params
def allowed_issue_base_params
return super - [:issue_type] if params[:issue_type] == 'test_case'
super
end
override :allowed_issue_admin_params
def allowed_issue_admin_params
return super + [:issue_type] if params[:issue_type] == 'test_case'
super
end
end end
end end
end end
...@@ -3,20 +3,26 @@ ...@@ -3,20 +3,26 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Issues::BuildService do RSpec.describe Issues::BuildService do
let(:project) { create(:project, :repository) } let_it_be(:project) { create(:project, :repository) }
let(:user) { create(:user) } let_it_be(:developer) { create(:user) }
let_it_be(:guest) { create(:user) }
let(:user) { developer }
before do before do
project.add_developer(user) project.add_developer(developer)
project.add_guest(guest)
end
def build_issue(issue_params = {})
described_class.new(project, user, issue_params).execute
end end
context 'with an issue template' do context 'with an issue template' do
describe '#execute' do describe '#execute' do
it 'fills in the template in the description' do let(:project) { build(:project, issues_template: 'Work hard, play hard!') }
project = build(:project, issues_template: 'Work hard, play hard!')
service = described_class.new(project, user)
issue = service.execute it 'fills in the template in the description' do
issue = build_issue
expect(issue.description).to eq('Work hard, play hard!') expect(issue.description).to eq('Work hard, play hard!')
end end
...@@ -27,17 +33,41 @@ RSpec.describe Issues::BuildService do ...@@ -27,17 +33,41 @@ RSpec.describe Issues::BuildService do
describe '#execute' do describe '#execute' do
let(:merge_request) { create(:merge_request, title: "Hello world", source_project: project) } let(:merge_request) { create(:merge_request, title: "Hello world", source_project: project) }
let(:discussion) { create(:diff_note_on_merge_request, project: project, noteable: merge_request, note: "Almost done").to_discussion } let(:discussion) { create(:diff_note_on_merge_request, project: project, noteable: merge_request, note: "Almost done").to_discussion }
let(:service) { described_class.new(project, user, merge_request_to_resolve_discussions_of: merge_request.iid, discussion_to_resolve: discussion.id) }
context 'with an issue template' do context 'with an issue template' do
let(:project) { create(:project, :repository, issues_template: 'Work hard, play hard!') } let(:project) { create(:project, :repository, issues_template: 'Work hard, play hard!') }
it 'picks the thread description over the issue template' do it 'picks the thread description over the issue template' do
issue = service.execute issue = build_issue(
merge_request_to_resolve_discussions_of: merge_request.iid,
discussion_to_resolve: discussion.id
)
expect(issue.description).to include('Almost done') expect(issue.description).to include('Almost done')
end end
end end
end end
end end
describe '#execute' do
context 'as developer' do
it 'sets test_case' do
issue = build_issue(issue_type: 'test_case')
expect(issue).to be_test_case
end
end
context 'as guest' do
let(:user) { guest }
context 'setting issue type' do
it 'cannot set test_case' do
issue = build_issue(issue_type: 'test_case')
expect(issue).to be_issue
end
end
end
end
end end
...@@ -5,34 +5,51 @@ require 'spec_helper' ...@@ -5,34 +5,51 @@ require 'spec_helper'
RSpec.describe 'Incident Management index', :js do RSpec.describe 'Incident Management index', :js do
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
let_it_be(:developer) { create(:user) } let_it_be(:developer) { create(:user) }
let_it_be(:guest) { create(:user) }
let_it_be(:incident) { create(:incident, project: project) } let_it_be(:incident) { create(:incident, project: project) }
before_all do before_all do
project.add_developer(developer) project.add_developer(developer)
project.add_guest(guest)
end end
before do shared_examples 'create incident form' do
sign_in(developer)
visit project_incidents_path(project)
wait_for_requests
end
context 'when a developer displays the incident list' do
it 'shows the create new issue button' do it 'shows the create new issue button' do
expect(page).to have_selector('.create-incident-button') expect(page).to have_selector('.create-incident-button')
end end
it 'shows the create issue page with the Incident type pre-selected when clicked' do it 'when clicked shows the create issue page with the Incident type pre-selected' do
find('.create-incident-button').click find('.create-incident-button').click
wait_for_requests wait_for_all_requests
expect(page).to have_selector(".dropdown-menu-toggle") expect(page).to have_selector('.dropdown-menu-toggle')
expect(page).to have_selector(".js-issuable-type-filter-dropdown-wrap") expect(page).to have_selector('.js-issuable-type-filter-dropdown-wrap')
page.within('.js-issuable-type-filter-dropdown-wrap') do page.within('.js-issuable-type-filter-dropdown-wrap') do
expect(page).to have_content('Incident') expect(page).to have_content('Incident')
end end
end end
end end
context 'when a developer displays the incident list' do
before do
sign_in(developer)
visit project_incidents_path(project)
wait_for_all_requests
end
it_behaves_like 'create incident form'
end
context 'when a guest displays the incident list' do
before do
sign_in(guest)
visit project_incidents_path(project)
wait_for_all_requests
end
it_behaves_like 'create incident form'
end
end end
...@@ -3,11 +3,14 @@ ...@@ -3,11 +3,14 @@
require 'spec_helper.rb' require 'spec_helper.rb'
RSpec.describe Issues::BuildService do RSpec.describe Issues::BuildService do
let(:project) { create(:project, :repository) } let_it_be(:project) { create(:project, :repository) }
let(:user) { create(:user) } let_it_be(:developer) { create(:user) }
let_it_be(:guest) { create(:user) }
before do let(:user) { developer }
project.add_developer(user)
before_all do
project.add_developer(developer)
project.add_guest(guest)
end end
def build_issue(issue_params = {}) def build_issue(issue_params = {})
...@@ -134,31 +137,56 @@ RSpec.describe Issues::BuildService do ...@@ -134,31 +137,56 @@ RSpec.describe Issues::BuildService do
end end
describe '#execute' do describe '#execute' do
it 'builds a new issues with given params' do context 'as developer' do
milestone = create(:milestone, project: project) it 'builds a new issues with given params' do
issue = build_issue(milestone_id: milestone.id) milestone = create(:milestone, project: project)
issue = build_issue(milestone_id: milestone.id)
expect(issue.milestone).to eq(milestone) expect(issue.milestone).to eq(milestone)
end end
it 'sets milestone to nil if it is not available for the project' do it 'sets milestone to nil if it is not available for the project' do
milestone = create(:milestone, project: create(:project)) milestone = create(:milestone, project: create(:project))
issue = build_issue(milestone_id: milestone.id) issue = build_issue(milestone_id: milestone.id)
expect(issue.milestone).to be_nil expect(issue.milestone).to be_nil
end
end end
context 'setting issue type' do context 'as guest' do
it 'sets the issue_type on the issue' do let(:user) { guest }
issue = build_issue(issue_type: 'incident')
expect(issue.issue_type).to eq('incident') it 'cannot set milestone' do
milestone = create(:milestone, project: project)
issue = build_issue(milestone_id: milestone.id)
expect(issue.milestone).to be_nil
end end
it 'defaults to issue if issue_type not given' do context 'setting issue type' do
issue = build_issue it 'defaults to issue if issue_type not given' do
issue = build_issue
expect(issue).to be_issue
end
it 'sets issue' do
issue = build_issue(issue_type: 'issue')
expect(issue).to be_issue
end
it 'sets incident' do
issue = build_issue(issue_type: 'incident')
expect(issue.issue_type).to eq('issue') expect(issue).to be_incident
end
it 'cannot set invalid type' do
expect do
build_issue(issue_type: 'invalid type')
end.to raise_error(ArgumentError, "'invalid type' is not a valid issue_type")
end
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