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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
7fb1bb01
Commit
7fb1bb01
authored
Nov 25, 2017
by
George Andrinopoulos
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create issue and merge request destroy services
parent
d199ecd4
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
59 additions
and
5 deletions
+59
-5
app/controllers/concerns/issuable_actions.rb
app/controllers/concerns/issuable_actions.rb
+1
-1
app/models/issue.rb
app/models/issue.rb
+0
-1
app/models/merge_request.rb
app/models/merge_request.rb
+0
-1
app/services/issuable/destroy_service.rb
app/services/issuable/destroy_service.rb
+9
-0
changelogs/unreleased/39601-create-issuable-destroy-service.yml
...logs/unreleased/39601-create-issuable-destroy-service.yml
+5
-0
lib/api/issues.rb
lib/api/issues.rb
+3
-1
lib/api/merge_requests.rb
lib/api/merge_requests.rb
+3
-1
spec/services/issuable/destroy_service_spec.rb
spec/services/issuable/destroy_service_spec.rb
+38
-0
No files found.
app/controllers/concerns/issuable_actions.rb
View file @
7fb1bb01
...
@@ -54,7 +54,7 @@ module IssuableActions
...
@@ -54,7 +54,7 @@ module IssuableActions
end
end
def
destroy
def
destroy
issuable
.
destroy
Issuable
::
DestroyService
.
new
(
project
,
current_user
).
execute
(
issuable
)
TodoService
.
new
.
destroy_issuable
(
issuable
,
current_user
)
TodoService
.
new
.
destroy_issuable
(
issuable
,
current_user
)
name
=
issuable
.
human_class_name
name
=
issuable
.
human_class_name
...
...
app/models/issue.rb
View file @
7fb1bb01
...
@@ -49,7 +49,6 @@ class Issue < ActiveRecord::Base
...
@@ -49,7 +49,6 @@ class Issue < ActiveRecord::Base
scope
:public_only
,
->
{
where
(
confidential:
false
)
}
scope
:public_only
,
->
{
where
(
confidential:
false
)
}
after_save
:expire_etag_cache
after_save
:expire_etag_cache
after_commit
:update_project_counter_caches
,
on: :destroy
attr_spammable
:title
,
spam_title:
true
attr_spammable
:title
,
spam_title:
true
attr_spammable
:description
,
spam_description:
true
attr_spammable
:description
,
spam_description:
true
...
...
app/models/merge_request.rb
View file @
7fb1bb01
...
@@ -52,7 +52,6 @@ class MergeRequest < ActiveRecord::Base
...
@@ -52,7 +52,6 @@ class MergeRequest < ActiveRecord::Base
after_create
:ensure_merge_request_diff
,
unless: :importing?
after_create
:ensure_merge_request_diff
,
unless: :importing?
after_update
:reload_diff_if_branch_changed
after_update
:reload_diff_if_branch_changed
after_commit
:update_project_counter_caches
,
on: :destroy
# When this attribute is true some MR validation is ignored
# When this attribute is true some MR validation is ignored
# It allows us to close or modify broken merge requests
# It allows us to close or modify broken merge requests
...
...
app/services/issuable/destroy_service.rb
0 → 100644
View file @
7fb1bb01
module
Issuable
class
DestroyService
<
IssuableBaseService
def
execute
(
issuable
)
if
issuable
.
destroy
issuable
.
update_project_counter_caches
end
end
end
end
changelogs/unreleased/39601-create-issuable-destroy-service.yml
0 → 100644
View file @
7fb1bb01
---
title
:
Create issuable destroy service
merge_request
:
15604
author
:
George Andrinopoulos
type
:
other
lib/api/issues.rb
View file @
7fb1bb01
...
@@ -255,7 +255,9 @@ module API
...
@@ -255,7 +255,9 @@ module API
authorize!
(
:destroy_issue
,
issue
)
authorize!
(
:destroy_issue
,
issue
)
destroy_conditionally!
(
issue
)
destroy_conditionally!
(
issue
)
do
|
issue
|
Issuable
::
DestroyService
.
new
(
user_project
,
current_user
).
execute
(
issue
)
end
end
end
desc
'List merge requests closing issue'
do
desc
'List merge requests closing issue'
do
...
...
lib/api/merge_requests.rb
View file @
7fb1bb01
...
@@ -167,7 +167,9 @@ module API
...
@@ -167,7 +167,9 @@ module API
authorize!
(
:destroy_merge_request
,
merge_request
)
authorize!
(
:destroy_merge_request
,
merge_request
)
destroy_conditionally!
(
merge_request
)
destroy_conditionally!
(
merge_request
)
do
|
merge_request
|
Issuable
::
DestroyService
.
new
(
user_project
,
current_user
).
execute
(
merge_request
)
end
end
end
params
do
params
do
...
...
spec/services/issuable/destroy_service_spec.rb
0 → 100644
View file @
7fb1bb01
require
'spec_helper'
describe
Issuable
::
DestroyService
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
subject
(
:service
)
{
described_class
.
new
(
project
,
user
)
}
describe
'#execute'
do
context
'when issuable is an issue'
do
let!
(
:issue
)
{
create
(
:issue
,
project:
project
,
author:
user
)
}
it
'destroys the issue'
do
expect
{
service
.
execute
(
issue
)
}.
to
change
{
project
.
issues
.
count
}.
by
(
-
1
)
end
it
'updates open issues count cache'
do
expect_any_instance_of
(
Projects
::
OpenIssuesCountService
).
to
receive
(
:refresh_cache
)
service
.
execute
(
issue
)
end
end
context
'when issuable is a merge request'
do
let!
(
:merge_request
)
{
create
(
:merge_request
,
target_project:
project
,
source_project:
project
,
author:
user
)
}
it
'destroys the merge request'
do
expect
{
service
.
execute
(
merge_request
)
}.
to
change
{
project
.
merge_requests
.
count
}.
by
(
-
1
)
end
it
'updates open merge requests count cache'
do
expect_any_instance_of
(
Projects
::
OpenMergeRequestsCountService
).
to
receive
(
:refresh_cache
)
service
.
execute
(
merge_request
)
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