Execute web hooks for WikiPage delete operation
* Add a new DestroyService for Wiki Pages * Alter WikiPagesController to use the new service
This commit is contained in:
parent
a616b475b1
commit
1fc6f6cc71
5 changed files with 38 additions and 2 deletions
|
@ -84,7 +84,7 @@ class Projects::WikisController < Projects::ApplicationController
|
|||
|
||||
def destroy
|
||||
@page = @project_wiki.find_page(params[:id])
|
||||
@page&.delete
|
||||
WikiPages::DestroyService.new(@project, current_user).execute(@page)
|
||||
|
||||
redirect_to(
|
||||
namespace_project_wiki_path(@project.namespace, @project, :home),
|
||||
|
|
11
app/services/wiki_pages/destroy_service.rb
Normal file
11
app/services/wiki_pages/destroy_service.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
module WikiPages
|
||||
class DestroyService < WikiPages::BaseService
|
||||
def execute(page)
|
||||
if page&.delete
|
||||
execute_hooks(page, 'delete')
|
||||
end
|
||||
|
||||
page
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
title: Execute web hooks for WikiPage delete operation
|
||||
merge_request: 8198
|
||||
author:
|
|
@ -714,7 +714,7 @@ X-Gitlab-Event: Merge Request Hook
|
|||
|
||||
### Wiki Page events
|
||||
|
||||
Triggered when a wiki page is created or edited.
|
||||
Triggered when a wiki page is created, edited or deleted.
|
||||
|
||||
**Request Header**:
|
||||
|
||||
|
|
21
spec/services/wiki_pages/destroy_service_spec.rb
Normal file
21
spec/services/wiki_pages/destroy_service_spec.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe WikiPages::DestroyService, services: true do
|
||||
let(:project) { create(:empty_project) }
|
||||
let(:user) { create(:user) }
|
||||
let(:wiki_page) { create(:wiki_page) }
|
||||
let(:service) { described_class.new(project, user) }
|
||||
|
||||
describe '#execute' do
|
||||
before do
|
||||
allow(service).to receive(:execute_hooks)
|
||||
project.add_master(user)
|
||||
end
|
||||
|
||||
it 'executes webhooks' do
|
||||
service.execute(wiki_page)
|
||||
|
||||
expect(service).to have_received(:execute_hooks).once.with(wiki_page, 'delete')
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue