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:
Mark Fletcher 2016-12-20 13:32:43 +00:00
parent a616b475b1
commit 1fc6f6cc71
5 changed files with 38 additions and 2 deletions

View file

@ -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),

View 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

View file

@ -0,0 +1,4 @@
---
title: Execute web hooks for WikiPage delete operation
merge_request: 8198
author:

View file

@ -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**:

View 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