Skip to content

Loading…

WIP - [Fixed Bug 703316] - Invitation email is impersonal #791

Closed
wants to merge 5 commits into from

3 participants

@jonathan-s

No description provided.

@dpoirier

I think this'll need to be a little more involved, unfortunately. The from address passed to send_mail() is used as the envelope from address, and should be simply an email address. To set the contents of the From header, we won't be able to use the Django send_mail(). Instead, we can construct an EmailMessage and pass it in the headers.

@jonathan-s

I'll take a look at it!

@glogiotatidis glogiotatidis commented on an outdated diff
mozillians/phonebook/models.py
@@ -40,9 +40,10 @@ def send(self, sender=None):
"""
if sender:
+ from_reply = sender.full_name + " via " + settings.FROM_NOREPLY
@glogiotatidis Mozilla member

We use ' instead of " in python code, unless there is a reason not to. Please change this for consistency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@glogiotatidis glogiotatidis commented on an outdated diff
mozillians/phonebook/models.py
@@ -40,9 +40,10 @@ def send(self, sender=None):
"""
if sender:
@glogiotatidis Mozilla member

If there is no sender, then from_reply will not be set and the send_mail will fail. Please add
from_reply = settings.FROM_NOREPLY just above this line to set a default value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@glogiotatidis glogiotatidis commented on an outdated diff
mozillians/templates/phonebook/invite_email.txt
@@ -1,5 +1,7 @@
{% trans sender=sender %}
-Hi there. {{ sender }} has invited you to join mozillians.org,
+Hi there,
@glogiotatidis Mozilla member

Localization tools will strip any newlines in trans blocks, thus this block will be send as a single line.

To keep the formating, break this into multiple blocks like this

{{ _('Hi there') }},

{% trans sender=sender %}
{{ sender }} has invited you to join mozillians.org,
the community directory for Mozilla contributors. You
can create a community profile for yourself and search
for other contributors to learn more about them or get
in touch.
{% endtrans %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@glogiotatidis glogiotatidis commented on an outdated diff
mozillians/templates/phonebook/invite_email.txt
@@ -13,4 +15,7 @@ in touch.
{{ personal_message }}
{% endif %}
-{{ _('Join Mozillians:') }} {{ link }}
+{{ _('Take two minutes to create your mozillians.org profile:') }}
@glogiotatidis Mozilla member

Add an extra blank line before this line to separate the personal message.

Additionally we can add a filter to indent in the contents of personal message so it's more distinguishable.

Try
{{ personal_message|indent(indentfirst=True) }}

@glogiotatidis Mozilla member

nit: you have an extra space at the end of this line. You may want to configure your editor to remove whitespace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@glogiotatidis
Mozilla member

Always use present tense in your commit messages, Fix bug XXX and a message that represents the change.
e.g. [fix bug 703316] Personalize invitation message.

@glogiotatidis
Mozilla member

@jonathan-s thanks for the pull request! I added some comments. You can make the changes and amend to your current commit, so we have only one commit to merge in for this bug.

Feel free to reply here or ping me on mozilla's IRC (giorgos) in #commtools if you have questions and / or new suggestions

@glogiotatidis
Mozilla member

@dpoirier i'm not sure i follow you. from_reply is set just fine here. Here is an example

MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: Please join me on mozillians.org
From: 4979c8ade727d501f345c0dc06eb3277d9bc9be2 via Mozillians  <no-reply@mozillians.org>

can you please elaborate?

@jonathan-s

@glogiotatidis It seems like I'm not entirely friends with git yet. I did an amendment and tried pushing it. Then I got a merge conflict which I resolved, as the merge conflict resolved I got a new commit. Once I had that I tried doing a rebase to squash those commits, but I didn't succeed with that. Oh well.

And Thanks a lot for the comments!!

@glogiotatidis
Mozilla member

I think I know what happened. When you amend, you change git's history. So you'll have to
git push -f to force the push to github, otherwise git will complain.

Do not worry, I'll review your changes (maybe tomorrow) and I'll fix this for you.

Thanks for updating!

@jonathan-s

Thank you! Then I know when to use git push -f the next time!

@jonathan-s

I also tried to find the builtin indent template filter, but I couldn't find it. So I assume it's a customized filter within this project.

@glogiotatidis
Mozilla member

Sorry for not providing a link in the first place. It's a jinja filter (we use jinja instead of django's template engine)

http://jinja.pocoo.org/docs/templates/#indent

@jonathan-s

Ah, then it makes sense! Is there any reason for using jinja instead of Django's own template engine?

@dpoirier

@glogiotatidis apparently I was wrong, Django send_mail is smarter than I thought.

@dpoirier

@jonathan-s I wasn't around when they chose Jinja, but it's often considered more flexible and faster than Django's own template engine. (I'm not sure how much the "faster" part is true anymore.)

@dpoirier dpoirier commented on an outdated diff
mozillians/templates/phonebook/invite_email.txt
((3 lines not shown))
{% trans sender=sender %}
-Hi there. {{ sender }} has invited you to join mozillians.org,
+{{ sender }} has invited you to join mozillians.org,
@dpoirier
dpoirier added a note

The bug suggested this paragraph start:

_Inviter's full name_ (_inviter's email address_) has invited you to join mozillians.org, the community directory for Mozilla contributors.

