Skip to content

Commit

Permalink
Update InfoRequest#recipient_name_and_email
Browse files Browse the repository at this point in the history
Handle when authorities don't have valid email addresses. In this case
just return the recipients name.

Fixes #7693
  • Loading branch information
gbp committed Apr 15, 2024
1 parent edfc84d commit 8fc8a0e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
18 changes: 11 additions & 7 deletions app/models/info_request.rb
Expand Up @@ -1265,13 +1265,17 @@ def recipient_email_valid_for_followup?
end

def recipient_name_and_email
MailHandler.address_from_name_and_email(
# TRANSLATORS: Please don't use double quotes (") in this translation
# or it will break the site's ability to send emails to authorities!
_("{{law_used_short}} requests at {{public_body}}",
law_used_short: legislation,
public_body: public_body.short_or_long_name),
recipient_email)
# TRANSLATORS: Please don't use double quotes (") in this translation
# or it will break the site's ability to send emails to authorities!
recipient_name = _("{{law_used_short}} requests at {{public_body}}",
law_used_short: legislation,
public_body: public_body.short_or_long_name)

if MySociety::Validate.is_valid_email(recipient_email)
MailHandler.address_from_name_and_email(recipient_name, recipient_email)
else
recipient_name
end
end

def public_response_events
Expand Down
1 change: 1 addition & 0 deletions doc/CHANGES.md
Expand Up @@ -2,6 +2,7 @@

## Highlighted Features

* Fix admin error when authority are missing an email address (Graeme Porteous)
* Allow categories to have notes associated with them (Graeme Porteous)
* Add styling option and rich text editor to the notes admin (Graeme Porteous)
* Strengthen 2FA warning. Users *must* remember to keep this code safe (Gareth
Expand Down
6 changes: 6 additions & 0 deletions spec/models/info_request_spec.rb
Expand Up @@ -2393,6 +2393,12 @@
expect(@info_request.recipient_name_and_email).to eq("FOI requests at TGQ <geraldine-requests@localhost>")
end

it "has a invalid email" do
allow(MySociety::Validate).to receive(:is_valid_email).and_return(false)
expect(@info_request.recipient_name_and_email).
to eq("FOI requests at TGQ")
end

it "copes with indexing after item is deleted" do
load_raw_emails_data
IncomingMessage.find_each(&:parse_raw_email!)
Expand Down

0 comments on commit 8fc8a0e

Please sign in to comment.