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

Commit

Permalink
Shelve work on multiple email support
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed Feb 8, 2017
1 parent 13c1703 commit 67ad75a
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 26 deletions.
25 changes: 15 additions & 10 deletions js/gratipay/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -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;
}
12 changes: 12 additions & 0 deletions tests/py/test_www_npm_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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</a> has not been claimed' in body
assert 'using <b>[email protected]</b>' in body

def test_auth_gets_multiple_options_if_present(self):
self.make_package('npm', 'bar', 'Bar', ['[email protected]', '[email protected]'])
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&#39;t find any emails" in body
21 changes: 16 additions & 5 deletions tests/ttw/test_package_claiming.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected] for a confirmation email.')
assert self.has_text('Check [email protected] 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=['[email protected]', '[email protected]'])
self.check()

def test_can_send_to_second_email(self):
self.make_package(emails=['[email protected]', '[email protected]'])
self.check(extra_action=lambda: self.css('input[type=radio]')[1].click())
36 changes: 26 additions & 10 deletions www/on/npm/%package/index.html.spt
Original file line number Diff line number Diff line change
Expand Up @@ -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" %}

Expand Down Expand Up @@ -47,15 +48,30 @@ url = 'https://npmjs.com/package/' + package.name
<p>{{ _('Gratipay helps companies and others pay for open source.') }}
<a href="/about/">{{ _("Learn more") }}</a></p>
{% else %}
<p>{{ _('Is this yours? You can claim it on Gratipay with one of these email addresses:')
}}</p>

<ul data-package-id="{{ package.id }}">
{% for i, email in enumerate(package.emails) %}
<li><input type="radio" name="email" value="{{ email }}" id="email-{{i}}">
<label for="email-{{ i }}">{{ email }}</a></li>
{% endfor %}
</ul>
<button type="submit" class="send">{{ _('Send confirmation link') }}</button>
{% if nemails == 0 %}
<p>{{ _("We didn't find any emails associated with this package.") }}</p>
{% else %}
<input type="hidden" name="package_id" value="{{ package.id }}">
<input type="hidden" name="nemails" value="{{ nemails }}">
{% if nemails == 1 %}
<input type="hidden" name="email" value="{{ package.emails[0] }}">
<p>{{ _( 'Is this yours? You can claim it on Gratipay using {b}{email}{_b}.'
, email=package.emails[0]
, b='<b>'|safe
, _b='</b>'|safe
) }}</p>
{% else %}
<p>{{ _('Is this yours? You can claim it on Gratipay with one of these email addresses:')
}}</p>
<ul>
{% for i, email in enumerate(package.emails) %}
<li><input type="radio" name="email" value="{{ email }}" id="email-{{i}}"
{% if i == 0 %}checked{% endif %}>
<label for="email-{{ i }}">{{ email }}</a></li>
{% endfor %}
</ul>
{% endif %}
<button type="submit" class="send">{{ _('Send confirmation link') }}</button>
{% endif %}
{% endif %}
{% endblock %}
2 changes: 1 addition & 1 deletion www/~/%username/emails/modify.json.spt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 67ad75a

Please sign in to comment.