Commit ac9fc0ca authored by David O'Regan's avatar David O'Regan Committed by Heinrich Lee Yu

Support incident creation as guest

parent 9f22b536
......@@ -64,20 +64,26 @@ module Issues
private
def whitelisted_issue_params
base_params = [:title, :description, :confidential]
admin_params = [:milestone_id, :issue_type]
def allowed_issue_base_params
[:title, :description, :confidential, :issue_type]
end
def allowed_issue_admin_params
[:milestone_id]
end
def allowed_issue_params
if can?(current_user, :admin_issue, project)
params.slice(*(base_params + admin_params))
params.slice(*(allowed_issue_base_params + allowed_issue_admin_params))
else
params.slice(*base_params)
params.slice(*allowed_issue_base_params)
end
end
def build_issue_params
{ author: current_user }.merge(issue_params_with_info_from_discussions)
.merge(whitelisted_issue_params)
{ author: current_user }
.merge(issue_params_with_info_from_discussions)
.merge(allowed_issue_params)
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.label :type, 'Type', class: 'col-form-label col-sm-2'
......
......@@ -19,6 +19,20 @@ module EE
def build_issue_params
issue_params_from_template.merge(super)
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
......@@ -3,20 +3,26 @@
require 'spec_helper'
RSpec.describe Issues::BuildService do
let(:project) { create(:project, :repository) }
let(:user) { create(:user) }
let_it_be(:project) { create(:project, :repository) }
let_it_be(:developer) { create(:user) }
let_it_be(:guest) { create(:user) }
let(:user) { developer }
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
context 'with an issue template' do
describe '#execute' do
it 'fills in the template in the description' do
project = build(:project, issues_template: 'Work hard, play hard!')
service = described_class.new(project, user)
let(:project) { build(:project, issues_template: 'Work hard, play hard!') }
issue = service.execute
it 'fills in the template in the description' do
issue = build_issue
expect(issue.description).to eq('Work hard, play hard!')
end
......@@ -27,17 +33,41 @@ RSpec.describe Issues::BuildService do
describe '#execute' do
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(: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
let(:project) { create(:project, :repository, issues_template: 'Work hard, play hard!') }
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')
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
......@@ -5,34 +5,51 @@ 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(:guest) { create(:user) }
let_it_be(:incident) { create(:incident, project: project) }
before_all do
project.add_developer(developer)
project.add_guest(guest)
end
before do
sign_in(developer)
visit project_incidents_path(project)
wait_for_requests
end
context 'when a developer displays the incident list' do
shared_examples 'create incident form' do
it 'shows the create new issue button' do
expect(page).to have_selector('.create-incident-button')
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
wait_for_requests
wait_for_all_requests
expect(page).to have_selector(".dropdown-menu-toggle")
expect(page).to have_selector(".js-issuable-type-filter-dropdown-wrap")
expect(page).to have_selector('.dropdown-menu-toggle')
expect(page).to have_selector('.js-issuable-type-filter-dropdown-wrap')
page.within('.js-issuable-type-filter-dropdown-wrap') do
expect(page).to have_content('Incident')
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
......@@ -3,11 +3,14 @@
require 'spec_helper.rb'
RSpec.describe Issues::BuildService do
let(:project) { create(:project, :repository) }
let(:user) { create(:user) }
let_it_be(:project) { create(:project, :repository) }
let_it_be(:developer) { create(:user) }
let_it_be(:guest) { create(:user) }
let(:user) { developer }
before do
project.add_developer(user)
before_all do
project.add_developer(developer)
project.add_guest(guest)
end
def build_issue(issue_params = {})
......@@ -134,6 +137,7 @@ RSpec.describe Issues::BuildService do
end
describe '#execute' do
context 'as developer' do
it 'builds a new issues with given params' do
milestone = create(:milestone, project: project)
issue = build_issue(milestone_id: milestone.id)
......@@ -147,18 +151,42 @@ RSpec.describe Issues::BuildService do
expect(issue.milestone).to be_nil
end
end
context 'setting issue type' do
it 'sets the issue_type on the issue' do
issue = build_issue(issue_type: 'incident')
context 'as guest' do
let(:user) { guest }
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
context 'setting issue type' do
it 'defaults to issue if issue_type not given' do
issue = build_issue
expect(issue.issue_type).to eq('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).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
......
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