From e10b9c4c294c914d997a782440be9ef8654db388 Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Wed, 11 May 2016 21:57:48 -0400 Subject: [PATCH] Add a notification when identity is viewed --- emails/identity-viewed.spt | 14 ++++++++++++++ tests/py/test_identity_pages.py | 13 ++++++++++--- www/~/%username/identities/%country.spt | 11 ++++++++++- 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 emails/identity-viewed.spt diff --git a/emails/identity-viewed.spt b/emails/identity-viewed.spt new file mode 100644 index 0000000000..43dae3dae7 --- /dev/null +++ b/emails/identity-viewed.spt @@ -0,0 +1,14 @@ +{{ _("Identity Viewed") }} +[---] text/html +{{ _( "This is a transactional email to let you know that {a_viewer}{viewer}{_a} viewed your identity information for {a_country}{country_name}{_a} on Gratipay." + , viewer=viewer + , country_name=country_name + , a_viewer=(''|safe).format(viewer) + , a_country=(''|safe).format(country_code) + , _a=''|safe + ) }} +[---] text/plain +{{ _( "This is a transactional email to let you know that {viewer} viewed your identity information for {country_name} on Gratipay." + , viewer=viewer + , country_name=country_name + ) }} diff --git a/tests/py/test_identity_pages.py b/tests/py/test_identity_pages.py index 7aa5f47166..b7b414ba78 100644 --- a/tests/py/test_identity_pages.py +++ b/tests/py/test_identity_pages.py @@ -1,11 +1,14 @@ -from gratipay.testing import Harness +from __future__ import absolute_import, division, print_function, unicode_literals + from gratipay.models.country import Country from gratipay.models.participant import Participant +from gratipay.testing.emails import EmailHarness -class Tests(Harness): +class Tests(EmailHarness): def setUp(self): + super(Tests, self).setUp() self.make_participant('alice', claimed_time='now', is_admin=True) self.make_participant('whit537', id=1451, email_address='chad@zetaweb.com', claimed_time='now', is_admin=True) @@ -57,9 +60,13 @@ def test_ip_is_200_for_self(self): def test_ip_is_403_for_most_admins(self): assert self.client.GxT('/~bob/identities/TT', auth_as='alice').code == 403 - def test_ip_is_200_for_whit537_yikes(self): + def test_ip_is_200_for_whit537_yikes_O_O(self): assert self.client.GET('/~bob/identities/TT', auth_as='whit537').code == 200 + def test_ip_notifies_participant_when_whit537_views(self): + self.client.GET('/~bob/identities/TT', auth_as='whit537') + assert 'whit537 viewed your identity' in self.get_last_email()['body_text'] + def test_ip_is_404_for_unknown_code(self): assert self.client.GxT('/~bob/identities/XX', auth_as='bob').code == 404 diff --git a/www/~/%username/identities/%country.spt b/www/~/%username/identities/%country.spt index 85c0c75d1e..ce83d7a9b4 100644 --- a/www/~/%username/identities/%country.spt +++ b/www/~/%username/identities/%country.spt @@ -18,7 +18,7 @@ if not participant.email_address: # load country country_code = request.path['country'] country = Country.from_code(country_code) -title = locale.countries.get(country_code) +title = country_name = locale.countries.get(country_code) if country is None or title is None: raise Response(404) @@ -35,6 +35,15 @@ for _identity in identities: if identity is None and nidentities >= 3: website.redirect('./', base_url='') # Not allowed to add any more! +# notify users whenever someone views their info +if identity is not None and participant != user.participant: + participant.send_email( 'identity-viewed' + , viewer=user.participant.username + , country_name=country_name + , country_code=country.code + , include_unsubscribe=False + ) + # handle POST requests if request.method == 'POST': action = request.body['action']