Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Add a notification when identity is viewed
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed May 12, 2016
1 parent 8335b3b commit e10b9c4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
14 changes: 14 additions & 0 deletions emails/identity-viewed.spt
Original file line number Diff line number Diff line change
@@ -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=('<a href="https://gratipay.com/~{}/">'|safe).format(viewer)
, a_country=('<a href="https://gratipay.com/about/me/identities/{}">'|safe).format(country_code)
, _a='</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
) }}
13 changes: 10 additions & 3 deletions tests/py/test_identity_pages.py
Original file line number Diff line number Diff line change
@@ -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='[email protected]',
claimed_time='now', is_admin=True)
Expand Down Expand Up @@ -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

Expand Down
11 changes: 10 additions & 1 deletion www/~/%username/identities/%country.spt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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']
Expand Down

0 comments on commit e10b9c4

Please sign in to comment.