Skip to content

Commit

Permalink
Unpublish draft worldwide office when deleted
Browse files Browse the repository at this point in the history
If a worldwide office is attached to a draft editionable worldwide
organisation and the office itself is deleted, we need to unpublish the
draft office and it's contact from Publishing API.

This cannot be done using `PublishingApiAssociatedDocuments` as
worldwide offices are hard deleted and therefore we can't use a query to
identify which offices have been deleted, like we can for HTML
attachments.
  • Loading branch information
brucebolt committed Mar 28, 2024
1 parent 79513d3 commit a585bc6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/controllers/admin/worldwide_offices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def destroy
title = @worldwide_office.title

if @worldwide_office.destroy
if @worldwide_office.edition
PublishingApiDiscardDraftWorker.perform_async(@worldwide_office.content_id, I18n.default_locale.to_s)
PublishingApiDiscardDraftWorker.perform_async(@worldwide_office.contact.content_id, I18n.default_locale.to_s)
end

republish_draft_worldwide_organisation
redirect_to admin_worldwide_organisation_worldwide_offices_path(@worldwide_organisation), notice: "#{title} has been deleted"
else
Expand Down
17 changes: 17 additions & 0 deletions test/functional/admin/worldwide_offices_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,23 @@ class Admin::WorldwideOfficesControllerTest < ActionController::TestCase
}
end

test "DELETE :destroy for an office attached to an editionable worldwide organisation discards draft of the office and the contact" do
feature_flags.switch! :editionable_worldwide_organisations, true

office = create(:worldwide_office, edition: create(:draft_editionable_worldwide_organisation), worldwide_organisation: nil)

PublishingApiDiscardDraftWorker.any_instance.expects(:perform).with(office.content_id, "en")
PublishingApiDiscardDraftWorker.any_instance.expects(:perform).with(office.contact.content_id, "en")

Sidekiq::Testing.inline! do
delete :destroy,
params: {
id: office,
worldwide_organisation_id: office.edition,
}
end
end

private

def create_worldwide_organisation_and_office
Expand Down

0 comments on commit a585bc6

Please sign in to comment.