Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
ac9fc0ca
Commit
ac9fc0ca
authored
Oct 20, 2020
by
David O'Regan
Committed by
Heinrich Lee Yu
Oct 20, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support incident creation as guest
parent
9f22b536
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
145 additions
and
50 deletions
+145
-50
app/services/issues/build_service.rb
app/services/issues/build_service.rb
+13
-7
app/views/shared/issuable/form/_type_selector.html.haml
app/views/shared/issuable/form/_type_selector.html.haml
+1
-1
ee/app/services/ee/issues/build_service.rb
ee/app/services/ee/issues/build_service.rb
+14
-0
ee/spec/services/issues/build_service_spec.rb
ee/spec/services/issues/build_service_spec.rb
+39
-9
spec/features/incidents/user_creates_new_incident_spec.rb
spec/features/incidents/user_creates_new_incident_spec.rb
+29
-12
spec/services/issues/build_service_spec.rb
spec/services/issues/build_service_spec.rb
+49
-21
No files found.
app/services/issues/build_service.rb
View file @
ac9fc0ca
...
...
@@ -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
...
...
app/views/shared/issuable/form/_type_selector.html.haml
View file @
ac9fc0ca
-
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'
...
...
ee/app/services/ee/issues/build_service.rb
View file @
ac9fc0ca
...
...
@@ -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
ee/spec/services/issues/build_service_spec.rb
View file @
ac9fc0ca
...
...
@@ -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
spec/features/incidents/user_creates_new_incident_spec.rb
View file @
ac9fc0ca
...
...
@@ -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 click
ed'
do
it
'
when clicked shows the create issue page with the Incident type pre-select
ed'
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
spec/services/issues/build_service_spec.rb
View file @
ac9fc0ca
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment