From 67ad75a47ea7e427a6667be1fbdf917db0808575 Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Wed, 8 Feb 2017 14:28:11 -0500 Subject: [PATCH] Shelve work on multiple email support --- js/gratipay/packages.js | 25 +++++++++++------- tests/py/test_www_npm_package.py | 12 +++++++++ tests/ttw/test_package_claiming.py | 21 +++++++++++---- www/on/npm/%package/index.html.spt | 36 +++++++++++++++++++------- www/~/%username/emails/modify.json.spt | 2 +- 5 files changed, 70 insertions(+), 26 deletions(-) diff --git a/js/gratipay/packages.js b/js/gratipay/packages.js index 9edffa7fca..b5a2209754 100644 --- a/js/gratipay/packages.js +++ b/js/gratipay/packages.js @@ -4,27 +4,21 @@ Gratipay.packages.post = function(e) { e.preventDefault(); var $this = $(this); var action = 'add-email-and-claim-package'; - var $inputs = $('input, button'); - var $selection = $('input[name=email]:checked'); - var address = $selection.val(); - var package_id = $selection.parent().parent().data('package-id'); + var package_id = $('input[name=package_id]').val(); + var email = Gratipay.packages.extractEmail(); + var $inputs = $('input, button'); $inputs.prop('disabled', true); $.ajax({ url: '/~' + Gratipay.username + '/emails/modify.json', type: 'POST', - data: {action: action, address: address, package_id: package_id}, + data: {action: action, address: email, package_id: package_id}, dataType: 'json', success: function (msg) { if (msg) { Gratipay.notification(msg, 'success'); } - if (action == 'add-email') { - $('input.add-email').val(''); - setTimeout(function(){ window.location.reload(); }, 3000); - return; - } $inputs.prop('disabled', false); }, error: [ @@ -33,3 +27,14 @@ Gratipay.packages.post = function(e) { ], }); }; + +Gratipay.packages.extractEmail = function() { + var nemails = parseInt($('input[name=nemails]').val(), 10); + var email; + if (nemails === 1) { + email = $('input[name=email]').val(); + } else { + email = $('input[name=email]:checked').val(); + } + return email; +} diff --git a/tests/py/test_www_npm_package.py b/tests/py/test_www_npm_package.py index 51fa907a16..95dd9a6ec2 100644 --- a/tests/py/test_www_npm_package.py +++ b/tests/py/test_www_npm_package.py @@ -18,4 +18,16 @@ def test_auth_gets_send_confirmation_page_from_unclaimed(self): self.make_participant('bob', claimed_time='now') body = self.client.GET('/on/npm/foo/', auth_as='bob').body assert 'npm/foo has not been claimed' in body + assert 'using alice@example.com' in body + + def test_auth_gets_multiple_options_if_present(self): + self.make_package('npm', 'bar', 'Bar', ['alice@example.com', 'alice@example.net']) + self.make_participant('bob', claimed_time='now') + body = self.client.GET('/on/npm/bar/', auth_as='bob').body assert 'with one of these email addresses' in body + + def test_auth_gets_something_if_no_emails(self): + self.make_package('npm', 'bar', 'Bar', []) + self.make_participant('bob', claimed_time='now') + body = self.client.GET('/on/npm/bar/', auth_as='bob').body + assert "didn't find any emails" in body diff --git a/tests/ttw/test_package_claiming.py b/tests/ttw/test_package_claiming.py index 60656c2d13..5f3f755fb3 100644 --- a/tests/ttw/test_package_claiming.py +++ b/tests/ttw/test_package_claiming.py @@ -4,14 +4,25 @@ from gratipay.testing import BrowserHarness -class Tests(BrowserHarness): +class TestSendConfirmationLink(BrowserHarness): - def test_sending_a_confirmation_email_appears_to_work(self): - self.make_package() + def check(self, extra_action=None): self.make_participant('bob', claimed_time='now') self.sign_in('bob') self.visit('/on/npm/foo/') - self.css('input[type=radio]')[0].click() + extra_action() if extra_action else '' self.css('button')[0].click() assert self.has_element('.notification.notification-success', 1) - assert self.has_text('Check alice@example.com for a confirmation email.') + assert self.has_text('Check alice@example.com for a confirmation link.') + + def test_appears_to_work(self): + self.make_package() + self.check() + + def test_works_when_there_are_multiple_addresses(self): + self.make_package(emails=['alice@example.com', 'bob@example.com']) + self.check() + + def test_can_send_to_second_email(self): + self.make_package(emails=['bob@example.com', 'alice@example.com']) + self.check(extra_action=lambda: self.css('input[type=radio]')[1].click()) diff --git a/www/on/npm/%package/index.html.spt b/www/on/npm/%package/index.html.spt index b97a787f9b..d7410f2076 100644 --- a/www/on/npm/%package/index.html.spt +++ b/www/on/npm/%package/index.html.spt @@ -12,6 +12,7 @@ banner = package_name page_id = "on-npm-foo" suppress_sidebar = True url = 'https://npmjs.com/package/' + package.name +nemails = len(package.emails) [---] {% extends "templates/base.html" %} @@ -47,15 +48,30 @@ url = 'https://npmjs.com/package/' + package.name

{{ _('Gratipay helps companies and others pay for open source.') }} {{ _("Learn more") }}

{% else %} -

{{ _('Is this yours? You can claim it on Gratipay with one of these email addresses:') - }}

- - - + {% if nemails == 0 %} +

{{ _("We didn't find any emails associated with this package.") }}

+ {% else %} + + + {% if nemails == 1 %} + +

{{ _( 'Is this yours? You can claim it on Gratipay using {b}{email}{_b}.' + , email=package.emails[0] + , b=''|safe + , _b=''|safe + ) }}

+ {% else %} +

{{ _('Is this yours? You can claim it on Gratipay with one of these email addresses:') + }}

+ + {% endif %} + + {% endif %} {% endif %} {% endblock %} diff --git a/www/~/%username/emails/modify.json.spt b/www/~/%username/emails/modify.json.spt index 9e094cdd75..14ce8ac2e4 100644 --- a/www/~/%username/emails/modify.json.spt +++ b/www/~/%username/emails/modify.json.spt @@ -41,7 +41,7 @@ elif action == 'add-email-and-claim-package': package_id = request.body['package_id'] package = Package.from_id(package_id) package.send_confirmation_email(address) - msg = _("Check {email_address} for a confirmation email.", email_address=address) + msg = _("Check {email} for a confirmation link.", email=address) else: raise Response(400, 'unknown action "%s"' % action)