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
8c8728cf
Commit
8c8728cf
authored
Jun 04, 2020
by
Amparo Luna
Committed by
Jarka Košanová
Jun 04, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pass hard delete option to snippets bulk destroy
parent
8fc733e6
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
3 deletions
+32
-3
app/services/snippets/bulk_destroy_service.rb
app/services/snippets/bulk_destroy_service.rb
+2
-2
app/services/users/destroy_service.rb
app/services/users/destroy_service.rb
+1
-1
changelogs/unreleased/al-214420-pass-hard-delete-on-snippets-destroy.yml
...leased/al-214420-pass-hard-delete-on-snippets-destroy.yml
+5
-0
spec/services/snippets/bulk_destroy_service_spec.rb
spec/services/snippets/bulk_destroy_service_spec.rb
+12
-0
spec/services/users/destroy_service_spec.rb
spec/services/users/destroy_service_spec.rb
+12
-0
No files found.
app/services/snippets/bulk_destroy_service.rb
View file @
8c8728cf
...
...
@@ -14,10 +14,10 @@ module Snippets
@snippets
=
snippets
end
def
execute
def
execute
(
options
=
{})
return
ServiceResponse
.
success
(
message:
'No snippets found.'
)
if
snippets
.
empty?
user_can_delete_snippets!
user_can_delete_snippets!
unless
options
[
:hard_delete
]
attempt_delete_repositories!
snippets
.
destroy_all
# rubocop: disable Cop/DestroyAll
...
...
app/services/users/destroy_service.rb
View file @
8c8728cf
...
...
@@ -56,7 +56,7 @@ module Users
MigrateToGhostUserService
.
new
(
user
).
execute
unless
options
[
:hard_delete
]
response
=
Snippets
::
BulkDestroyService
.
new
(
current_user
,
user
.
snippets
).
execute
response
=
Snippets
::
BulkDestroyService
.
new
(
current_user
,
user
.
snippets
).
execute
(
options
)
raise
DestroyError
,
response
.
message
if
response
.
error?
# Rails attempts to load all related records into memory before
...
...
changelogs/unreleased/al-214420-pass-hard-delete-on-snippets-destroy.yml
0 → 100644
View file @
8c8728cf
---
title
:
Pass hard delete option to snippets bulk destroy
merge_request
:
33520
author
:
type
:
fixed
spec/services/snippets/bulk_destroy_service_spec.rb
View file @
8c8728cf
...
...
@@ -69,6 +69,18 @@ describe Snippets::BulkDestroyService do
it_behaves_like
'error is raised'
do
let
(
:error_message
)
{
"You don't have access to delete these snippets."
}
end
context
'when hard_delete option is passed'
do
subject
{
described_class
.
new
(
service_user
,
snippets
).
execute
(
hard_delete:
true
)
}
it
'returns a ServiceResponse success response'
do
expect
(
subject
).
to
be_success
end
it
'deletes all the snippets that belong to the user'
do
expect
{
subject
}.
to
change
(
Snippet
,
:count
).
by
(
-
2
)
end
end
end
context
'when an error is raised deleting the repository'
do
...
...
spec/services/users/destroy_service_spec.rb
View file @
8c8728cf
...
...
@@ -67,6 +67,18 @@ describe Users::DestroyService do
end
end
it
'calls the bulk snippet destroy service with hard delete option if it is present'
do
# this avoids getting into Projects::DestroyService as it would
# call Snippets::BulkDestroyService first!
allow
(
user
).
to
receive
(
:personal_projects
).
and_return
([])
expect_next_instance_of
(
Snippets
::
BulkDestroyService
)
do
|
bulk_destroy_service
|
expect
(
bulk_destroy_service
).
to
receive
(
:execute
).
with
(
hard_delete:
true
).
and_call_original
end
service
.
execute
(
user
,
hard_delete:
true
)
end
it
'does not delete project snippets that the user is the author of'
do
repo
=
create
(
:project_snippet
,
:repository
,
author:
user
).
snippet_repository
service
.
execute
(
user
)
...
...
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