Skip to content

Commit

Permalink
Don’t send emails for HMCTS content items
Browse files Browse the repository at this point in the history
This commit blocks HMCTS content items from triggering emails. This will be used temporarily whilst HMCTS forms are migrated to GOV.UK to stop them generating emails and will be removed once the migration is complete.
  • Loading branch information
Ruben Arakelyan committed Mar 20, 2018
1 parent 9778cea commit 5dff395
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
9 changes: 9 additions & 0 deletions email_alert_service/models/message_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ def email_alerts_supported?(document)
document_links = document.fetch("links", {})
document_type = document.fetch("document_type")

# Temporarily stop HMCTS-related content items from triggering
# email alerts while their forms are migrated to GOV.UK.
# This will be removed on 21/03/2018.
# This only works if HMCTS is the first organisation, which will
# be the case here.
document_expanded_links = document.fetch("expanded_links", {})
return false if document_expanded_links.dig("organisations", 0, "base_path") ==
"/government/organisations/hm-courts-and-tribunals-service"

contains_supported_attribute?(document_links) \
|| contains_supported_attribute?(document_tags) \
|| whitelisted_document_type?(document_type) \
Expand Down
33 changes: 33 additions & 0 deletions spec/models/message_processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,30 @@
}
end

let(:hmcts_document) do
{
"base_path" => "path/to-doc",
"title" => "Example title",
"document_type" => "example",
"description" => "example description",
"public_updated_at" => "2014-10-06T13:39:19.000+00:00",
"details" => {
"change_history" => change_history,
"tags" => {
"topics" => ["example topic"]
}
},
"expanded_links" => {
"topics" => ["example-topic-uuid"],
"organisations" => [
{
"base_path" => "/government/organisations/hm-courts-and-tribunals-service"
}
]
}
}
end

def email_was_triggered
expect(mock_email_alert).to have_received(:trigger)
end
Expand Down Expand Up @@ -200,6 +224,15 @@ def message_requeued
end
end

context "organisation is HMCTS" do
it "acknowledges but doesn't trigger the email" do
processor.process(hmcts_document.to_json, properties, delivery_info)

email_was_not_triggered
message_acknowledged
end
end

context "has links but is from a blacklisted publishing application" do
before do
good_document["details"] = { "change_history" => change_history }
Expand Down

0 comments on commit 5dff395

Please sign in to comment.