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

Place email template improvements #120

Merged
merged 8 commits into from
Apr 23, 2018
Merged

Place email template improvements #120

merged 8 commits into from
Apr 23, 2018

Conversation

goldpbear
Copy link
Contributor

@goldpbear goldpbear commented Apr 18, 2018

Addresses #117.
Fixes #121, #122.

Needs to be tested on the staging server before merging
UPDATE: seems to be working on the staging server as expected

Two tweaks to our place email template feature:

  • Support multiple emails in the BCC field
  • Send emails to the BCC recipients even when no main recipient email is provided

Note that the multi-email BCC list is just a CharField (so we lose email validation checks). There might be a better pattern for entering a list of emails, but I didn't turn up anything after a quick search. We may want to research more carefully but since this isn't user-facing it's not a huge deal I think.
We now have a fixed number (5) of EmailFields for BCC addresses.

TODO:

  • Run migrations

Copy link
Member

@modulitos modulitos left a comment

Choose a reason for hiding this comment

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

Just a couple suggestions:

  • Make sure to run manage.py makemigrations to ensure that no migrations are needed
  • Unfortunately our continuous testing setup is broken, so make sure to run the tests locally and ensure that they are all passing
  • Use an array for our bcc_emails field (see comment)

@@ -211,7 +211,7 @@ class PlaceEmailTemplate (TimeStampedModel):
event = models.CharField(max_length=128, choices=EVENT_CHOICES, default='add')
recipient_email_field = models.CharField(max_length=128)
from_email = models.EmailField()
bcc_email = models.EmailField(blank=True, default=None)
bcc_email = models.CharField(max_length=512, blank=True, default=None)
Copy link
Member

Choose a reason for hiding this comment

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

As discussed, can we make this an array of models.EmailField, and rename the field to bcc_emails? It would be a bit cleaner and allow us to retain email validation.

Note that we will have to migrate the email in the existing bcc_email field, if present, and add it to be the first item in the array. We can add this to the migration itself, or we can do this manually, if it is simpler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My guess is it will be simpler to do this manually, since I think we only have one email template in use at the moment.

Copy link
Contributor Author

@goldpbear goldpbear Apr 20, 2018

Choose a reason for hiding this comment

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

I might be missing something, but from what I can tell ArrayField is a Django 1.8+ feature: https://docs.djangoproject.com/en/2.0/ref/contrib/postgres/fields/#arrayfield.

Is there another way to have arrays of fields? Maybe a simpler approach for the time being would be to just hard-code a fixed number of BCC EmailFields, like 5 or so, and we'd just be limited to having 5 BCC emails on our templates.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe a simpler approach for the time being would be to just hard-code a fixed number of BCC EmailFields, like 5 or so, and we'd just be limited to having 5 BCC emails on our templates.

I think that's a reasonable idea :-)

@@ -1256,17 +1260,13 @@ def trigger_emails(self, email_templates, obj):

logger.debug('[EMAIL] Going ahead, no errors')

# If the user didn't provide an email address, then no need to go further.
if not recipient_email:
# If the user didn't provide an email address, or no BCC emails are provided,
Copy link
Contributor

Choose a reason for hiding this comment

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

"or" -> "and"

Copy link
Member

@modulitos modulitos left a comment

Choose a reason for hiding this comment

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

I think we should fix the error handling to provide more feedback, but otherwise this looks good 👍

if not recipient_email:
# If the user didn't provide an email address, or no BCC emails are provided,
# then no need to go further.
if not recipient_email and not bcc_list:
Copy link
Member

Choose a reason for hiding this comment

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

Can we move this check to above the if errors conditional, and add an error to the errors array? It would be more idiomatic with the way we are handling errors in this function instead of returning out of the function without any feedback.

errors.append("No '%s' field found on the place. "
"Be sure to configure the 'notifications.submitter_"
"email_field' property if necessary." % (email_field,))
recipient_email = ""
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps we can add a logger.debug here to clarify that recipient_email was not provided?

Copy link
Member

@modulitos modulitos 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 👍

@goldpbear goldpbear merged commit cb7dc4a into master Apr 23, 2018
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.

Multiple emails in place email template BCC list
3 participants