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

MBS-13719: Enable sending contact emails through new service #3390

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

JadedBlueEyes
Copy link
Contributor

@JadedBlueEyes JadedBlueEyes commented Oct 21, 2024

Problem

This is the start of enabling mb-mail-service incrementally, as a broken-down version of #3363.
This adds the configuration option MAIL_SERVICE_BASE_URL in DBdefs, and replaces send_message_to_editor (aka /user/<id>/contact) with the new template.

Testing

This has been manually tested.

Documenting

Further action

  1. Ensure beta.musicbrainz.org is configured correctly before deploying
  2. Once this has seen some success, enable more new templates
  3. Write replacement tests for the new code

Copy link
Member

@mwiencek mwiencek left a comment

Choose a reason for hiding this comment

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

Thanks for splitting this, I hope we can put it on test/beta soon!

{
my $email = $self->_create_message_to_editor_email(%opts);
$self->_send_email($email);
my $_url = $mail_service_base_url . "/send_single";
Copy link
Member

Choose a reason for hiding this comment

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

May as well use interpolation here since we're already using the double quotes:

Suggested change
my $_url = $mail_service_base_url . "/send_single";
my $_url = "$mail_service_base_url/send_single";

'template_id' => 'editor-message',
'to' => _user_address($to),
'from' => $EMAIL_NOREPLY_ADDRESS,
# 'lang'
Copy link
Member

Choose a reason for hiding this comment

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

Maybe change this to a "TODO" comment saying we'll use a not-yet-added mail language preference here?

Comment on lines +410 to +411
'to_name' => $to -> name,
'from_name' => $from -> name,
Copy link
Member

Choose a reason for hiding this comment

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

small style suggestion for consistency with the rest of our Perl code

Suggested change
'to_name' => $to -> name,
'from_name' => $from -> name,
'to_name' => $to->name,
'from_name' => $from->name,

Please do not respond to this e-mail.
EOF
my $res = $self->c->lwp->request(POST $_url, %$header_params, Content => encode_json($body));
if (! $res->is_success) {
Copy link
Member

Choose a reason for hiding this comment

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

small style suggestion for consistency with the rest of our Perl code

Suggested change
if (! $res->is_success) {
if (!$res->is_success) {

or

Suggested change
if (! $res->is_success) {
unless ($res->is_success) {

EOF
my $res = $self->c->lwp->request(POST $_url, %$header_params, Content => encode_json($body));
if (! $res->is_success) {
print "Failed to send!"
Copy link
Member

Choose a reason for hiding this comment

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

I think we should die here (which will show the user an error page) rather than continue with the send-to-self path. We can also provide some extra details about the failed response:

my $status = $res->status;
die "Failed to send mail ($status):\n" . Dumper($res->content);

This requires importing use Data::Dumper;.


$self->_send_email($copy);
if ($opts{send_to_self}) {
my $self_body = {
Copy link
Member

Choose a reason for hiding this comment

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

It should be fine to just reuse the previous $body:

$body->{to} = _user_address($from);
$body->{params}{is_self_copy} = \1;


my $res = $self->c->lwp->request(POST $_url, %$header_params, Content => encode_json($self_body));
if (! $res->is_success) {
print "Failed to send!"
Copy link
Member

Choose a reason for hiding this comment

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

Same comment re: die above.

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.

2 participants