forked from alphagov/e-petitions
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add base infrastructure for switch to using GOV.UK Notify
- Loading branch information
Showing
58 changed files
with
2,324 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
cy-GB: | ||
notify: | ||
templates: | ||
email_confirmation_for_signer: "de60bc30-2d7b-4a71-851f-0ac357af048f" | ||
email_creator_about_other_business: "86b5dee8-ca22-45be-af00-d74d601e656d" | ||
email_duplicate_signatures: "8d63e92e-1591-420d-a8ec-1df6ecf6a34c" | ||
email_signer_about_other_business: "5aa3434b-0530-4655-a2d2-318fd3668568" | ||
gather_sponsors_for_petition_christmas: "6c9730a2-e31d-4c15-9c05-e96ef5cb8ff4" | ||
gather_sponsors_for_petition_easter: "5920b765-6921-4537-9e01-d8b1338b1071" | ||
gather_sponsors_for_petition_moderation_delay: "fb8c5cee-8fb1-46f3-8818-58f3c4311c2b" | ||
gather_sponsors_for_petition: "1a52a93e-808a-4ce4-9b24-2d165aaaef4b" | ||
notify_creator_of_debate_scheduled: "0e81b36b-9e52-445c-8984-0ee9d89399fe" | ||
notify_creator_of_negative_debate_outcome: "3e283d4a-7b74-4a96-8431-857e3b3bfc89" | ||
notify_creator_of_positive_debate_outcome: "4bda6753-3639-4bad-94a2-b1b1596222b9" | ||
notify_creator_that_petition_is_published: "2d864e9a-275b-41ea-90c9-92b93da8c48a" | ||
notify_creator_that_petition_was_rejected_hidden: "59dad299-5c03-48b9-be2b-37b90a7701fe" | ||
notify_creator_that_petition_was_rejected: "71d0736e-ff45-43d5-b083-c78f04d2b02c" | ||
notify_signer_of_debate_scheduled: "939413df-ec0d-4898-acb2-46a63ea3d42f" | ||
notify_signer_of_negative_debate_outcome: "d97d154f-cdb8-4273-b6cb-d5f89479efba" | ||
notify_signer_of_positive_debate_outcome: "61cd5971-7bc7-4a1e-b30b-d799a36bff5c" | ||
notify_sponsor_that_petition_is_published: "46f90a8f-eb76-4ed7-b24f-c657560c5c41" | ||
notify_sponsor_that_petition_was_rejected_hidden: "cf28ed24-3710-4843-bc35-0ec157adb9ca" | ||
notify_sponsor_that_petition_was_rejected: "9bcdcefd-60a3-4698-85c7-5b4246745b43" | ||
petition_and_email_confirmation_for_sponsor: "f10ca6dd-4f07-479c-a588-a3abbafe2c55" | ||
sponsor_signed_email_below_threshold: "29b774ac-7852-4657-9b7d-c0395e7f890c" | ||
sponsor_signed_email_on_threshold_christmas: "50d84545-2438-478d-9838-d61fc2467efd" | ||
sponsor_signed_email_on_threshold_easter: "fffa81d1-0625-44a1-af7b-780dd27a7719" | ||
sponsor_signed_email_on_threshold: "8766cdb6-19cb-4eab-a2ba-1af7643f66ee" | ||
|
||
strings: | ||
sponsor_count: | ||
zero: "Mae gennych chi 0 gefnogwr hyd yn hyn" | ||
one: "Mae gennych chi 1 cefnogwr hyd yn hyn" | ||
two: "Mae gennych chi 2 gefnogwr hyd yn hyn" | ||
other: "Mae gennych chi %{count} chefnogwr hyd yn hyn" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
en-GB: | ||
notify: | ||
templates: | ||
email_confirmation_for_signer: "a33e91d1-808a-4a85-abcc-8a4c62266789" | ||
email_creator_about_other_business: "5b75b985-fc6e-4473-8b51-0958818bea63" | ||
email_duplicate_signatures: "e4beb5af-0db1-406b-9c03-a8c8b65f27fd" | ||
email_signer_about_other_business: "fdc05cf0-81d1-4a28-933c-65b8e10666dd" | ||
gather_sponsors_for_petition_christmas: "f7965a34-6f8e-4aa3-97fe-51e8f465d264" | ||
gather_sponsors_for_petition_easter: "ed21ff1d-b718-4cef-9491-451f443f9a1d" | ||
gather_sponsors_for_petition_moderation_delay: "c93ca86b-b508-417c-a4b5-28ec33047b2e" | ||
gather_sponsors_for_petition: "7e098470-4a73-435c-bd8c-9f0d9d9ba010" | ||
notify_creator_of_debate_scheduled: "085e81e4-5ced-4cfe-b142-a03f8b5ffb08" | ||
notify_creator_of_negative_debate_outcome: "41021e4a-70d7-43ec-b98e-14ca5e8e0835" | ||
notify_creator_of_positive_debate_outcome: "929f4523-ee7d-4895-a9e5-32f9fff0c41a" | ||
notify_creator_that_petition_is_published: "dc337901-65b0-4e76-b1d5-b14b90e7ee3e" | ||
notify_creator_that_petition_was_rejected_hidden: "0e9af1c3-17b2-4af6-9440-5fce1f5eb7bb" | ||
notify_creator_that_petition_was_rejected: "262dc874-cba2-4aef-888d-b6fcd23401a8" | ||
notify_signer_of_debate_scheduled: "824662f6-2cb1-4da8-b65d-6b071c569d0e" | ||
notify_signer_of_negative_debate_outcome: "865e3a66-6b98-406d-8883-04dd7d35a580" | ||
notify_signer_of_positive_debate_outcome: "4254e36c-b0bc-48ad-9a8c-62d59d16d0ce" | ||
notify_sponsor_that_petition_is_published: "a8557cbf-a889-4392-88a1-988634169d69" | ||
notify_sponsor_that_petition_was_rejected_hidden: "69e7f6e1-da4c-4b1e-95d5-e687a62c2cc7" | ||
notify_sponsor_that_petition_was_rejected: "0a9de360-8eab-4e81-946b-7fe2146b6b1e" | ||
petition_and_email_confirmation_for_sponsor: "0f912b39-37e2-4de0-886a-28c3e529d139" | ||
sponsor_signed_email_below_threshold: "32eabf04-06e7-4e80-9be4-f425321419c1" | ||
sponsor_signed_email_on_threshold_christmas: "f6ea7df0-9cb1-4895-941a-183ddd0e79db" | ||
sponsor_signed_email_on_threshold_easter: "6fbe2afa-0ee5-4dec-adab-1a7518cbee33" | ||
sponsor_signed_email_on_threshold: "b0bbd8f3-ad81-4095-a01d-68d979775418" | ||
|
||
strings: | ||
sponsor_count: | ||
zero: "You have 0 supporters so far" | ||
one: "You have 1 supporter so far" | ||
two: "You have 2 supporters so far" | ||
other: "You have %{count} supporters so far" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
module NotifyMock | ||
URL = "https://api.notifications.service.gov.uk/v2/notifications/email" | ||
|
||
APPLICATION = Module.new do | ||
class << self | ||
include MarkdownHelper | ||
|
||
def call(env) | ||
params = JSON.parse(env["rack.input"].read) | ||
template = templates.fetch(params["template_id"]) | ||
|
||
message = Mail::Message.new | ||
subject = template["subject"].dup | ||
body = template["body"].dup | ||
|
||
params["personalisation"].each do |key, value| | ||
subject.gsub!("((#{key}))", value.to_s) | ||
body.gsub!("((#{key}))", value.to_s) | ||
end | ||
|
||
text_part = markdown_to_text(body) | ||
html_part = markdown_to_html(body) | ||
|
||
message.message_id = "#{SecureRandom.uuid}@#{Site.host}" | ||
message.from = Site.email_from | ||
message.to = params["email_address"] | ||
message.subject = subject | ||
message.text_part = text_part | ||
message.html_part = html_part | ||
|
||
ActionMailer::Base.deliveries << message | ||
|
||
[ 200, { "Content-Type" => "application/json" }, ["{}"] ] | ||
end | ||
|
||
private | ||
|
||
def templates | ||
@templates ||= load_templates | ||
end | ||
|
||
def load_templates | ||
template_files.each_with_object({}) do |file, hash| | ||
hash[File.basename(file, ".yml")] = YAML.load_file(file) | ||
end | ||
end | ||
|
||
def template_files | ||
Dir["#{template_dir}/*.yml"] | ||
end | ||
|
||
def template_dir | ||
Rails.root.join("spec", "fixtures", "notify") | ||
end | ||
end | ||
end | ||
|
||
class << self | ||
def url | ||
URL | ||
end | ||
|
||
def app | ||
APPLICATION | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require "notifications/client" | ||
require "fileutils" | ||
|
||
namespace :notify do | ||
task fetch_templates: :environment do | ||
template_dir = Rails.root.join("spec", "fixtures", "notify") | ||
client = Notifications::Client.new(ENV.fetch("NOTIFY_API_KEY")) | ||
templates = client.get_all_templates(type: "email") | ||
|
||
FileUtils.rm_rf template_dir | ||
FileUtils.mkdir_p template_dir | ||
|
||
templates.collection.each do |template| | ||
template_path = template_dir.join("#{template.id}.yml") | ||
|
||
yaml = <<~YAML | ||
id: "#{template.id}" | ||
name: "#{template.name}" | ||
subject: "#{template.subject}" | ||
body: |- | ||
#{template.body.split("\r\n").map { |l| " #{l}" }.join("\n")} | ||
YAML | ||
|
||
File.write(template_path, yaml) | ||
end | ||
rescue Notifications::Client::RequestError => e | ||
puts e.message | ||
end | ||
end |
39 changes: 39 additions & 0 deletions
39
spec/fixtures/notify/085e81e4-5ced-4cfe-b142-a03f8b5ffb08.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
id: "085e81e4-5ced-4cfe-b142-a03f8b5ffb08" | ||
name: "notify_creator_of_debate_scheduled_en" | ||
subject: "Senedd will debate “((action_en))” | Bydd y Senedd yn trafod “((action_cy))”" | ||
body: |- | ||
Dear ((name)), | ||
Senedd is going to debate your petition – “((action_en))”. | ||
((petition_url_en)) | ||
The debate is scheduled for ((debate_date_en)). | ||
Once the debate has happened, we’ll email you a video and transcript. | ||
Thanks, | ||
The Petitions team | ||
Senedd | ||
You’re receiving this email because you created this petition: “((action_en))”. | ||
To unsubscribe from getting emails about this petition: ((unsubscribe_url_en)) | ||
--- | ||
Annwyl ((name)), | ||
Mae'r Senedd yn mynd i drafod eich deiseb - “((action_cy))”. | ||
((petition_url_cy)) | ||
Mae'r ddadl wedi'i hamserlennu ar gyfer ((debate_date_cy)). | ||
Ar ôl i'r ddadl ddigwydd, byddwn yn e-bostio fideo a thrawsgrifiad atoch. | ||
Diolch, | ||
Tîm Deisebau | ||
Y Senedd | ||
Rydych chi'n derbyn yr e-bost hwn oherwydd i chi greu'r ddeiseb hon: “((action_cy))”. | ||
Dad-danysgrifio rhag cael negeseuon e-bost am y ddeiseb hon: ((unsubscribe_url_cy)) |
45 changes: 45 additions & 0 deletions
45
spec/fixtures/notify/0a9de360-8eab-4e81-946b-7fe2146b6b1e.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
id: "0a9de360-8eab-4e81-946b-7fe2146b6b1e" | ||
name: "notify_sponsor_that_petition_was_rejected_en" | ||
subject: "We rejected the petition “((action))” that you supported | Gwrthodwyd y ddeiseb “((action))” y gwnaethoch chi ei chefnogi" | ||
body: |- | ||
Dear ((sponsor)), | ||
Thank you for supporting a petition. | ||
Before we can publish a petition on our website and it can begin to collect signatures, we need to ensure that it meets the petition rules. | ||
Unfortunately, we are not able to accept the proposed petition “((action))”. | ||
((content_en)) | ||
Click this link to see the rejected petition: | ||
((url_en)) | ||
We only reject petitions that don’t meet the petition standards: | ||
((standards_url_en)) | ||
Thanks, | ||
The Petitions team | ||
Senedd | ||
--- | ||
Annwyl ((sponsor)), | ||
Diolch am gefnogi deiseb. | ||
Cyn cyhoeddi deiseb ar ein gwefan a dechrau casglu llofnodion, mae angen i ni sicrhau ei bod yn bodloni’r rheolau ar gyfer deisebau. | ||
Yn anffodus, ni allwn dderbyn y ddeiseb a gynigiwyd “((action))”. | ||
((content_cy)) | ||
Cliciwch ar y linc i weld y ddeiseb a wrthodwyd: | ||
((url_cy)) | ||
Dim ond deisebau nad ydynt yn bodloni'r safonau y byddwn yn eu gwrthod: | ||
((standards_url_cy)) | ||
Diolch, | ||
Tîm Deisebau | ||
Y Senedd |
39 changes: 39 additions & 0 deletions
39
spec/fixtures/notify/0e81b36b-9e52-445c-8984-0ee9d89399fe.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
id: "0e81b36b-9e52-445c-8984-0ee9d89399fe" | ||
name: "notify_creator_of_debate_scheduled_cy" | ||
subject: "Bydd y Senedd yn trafod “((action_cy))” | Senedd will debate “((action_en))”" | ||
body: |- | ||
Annwyl ((name)), | ||
Mae'r Senedd yn mynd i drafod eich deiseb - “((action_cy))”. | ||
((petition_url_cy)) | ||
Mae'r ddadl wedi'i hamserlennu ar gyfer ((debate_date_cy)). | ||
Ar ôl i'r ddadl ddigwydd, byddwn yn e-bostio fideo a thrawsgrifiad atoch. | ||
Diolch, | ||
Tîm Deisebau | ||
Y Senedd | ||
Rydych chi'n derbyn yr e-bost hwn oherwydd i chi greu'r ddeiseb hon: “((action_cy))”. | ||
Dad-danysgrifio rhag cael negeseuon e-bost am y ddeiseb hon: ((unsubscribe_url_cy)) | ||
--- | ||
Dear ((name)), | ||
Senedd is going to debate your petition – “((action_en))”. | ||
((petition_url_en)) | ||
The debate is scheduled for ((debate_date_en)). | ||
Once the debate has happened, we’ll email you a video and transcript. | ||
Thanks, | ||
The Petitions team | ||
Senedd | ||
You’re receiving this email because you created this petition: “((action_en))”. | ||
To unsubscribe from getting emails about this petition: ((unsubscribe_url_en)) |
49 changes: 49 additions & 0 deletions
49
spec/fixtures/notify/0e9af1c3-17b2-4af6-9440-5fce1f5eb7bb.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
id: "0e9af1c3-17b2-4af6-9440-5fce1f5eb7bb" | ||
name: "notify_creator_that_petition_was_rejected_hidden_en" | ||
subject: "We rejected your petition “((action))” | Gwrthodwyd eich deiseb “((action))”" | ||
body: |- | ||
Dear ((creator)), | ||
Thank you for submitting a petition to the Senedd. | ||
Before we can publish a petition on our website and it can begin to collect signatures, we need to ensure that it meets the petition rules. | ||
Unfortunately, we are not able to accept your proposed petition “((action))”. | ||
((content_en)) | ||
We only reject petitions that don’t meet the petition standards: | ||
((standards_url_en)) | ||
If you want to try again, click here to start a petition: | ||
((new_petition_url_en)) | ||
We’re sorry that we’re not able to take your petition forward on this occasion. | ||
Thanks, | ||
The Petitions team | ||
Senedd | ||
--- | ||
Annwyl ((creator)), | ||
Diolch am gyflwyno deiseb i'r Senedd. | ||
Cyn cyhoeddi deiseb ar ein gwefan a dechrau casglu llofnodion, mae angen i ni sicrhau ei bod yn bodloni’r rheolau ar gyfer deisebau. | ||
Yn anffodus, ni allwn dderbyn y ddeiseb a gynigiwyd gennych “((action))”. | ||
((content_cy)) | ||
Dim ond deisebau nad ydynt yn bodloni'r safonau y byddwn yn eu gwrthod: | ||
((standards_url_cy)) | ||
Os hoffech roi cynnig arall arni, cliciwch yma i ddechrau deiseb: | ||
((new_petition_url_cy)) | ||
Mae'n ddrwg gennym na allwn fwrw ymlaen â'ch deiseb y tro hwn. | ||
Diolch, | ||
Tîm Deisebau | ||
Y Senedd |
33 changes: 33 additions & 0 deletions
33
spec/fixtures/notify/0f912b39-37e2-4de0-886a-28c3e529d139.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
id: "0f912b39-37e2-4de0-886a-28c3e529d139" | ||
name: "petition_and_email_confirmation_for_sponsor_en" | ||
subject: "Please confirm your email address | Cadarnhewch eich cyfeiriad e-bost" | ||
body: |- | ||
Click this link to sign the petition: | ||
((url_en)) | ||
((creator))’s petition: | ||
# ((action)) | ||
((content)) | ||
Thanks, | ||
The Petitions team | ||
Senedd | ||
--- | ||
Cliciwch ar y linc i lofnodi’r ddeiseb: | ||
((url_cy)) | ||
Deiseb ((creator)) | ||
# ((action)) | ||
((content)) | ||
Diolch, | ||
Tîm Deisebau | ||
Y Senedd |
Oops, something went wrong.