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
d8ce327c
Commit
d8ce327c
authored
Aug 10, 2020
by
ddash2
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Destroy service uses ServiceResponse
parent
77e1d308
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
89 additions
and
24 deletions
+89
-24
app/controllers/concerns/wiki_actions.rb
app/controllers/concerns/wiki_actions.rb
+12
-13
app/services/wiki_pages/destroy_service.rb
app/services/wiki_pages/destroy_service.rb
+6
-3
lib/api/wikis.rb
lib/api/wikis.rb
+6
-2
lib/gitlab/git/wiki.rb
lib/gitlab/git/wiki.rb
+0
-1
locale/gitlab.pot
locale/gitlab.pot
+3
-0
spec/support/shared_examples/controllers/wiki_actions_shared_examples.rb
...ared_examples/controllers/wiki_actions_shared_examples.rb
+48
-1
spec/support/shared_examples/services/wiki_pages/destroy_service_shared_examples.rb
...es/services/wiki_pages/destroy_service_shared_examples.rb
+14
-4
No files found.
app/controllers/concerns/wiki_actions.rb
View file @
d8ce327c
...
...
@@ -103,7 +103,7 @@ module WikiActions
else
render
'shared/wikis/edit'
end
rescue
WikiPage
::
PageChangedError
,
WikiPage
::
PageRenameError
,
Gitlab
::
Git
::
Wiki
::
OperationError
=>
e
rescue
WikiPage
::
PageChangedError
,
WikiPage
::
PageRenameError
=>
e
@error
=
e
render
'shared/wikis/edit'
end
...
...
@@ -120,13 +120,8 @@ module WikiActions
notice:
_
(
'Wiki was successfully updated.'
)
)
else
flash
[
:alert
]
=
response
.
message
render
'shared/wikis/edit'
end
rescue
Gitlab
::
Git
::
Wiki
::
OperationError
=>
e
@page
=
build_page
(
wiki_params
)
@error
=
e
render
'shared/wikis/edit'
end
# rubocop:enable Gitlab/ModuleWithInstanceVariables
...
...
@@ -162,15 +157,19 @@ module WikiActions
# rubocop:disable Gitlab/ModuleWithInstanceVariables
def
destroy
WikiPages
::
DestroyService
.
new
(
container:
container
,
current_user:
current_user
).
execute
(
page
)
return
render_404
unless
page
response
=
WikiPages
::
DestroyService
.
new
(
container:
container
,
current_user:
current_user
).
execute
(
page
)
if
response
.
success?
redirect_to
wiki_path
(
wiki
),
status: :found
,
notice:
_
(
"Page was successfully deleted"
)
rescue
Gitlab
::
Git
::
Wiki
::
OperationError
=>
e
@error
=
e
els
e
@error
=
respons
e
render
'shared/wikis/edit'
end
end
# rubocop:enable Gitlab/ModuleWithInstanceVariables
private
...
...
app/services/wiki_pages/destroy_service.rb
View file @
d8ce327c
...
...
@@ -3,11 +3,14 @@
module
WikiPages
class
DestroyService
<
WikiPages
::
BaseService
def
execute
(
page
)
if
page
&
.
delete
if
page
.
delete
execute_hooks
(
page
)
ServiceResponse
.
success
(
payload:
{
page:
page
})
else
ServiceResponse
.
error
(
message:
_
(
'Could not delete wiki page'
),
payload:
{
page:
page
}
)
end
page
end
def
usage_counter_action
...
...
lib/api/wikis.rb
View file @
d8ce327c
...
...
@@ -101,11 +101,15 @@ module API
delete
':id/wikis/:slug'
do
authorize!
:admin_wiki
,
container
WikiPages
::
DestroyService
response
=
WikiPages
::
DestroyService
.
new
(
container:
container
,
current_user:
current_user
)
.
execute
(
wiki_page
)
if
response
.
success?
no_content!
else
render_api_error!
(
reponse
.
message
)
end
end
desc
'Upload an attachment to the wiki repository'
do
...
...
lib/gitlab/git/wiki.rb
View file @
d8ce327c
...
...
@@ -6,7 +6,6 @@ module Gitlab
include
Gitlab
::
Git
::
WrapsGitalyErrors
DuplicatePageError
=
Class
.
new
(
StandardError
)
OperationError
=
Class
.
new
(
StandardError
)
DEFAULT_PAGINATION
=
Kaminari
.
config
.
default_per_page
...
...
locale/gitlab.pot
View file @
d8ce327c
...
...
@@ -6979,6 +6979,9 @@ msgstr ""
msgid "Could not delete chat nickname %{chat_name}."
msgstr ""
msgid "Could not delete wiki page"
msgstr ""
msgid "Could not find design."
msgstr ""
...
...
spec/support/shared_examples/controllers/wiki_actions_shared_examples.rb
View file @
d8ce327c
...
...
@@ -388,7 +388,54 @@ RSpec.shared_examples 'wiki controller actions' do
end
.
not_to
change
{
wiki
.
list_pages
.
size
}
expect
(
response
).
to
render_template
(
'shared/wikis/edit'
)
expect
(
flash
[
:alert
]).
to
eq
(
'Could not create wiki page'
)
end
end
end
describe
'DELETE #destroy'
do
let
(
:id_param
)
{
wiki_title
}
subject
do
delete
(
:destroy
,
params:
routing_params
.
merge
(
id:
id_param
))
end
context
'when page exists'
do
it
'deletes the page'
do
expect
do
subject
end
.
to
change
{
wiki
.
list_pages
.
size
}.
by
(
-
1
)
end
context
'but page cannot be deleted'
do
before
do
allow_next_instance_of
(
WikiPage
)
do
|
page
|
allow
(
page
).
to
receive
(
:delete
).
and_return
(
false
)
end
end
it
'renders the edit state'
do
expect
do
subject
end
.
not_to
change
{
wiki
.
list_pages
.
size
}
expect
(
response
).
to
render_template
(
'shared/wikis/edit'
)
expect
(
assigns
(
:error
).
message
).
to
eq
(
'Could not delete wiki page'
)
end
end
end
context
'when page does not exist'
do
let
(
:id_param
)
{
'nil'
}
it
'renders 404'
do
expect
do
subject
end
.
not_to
change
{
wiki
.
list_pages
.
size
}
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
end
end
...
...
spec/support/shared_examples/services/wiki_pages/destroy_service_shared_examples.rb
View file @
d8ce327c
...
...
@@ -32,9 +32,19 @@ RSpec.shared_examples 'WikiPages::DestroyService#execute' do |container_type|
)
end
context
'when the deletion fails'
do
before
do
expect
(
page
).
to
receive
(
:delete
).
and_return
(
false
)
end
it
'returns an error response'
do
response
=
service
.
execute
(
page
)
expect
(
response
).
to
be_error
end
it
'does not increment the delete count if the deletion failed'
do
counter
=
Gitlab
::
UsageDataCounters
::
WikiPageCounter
e
xpect
{
service
.
execute
(
nil
)
}.
not_to
change
{
counter
.
read
(
:delete
)
}
expect
{
service
.
execute
(
page
)
}.
not_to
change
{
counter
.
read
(
:delete
)
}
e
nd
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