Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bucks] Add email alternative to templates #4001

Merged

Conversation

MorayMySoc
Copy link
Contributor

@MorayMySoc MorayMySoc commented Jul 4, 2022

  • Adds setting to allow email alternative text to be added
  • Filters out alerts that need to send the email text from general alerts of added comments
  • Update database with new fields
  • Create email templates for email template text
  • Updates documentation to include template email text

https:/mysociety/societyworks/issues/2817

@codecov
Copy link

codecov bot commented Jul 4, 2022

Codecov Report

Merging #4001 (297465d) into master (edec516) will decrease coverage by 9.12%.
The diff coverage is n/a.

❗ Current head 297465d differs from pull request most recent head 6d2795b. Consider uploading reports for the commit 6d2795b to get more accurate results

@@            Coverage Diff             @@
##           master    #4001      +/-   ##
==========================================
- Coverage   82.82%   73.69%   -9.13%     
==========================================
  Files         362       55     -307     
  Lines       25270     4760   -20510     
  Branches     3809        0    -3809     
==========================================
- Hits        20929     3508   -17421     
+ Misses       3154     1252    -1902     
+ Partials     1187        0    -1187     
Impacted Files Coverage Δ
...llib/FixMyStreet/App/Controller/Admin/Templates.pm
perllib/FixMyStreet/DB/Result/Comment.pm
perllib/FixMyStreet/DB/Result/ResponseTemplate.pm
perllib/FixMyStreet/Queue/Item/Report.pm
perllib/FixMyStreet/Script/Alerts.pm
perllib/FixMyStreet/Template.pm
perllib/Open311/UpdatesBase.pm
perllib/Utils.pm
perllib/FixMyStreet/App/Form/Wizard.pm
perllib/FixMyStreet/Cobrand/EastSussex.pm
... and 297 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@MorayMySoc MorayMySoc requested review from chrismytton and removed request for chrismytton July 4, 2022 14:55
Copy link
Member

@chrismytton chrismytton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Moray, this is looking really good! Sorry it's taken more so long to review this, I'm not familiar with the updates/alert sending code, so had to do some background research in order to review this properly!

I wonder if this could potentially be simplified by adding an email_text column to the comment table, rather than storing it as extra metadata. That way you wouldn't need to mess around with the RABX to get the email text back out. What do you think?

A few other things:

  1. I'm not 100% convinced the template_email_alternative feature flag is needed. Is this just so other cobrand admins don't get surprised by an extra field on the response templates page?
  2. What's the advantage of the use_template_email column on the response templates, rather than just checking to see if there is an email template and using that if present?
  3. Why is the new templated_email_alert-update needed? Looks like you could change the item_text to use the email text in the same place that we're adding the "State changed to:" text (see code below) then you wouldn't need a separate email template.

if ($row->{is_new_update}) {
# this might throw up the odd false positive but only in cases where the
# state has changed and there was already update text
if ($row->{item_problem_state} && $last_problem_state ne $row->{item_problem_state}) {
my $state = FixMyStreet::DB->resultset("State")->display($row->{item_problem_state}, 1, $cobrand->moniker);
my $update = _('State changed to:') . ' ' . $state;
$row->{item_text} = $row->{item_text} ? $row->{item_text} . "\n\n" . $update :
$update;
$last_problem_state = $row->{item_problem_state};
}
next unless $row->{item_text};
}

@mysociety-pusher mysociety-pusher force-pushed the 2817-bucks-add-email-alternative-to-templates branch from d005224 to c534a77 Compare July 15, 2022 10:40
@MorayMySoc
Copy link
Contributor Author

I've added an email_text column to the comments and removed the extra_data stuff. I've also removed the cobrand specifics. I have left the separate template in as I think that it is a different style of email as we discussed, but happy to reconsider. Also added that these emails should go to the reporter and any subscriber should continue to receive the subscription list - which I think is working. Added a test which makes me think it it anyway!

Copy link
Member

@chrismytton chrismytton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely getting closer! I've left a couple of comments inline, as well as the query below about updates to the Perl DB models.


This seems to be missing the changes from db/rerun_dbic_loader.pl which adds the columns to perllib/FixMyStreet/DB/Result/Comment.pm and perllib/FixMyStreet/DB/Result/ResponseTemplate.pm. When you run that command it will generate a lot of extraneous fluff, you just need the bits adding the columns, as per the following:

diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm
index b7af66505..61b17ade7 100644
--- a/perllib/FixMyStreet/DB/Result/Comment.pm
+++ b/perllib/FixMyStreet/DB/Result/Comment.pm
@@ -72,6 +72,8 @@ __PACKAGE__->add_columns(
   { data_type => "timestamp", is_nullable => 1 },
   "send_state",
   { data_type => "text", default_value => "unprocessed", is_nullable => 0 },
+  "private_email_text",
+  { data_type => "text", is_nullable => 1 },
 );
 __PACKAGE__->set_primary_key("id");
 __PACKAGE__->has_many(
diff --git a/perllib/FixMyStreet/DB/Result/ResponseTemplate.pm b/perllib/FixMyStreet/DB/Result/ResponseTemplate.pm
index 7d6dfe29f..768013510 100644
--- a/perllib/FixMyStreet/DB/Result/ResponseTemplate.pm
+++ b/perllib/FixMyStreet/DB/Result/ResponseTemplate.pm
@@ -41,6 +41,8 @@ __PACKAGE__->add_columns(
   { data_type => "text", is_nullable => 1 },
   "external_status_code",
   { data_type => "text", is_nullable => 1 },
+  "email_text",
+  { data_type => "text", is_nullable => 1 },
 );
 __PACKAGE__->set_primary_key("id");
 __PACKAGE__->add_unique_constraint("response_templates_body_id_title_key", ["body_id", "title"]);

templates/web/base/admin/templates/edit.html Outdated Show resolved Hide resolved
perllib/FixMyStreet/Script/Alerts.pm Outdated Show resolved Hide resolved
perllib/Open311/UpdatesBase.pm Outdated Show resolved Hide resolved
templates/email/default/templated_email_alert-update.html Outdated Show resolved Hide resolved
templates/email/default/templated_email_alert-update.txt Outdated Show resolved Hide resolved
@chrismytton
Copy link
Member

Oh and I think rebasing this branch onto lastest master should hopefully fix the test failures!

@mysociety-pusher mysociety-pusher force-pushed the 2817-bucks-add-email-alternative-to-templates branch from c534a77 to ddf7409 Compare July 25, 2022 16:46
Copy link
Member

@chrismytton chrismytton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! 👍

Let's get this change on staging and see what the client thinks 🙂

@MorayMySoc MorayMySoc requested a review from dracos August 3, 2022 16:18
@MorayMySoc
Copy link
Contributor Author

@dracos This latest commit to answer feedback on the FD ticket

Copy link
Member

@dracos dracos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments, hopefully nothing major.

I should note that in FD, they have said "If Text is blank and text for email alert is populated, then we don't publish anything online but we do send an email to the customer" - whilst the rest of what they say is correct (for only Text, or both present), I don't believe this part is currently the functionality, and no-one has gone back to point this out, which will need doing. If text is blank, the template won't be used at all, as far as I can tell - if the admin allows blank text to be submitted, presumably that should be fixed.

CHANGELOG.md Outdated Show resolved Hide resolved
bin/update-schema Outdated Show resolved Hide resolved
perllib/Open311/UpdatesBase.pm Outdated Show resolved Hide resolved
perllib/Open311/UpdatesBase.pm Outdated Show resolved Hide resolved
templates/email/default/templated_email_alert-update.txt Outdated Show resolved Hide resolved
templates/email/default/templated_email_alert-update.html Outdated Show resolved Hide resolved
perllib/FixMyStreet/Script/Alerts.pm Outdated Show resolved Hide resolved
perllib/FixMyStreet/Script/Alerts.pm Show resolved Hide resolved
perllib/FixMyStreet/Script/Alerts.pm Outdated Show resolved Hide resolved
@dracos dracos force-pushed the 2817-bucks-add-email-alternative-to-templates branch 4 times, most recently from d5b0174 to 6c2d86e Compare August 4, 2022 16:38
@MorayMySoc MorayMySoc requested a review from dracos August 5, 2022 10:08
Copy link
Member

@dracos dracos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of small issues is all.

perllib/Open311/UpdatesBase.pm Outdated Show resolved Hide resolved
@MorayMySoc MorayMySoc requested a review from dracos August 5, 2022 10:56
Copy link
Member

@dracos dracos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good :)

@mysociety-pusher mysociety-pusher force-pushed the 2817-bucks-add-email-alternative-to-templates branch from bdc9015 to 4951f17 Compare August 5, 2022 13:22
@MorayMySoc MorayMySoc requested a review from dracos August 15, 2022 11:53
Copy link
Member

@dracos dracos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of tiny suggestions

t/app/controller/report_new_update.t Outdated Show resolved Hide resolved
templates/web/base/admin/list_updates.html Outdated Show resolved Hide resolved
templates/web/base/admin/list_updates.html Outdated Show resolved Hide resolved
@MorayMySoc MorayMySoc requested a review from dracos August 15, 2022 14:28
@MorayMySoc MorayMySoc requested a review from dracos August 16, 2022 12:03
@mysociety-pusher mysociety-pusher force-pushed the 2817-bucks-add-email-alternative-to-templates branch from f7200d5 to 92a8567 Compare August 16, 2022 12:20
* Adds setting to allow email alternative text to be added
* Filters out alerts that need to send the private email text
from general alerts of added comments
* Update database with new fields
* Create private email templates
* Updates documentation to include the feature
@mysociety-pusher mysociety-pusher force-pushed the 2817-bucks-add-email-alternative-to-templates branch from 92a8567 to 6d2795b Compare August 16, 2022 12:53
@mysociety-pusher mysociety-pusher merged commit 6d2795b into master Aug 16, 2022
@github-pages github-pages bot temporarily deployed to github-pages August 16, 2022 13:10 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants