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
85f9a3ed
Commit
85f9a3ed
authored
Apr 30, 2021
by
Sarah Yasonik
Committed by
David Fernandez
Apr 30, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow issue type changes via internal API
parent
de530d4e
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
88 additions
and
16 deletions
+88
-16
app/controllers/projects/issues_controller.rb
app/controllers/projects/issues_controller.rb
+4
-13
app/services/issues/update_service.rb
app/services/issues/update_service.rb
+2
-1
changelogs/unreleased/sy-change-issue-type.yml
changelogs/unreleased/sy-change-issue-type.yml
+5
-0
ee/app/services/ee/issues/update_service.rb
ee/app/services/ee/issues/update_service.rb
+7
-0
ee/app/services/incident_management/incidents/create_sla_service.rb
...vices/incident_management/incidents/create_sla_service.rb
+1
-0
ee/spec/services/ee/issues/update_service_spec.rb
ee/spec/services/ee/issues/update_service_spec.rb
+35
-0
ee/spec/services/incident_management/incidents/create_sla_service_spec.rb
.../incident_management/incidents/create_sla_service_spec.rb
+11
-0
spec/controllers/projects/issues_controller_spec.rb
spec/controllers/projects/issues_controller_spec.rb
+14
-1
spec/services/issues/update_service_spec.rb
spec/services/issues/update_service_spec.rb
+9
-1
No files found.
app/controllers/projects/issues_controller.rb
View file @
85f9a3ed
...
@@ -108,10 +108,10 @@ class Projects::IssuesController < Projects::ApplicationController
...
@@ -108,10 +108,10 @@ class Projects::IssuesController < Projects::ApplicationController
params
[
:issue
]
||=
ActionController
::
Parameters
.
new
(
params
[
:issue
]
||=
ActionController
::
Parameters
.
new
(
assignee_ids:
""
assignee_ids:
""
)
)
build_params
=
issue_
create_
params
.
merge
(
build_params
=
issue_params
.
merge
(
merge_request_to_resolve_discussions_of:
params
[
:merge_request_to_resolve_discussions_of
],
merge_request_to_resolve_discussions_of:
params
[
:merge_request_to_resolve_discussions_of
],
discussion_to_resolve:
params
[
:discussion_to_resolve
],
discussion_to_resolve:
params
[
:discussion_to_resolve
],
confidential:
!!
Gitlab
::
Utils
.
to_boolean
(
issue_
create_
params
[
:confidential
])
confidential:
!!
Gitlab
::
Utils
.
to_boolean
(
issue_params
[
:confidential
])
)
)
service
=
::
Issues
::
BuildService
.
new
(
project
,
current_user
,
build_params
)
service
=
::
Issues
::
BuildService
.
new
(
project
,
current_user
,
build_params
)
...
@@ -128,7 +128,7 @@ class Projects::IssuesController < Projects::ApplicationController
...
@@ -128,7 +128,7 @@ class Projects::IssuesController < Projects::ApplicationController
end
end
def
create
def
create
create_params
=
issue_
create_
params
.
merge
(
spammable_params
).
merge
(
create_params
=
issue_params
.
merge
(
spammable_params
).
merge
(
merge_request_to_resolve_discussions_of:
params
[
:merge_request_to_resolve_discussions_of
],
merge_request_to_resolve_discussions_of:
params
[
:merge_request_to_resolve_discussions_of
],
discussion_to_resolve:
params
[
:discussion_to_resolve
]
discussion_to_resolve:
params
[
:discussion_to_resolve
]
)
)
...
@@ -314,17 +314,8 @@ class Projects::IssuesController < Projects::ApplicationController
...
@@ -314,17 +314,8 @@ class Projects::IssuesController < Projects::ApplicationController
task_num
task_num
lock_version
lock_version
discussion_locked
discussion_locked
]
+
[{
label_ids:
[],
assignee_ids:
[],
update_task:
[
:index
,
:checked
,
:line_number
,
:line_source
]
}]
end
def
issue_create_params
create_params
=
%i[
issue_type
issue_type
]
]
+
[{
label_ids:
[],
assignee_ids:
[],
update_task:
[
:index
,
:checked
,
:line_number
,
:line_source
]
}]
params
.
require
(
:issue
).
permit
(
*
create_params
).
merge
(
issue_params
)
end
end
def
reorder_params
def
reorder_params
...
...
app/services/issues/update_service.rb
View file @
85f9a3ed
...
@@ -24,10 +24,11 @@ module Issues
...
@@ -24,10 +24,11 @@ module Issues
def
filter_params
(
issue
)
def
filter_params
(
issue
)
super
super
# filter confidential in `Issues::UpdateService` and not in `IssuableBaseService#filtr_params`
# filter confidential in `Issues::UpdateService` and not in `IssuableBaseService#filt
e
r_params`
# because we do allow users that cannot admin issues to set confidential flag when creating an issue
# because we do allow users that cannot admin issues to set confidential flag when creating an issue
unless
can_admin_issuable?
(
issue
)
unless
can_admin_issuable?
(
issue
)
params
.
delete
(
:confidential
)
params
.
delete
(
:confidential
)
params
.
delete
(
:issue_type
)
end
end
end
end
...
...
changelogs/unreleased/sy-change-issue-type.yml
0 → 100644
View file @
85f9a3ed
---
title
:
Add internal API support for updating issue types on issues
merge_request
:
60173
author
:
type
:
added
ee/app/services/ee/issues/update_service.rb
View file @
85f9a3ed
...
@@ -36,6 +36,7 @@ module EE
...
@@ -36,6 +36,7 @@ module EE
super
super
handle_iteration_change
(
issue
)
handle_iteration_change
(
issue
)
handle_issue_type_change
(
issue
)
end
end
private
private
...
@@ -54,6 +55,12 @@ module EE
...
@@ -54,6 +55,12 @@ module EE
end
end
end
end
def
handle_issue_type_change
(
issue
)
return
unless
issue
.
previous_changes
.
include?
(
'issue_type'
)
::
IncidentManagement
::
Incidents
::
CreateSlaService
.
new
(
issue
,
current_user
).
execute
end
def
handle_promotion
(
issue
)
def
handle_promotion
(
issue
)
return
unless
params
.
delete
(
:promote_to_epic
)
return
unless
params
.
delete
(
:promote_to_epic
)
...
...
ee/app/services/incident_management/incidents/create_sla_service.rb
View file @
85f9a3ed
...
@@ -12,6 +12,7 @@ module IncidentManagement
...
@@ -12,6 +12,7 @@ module IncidentManagement
def
execute
def
execute
return
not_enabled_success
unless
issuable
.
sla_available?
return
not_enabled_success
unless
issuable
.
sla_available?
return
not_enabled_success
unless
incident_setting
&
.
sla_timer?
return
not_enabled_success
unless
incident_setting
&
.
sla_timer?
return
success
(
sla:
issuable
.
issuable_sla
)
if
issuable
.
issuable_sla
sla
=
issuable
.
build_issuable_sla
(
sla
=
issuable
.
build_issuable_sla
(
due_at:
issuable
.
created_at
+
incident_setting
.
sla_timer_minutes
.
minutes
due_at:
issuable
.
created_at
+
incident_setting
.
sla_timer_minutes
.
minutes
...
...
ee/spec/services/ee/issues/update_service_spec.rb
View file @
85f9a3ed
...
@@ -169,6 +169,41 @@ RSpec.describe Issues::UpdateService do
...
@@ -169,6 +169,41 @@ RSpec.describe Issues::UpdateService do
end
end
end
end
context
'changing issue_type'
do
let!
(
:sla_setting
)
{
create
(
:project_incident_management_setting
,
:sla_enabled
,
project:
project
)
}
before
do
stub_licensed_features
(
incident_sla:
true
)
end
context
'from issue to incident'
do
it
'creates an SLA'
do
expect
{
update_issue
(
issue_type:
'incident'
)
}.
to
change
(
IssuableSla
,
:count
).
by
(
1
)
expect
(
issue
.
reload
.
issuable_sla
).
to
be_present
end
end
context
'from incident to issue'
do
let
(
:issue
)
{
create
(
:incident
,
project:
project
)
}
let!
(
:sla
)
{
create
(
:issuable_sla
,
issue:
issue
)
}
it
'does not remove the SLA or create a new one'
do
expect
{
update_issue
(
issue_type:
'issue'
)
}.
not_to
change
(
IssuableSla
,
:count
)
expect
(
issue
.
reload
.
issuable_sla
).
to
be_present
end
end
# Not an expected scenario, but covers an SLA-agnostic hypothetical
context
'from test_case to issue'
do
let
(
:issue
)
{
create
(
:quality_test_case
,
project:
project
)
}
it
'does nothing'
do
expect
{
update_issue
(
issue_type:
'issue'
)
}.
not_to
change
(
IssuableSla
,
:count
)
expect
(
issue
.
reload
.
issuable_sla
).
to
be_nil
end
end
end
context
'assigning epic'
do
context
'assigning epic'
do
before
do
before
do
stub_licensed_features
(
epics:
true
)
stub_licensed_features
(
epics:
true
)
...
...
ee/spec/services/incident_management/incidents/create_sla_service_spec.rb
View file @
85f9a3ed
...
@@ -54,6 +54,17 @@ RSpec.describe IncidentManagement::Incidents::CreateSlaService do
...
@@ -54,6 +54,17 @@ RSpec.describe IncidentManagement::Incidents::CreateSlaService do
it_behaves_like
'no issuable sla created'
it_behaves_like
'no issuable sla created'
end
end
context
'issuable sla already exists'
do
let!
(
:issuable_sla
)
{
create
(
:issuable_sla
,
issue:
incident
)
}
it
'returns a success with the sla'
,
:aggregate_failures
do
expect
{
subject
}.
not_to
change
(
IssuableSla
,
:count
)
expect
(
create_issuable_sla_response
.
success?
).
to
eq
(
true
)
expect
(
response_payload_sla
).
to
be_a
(
IssuableSla
)
end
end
it
'creates the issuable sla with the given offset'
,
:aggregate_failures
do
it
'creates the issuable sla with the given offset'
,
:aggregate_failures
do
expect
{
subject
}.
to
change
(
IssuableSla
,
:count
)
expect
{
subject
}.
to
change
(
IssuableSla
,
:count
)
...
...
spec/controllers/projects/issues_controller_spec.rb
View file @
85f9a3ed
...
@@ -586,13 +586,15 @@ RSpec.describe Projects::IssuesController do
...
@@ -586,13 +586,15 @@ RSpec.describe Projects::IssuesController do
end
end
describe
'PUT #update'
do
describe
'PUT #update'
do
let
(
:issue_params
)
{
{
title:
'New title'
}
}
subject
do
subject
do
put
:update
,
put
:update
,
params:
{
params:
{
namespace_id:
project
.
namespace
,
namespace_id:
project
.
namespace
,
project_id:
project
,
project_id:
project
,
id:
issue
.
to_param
,
id:
issue
.
to_param
,
issue:
{
title:
'New title'
}
issue:
issue_params
},
},
format: :json
format: :json
end
end
...
@@ -614,6 +616,17 @@ RSpec.describe Projects::IssuesController do
...
@@ -614,6 +616,17 @@ RSpec.describe Projects::IssuesController do
expect
(
issue
.
reload
.
title
).
to
eq
(
'New title'
)
expect
(
issue
.
reload
.
title
).
to
eq
(
'New title'
)
end
end
context
'with issue_type param'
do
let
(
:issue_params
)
{
{
issue_type:
'incident'
}
}
it
'permits the parameter'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
issue
.
reload
.
issue_type
).
to
eql
(
'incident'
)
end
end
context
'when the SpamVerdictService disallows'
do
context
'when the SpamVerdictService disallows'
do
before
do
before
do
stub_application_setting
(
recaptcha_enabled:
true
)
stub_application_setting
(
recaptcha_enabled:
true
)
...
...
spec/services/issues/update_service_spec.rb
View file @
85f9a3ed
...
@@ -282,7 +282,14 @@ RSpec.describe Issues::UpdateService, :mailer do
...
@@ -282,7 +282,14 @@ RSpec.describe Issues::UpdateService, :mailer do
end
end
it
'filters out params that cannot be set without the :admin_issue permission'
do
it
'filters out params that cannot be set without the :admin_issue permission'
do
described_class
.
new
(
project
,
guest
,
opts
.
merge
(
confidential:
true
)).
execute
(
issue
)
described_class
.
new
(
project
,
guest
,
opts
.
merge
(
confidential:
true
,
issue_type:
'test_case'
)
).
execute
(
issue
)
expect
(
issue
).
to
be_valid
expect
(
issue
).
to
be_valid
expect
(
issue
.
title
).
to
eq
'New title'
expect
(
issue
.
title
).
to
eq
'New title'
...
@@ -293,6 +300,7 @@ RSpec.describe Issues::UpdateService, :mailer do
...
@@ -293,6 +300,7 @@ RSpec.describe Issues::UpdateService, :mailer do
expect
(
issue
.
due_date
).
to
be_nil
expect
(
issue
.
due_date
).
to
be_nil
expect
(
issue
.
discussion_locked
).
to
be_falsey
expect
(
issue
.
discussion_locked
).
to
be_falsey
expect
(
issue
.
confidential
).
to
be_falsey
expect
(
issue
.
confidential
).
to
be_falsey
expect
(
issue
.
issue_type
).
to
eql
(
'issue'
)
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