From 1fc6f6cc7101a9c4dee694682a3533a5e4ba3447 Mon Sep 17 00:00:00 2001 From: Mark Fletcher Date: Tue, 20 Dec 2016 13:32:43 +0000 Subject: [PATCH] Execute web hooks for WikiPage delete operation * Add a new DestroyService for Wiki Pages * Alter WikiPagesController to use the new service --- app/controllers/projects/wikis_controller.rb | 2 +- app/services/wiki_pages/destroy_service.rb | 11 ++++++++++ ...ge-delete-does-not-trigger-the-webhook.yml | 4 ++++ doc/user/project/integrations/webhooks.md | 2 +- .../wiki_pages/destroy_service_spec.rb | 21 +++++++++++++++++++ 5 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 app/services/wiki_pages/destroy_service.rb create mode 100644 changelogs/unreleased/19302-wiki-page-delete-does-not-trigger-the-webhook.yml create mode 100644 spec/services/wiki_pages/destroy_service_spec.rb diff --git a/app/controllers/projects/wikis_controller.rb b/app/controllers/projects/wikis_controller.rb index 0faa71c4d7d..2d8064c9878 100644 --- a/app/controllers/projects/wikis_controller.rb +++ b/app/controllers/projects/wikis_controller.rb @@ -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), diff --git a/app/services/wiki_pages/destroy_service.rb b/app/services/wiki_pages/destroy_service.rb new file mode 100644 index 00000000000..6b93fb2f6d7 --- /dev/null +++ b/app/services/wiki_pages/destroy_service.rb @@ -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 diff --git a/changelogs/unreleased/19302-wiki-page-delete-does-not-trigger-the-webhook.yml b/changelogs/unreleased/19302-wiki-page-delete-does-not-trigger-the-webhook.yml new file mode 100644 index 00000000000..d74057dca8a --- /dev/null +++ b/changelogs/unreleased/19302-wiki-page-delete-does-not-trigger-the-webhook.yml @@ -0,0 +1,4 @@ +--- +title: Execute web hooks for WikiPage delete operation +merge_request: 8198 +author: diff --git a/doc/user/project/integrations/webhooks.md b/doc/user/project/integrations/webhooks.md index 9df0c765f84..55d480bfb72 100644 --- a/doc/user/project/integrations/webhooks.md +++ b/doc/user/project/integrations/webhooks.md @@ -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**: diff --git a/spec/services/wiki_pages/destroy_service_spec.rb b/spec/services/wiki_pages/destroy_service_spec.rb new file mode 100644 index 00000000000..a4b9a390fe2 --- /dev/null +++ b/spec/services/wiki_pages/destroy_service_spec.rb @@ -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