Even if {{ sender }} happens to get rendered that way, it would probably be better to format the message explicitly in the template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@dpoirier dpoirier commented on an outdated diff
mozillians/templates/phonebook/invite_email.txt
((6 lines not shown))
{% endif %}
-{{ _('Join Mozillians:') }} {{ link }}
+{{ _('Take two minutes to create your mozillians.org profile:') }}
+{{ link }}
+
+{{ _('Thanks for contributing to Mozilla') }} :)
@dpoirier
dpoirier added a note

Period at the end of this sentence?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@glogiotatidis
Mozilla member

hey @jonathan-s. sorry for the multiday delay. Do you feel comfortable to go ahead with the changes Dan suggests and also create a test to verify that everything works as expected?

If the test is over your head, I'm happy to do that for you. Let me know.

Thanks!

@glogiotatidis
Mozilla member

hey @jonathan-s . no pressure, I'm just checking in to say that if you're stuck I'm happy to help :)

@jonathan-s

Hi @glogiotatidis, well the thing I am stuck with is getting that 'gettext' thing to work properly on my computer. That's the one thing that gives me errors and sort of prevents me from going further so to speak.

@glogiotatidis
Mozilla member

Sorry to hear that @jonathan-s. How do you like to move on with this? Would you like to try settings up debian / ubuntu on a virtualbox? Alternatively I can finish this off for you and you go ahead with another bug?

It would be great that you continue to work on mozillians, I don't want a stupid installation issue to hold you back :(

Would you consider the following solution: coding locally but testing your code to a remote dev environment built for you?

@jonathan-s

It sounds like a good idea to set up a virtualbox with ubuntu / debian. That would probably help in the long run. Although I'd need some help doing that.

@glogiotatidis
Mozilla member

OK let's move forward with this. There're plenty of guides online on how to install ubuntu on virtualbox and as always if you get stuck feel free to ping us. :)

@jonathan-s

l box with ubuntu on it. But instead it throws an error when I try to create a user through the UserFactory, traceback here: http://pastebin.mozilla.org/4517668 any pointers perchance giorgos?

@glogiotatidis
Mozilla member

The error you see it's related to ElasticSearch. Read step 7 here http://mozillians.readthedocs.org/en/latest/installation-virtualenv.html

You'll have to run ELasticSearch on every boot of your VM

Let me know if that helps.

@glogiotatidis glogiotatidis changed the title from [Fixed Bug 703316] - Invitation email is impersonal to WIP - [Fixed Bug 703316] - Invitation email is impersonal
@glogiotatidis
Mozilla member

Closing due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
14 mozillians/phonebook/models.py
@@ -38,24 +38,30 @@ def send(self, sender=None):
Includes the name and email of the inviting person, if
available.
+ sender is a user.userprofile
"""
+ from_reply = settings.FROM_NOREPLY
+
if sender:
- sender = '%s (%s)' % (sender.full_name, sender.user.email)
+ from_reply = sender.full_name + ' via ' + settings.FROM_NOREPLY
+ full_name = sender.full_name
+ email_in_brackets = "(" + sender.user.email + ")"
- subject = _('Become a Mozillian')
+ subject = _('Please join me on mozillians.org')
template = get_template('phonebook/invite_email.txt')
message = template.render({
'personal_message': self.message,
- 'sender': sender or _('A fellow Mozillian'),
+ 'full_name': full_name or _('A fellow Mozillian'),
+ 'email_in_brackets': email_in_brackets,
'link': self.get_url()})
# Manually replace quotes and double-quotes as these get
# escaped by the template and this makes the message look bad.
filtered_message = message.replace('&#34;', '"').replace('&#39;', "'")
- send_mail(subject, filtered_message, settings.FROM_NOREPLY,
+ send_mail(subject, filtered_message, from_reply,
[self.recipient])
def send_thanks(self):
View
38 mozillians/phonebook/tests/test_models.py
@@ -0,0 +1,38 @@
+from mock import Mock
+
+from django.template.loader import get_template
+from django.core import mail
+
+from mozillians.common.tests import TestCase
+from mozillians.phonebook.tests import InviteFactory
+from mozillians.users.tests import UserFactory
+from mozillians.phonebook.models import Invite
+
+
+
+"""for the tests, I'd mock send_mail and check the everything
+is as expected, morinonaka"""
+
+class InviteTests(TestCase):
+
+ def setUp(self):
+ pass
+
+# def test_invite_template_exists(self):
+# template = get_template('phonebook/invite_email.txt')
+
+
+ def test_sends_mail_correctly(self):
+ user = UserFactory.create()
+ #invitation = InviteFactory(inviter=user.userprofile)
+
+
+ invitation = Invite(
+ inviter=user.userprofile,
+ recipient='joe@joe.com',
+ message='blank')
+
+ invitation.send(sender=user.userprofile)
+
+ def test_sends_mail_without_userprofile(self):
+ pass
View
11 mozillians/templates/phonebook/invite_email.txt
@@ -1,5 +1,7 @@
+{{ _('Hi there,') }}
+
{% trans sender=sender %}
-Hi there. {{ sender }} has invited you to join mozillians.org,
+{{ full_name }} {{ email_in_brackets }} has invited you to join mozillians.org,
the community directory for Mozilla contributors. You
can create a community profile for yourself and search
for other contributors to learn more about them or get
@@ -10,7 +12,10 @@ in touch.
{{ _('Personal message:') }}
-{{ personal_message }}
+{{ personal_message|indent(indentfirst=True) }}
{% endif %}
-{{ _('Join Mozillians:') }} {{ link }}
+{{ _('Take two minutes to create your mozillians.org profile:') }}
+{{ link }}
+
+{{ _('Thanks for contributing to Mozilla.') }} :)
Something went wrong with that request. Please try again.