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

Commit

Permalink
Round out confirmation form for zero and ∞
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed Feb 8, 2017
1 parent 13c1703 commit 0a16a01
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 29 deletions.
14 changes: 4 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 = $('input[name=email]:checked').val();

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 Down
6 changes: 6 additions & 0 deletions scss/components/listing.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
.sorry {
text-align: center;
font: normal 12px/15px $Ideal;
color: $medium-gray;
}

table.listing {
width: 100%;

Expand Down
6 changes: 0 additions & 6 deletions scss/pages/search.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@
}
}

.sorry {
text-align: center;
font: normal 12px/15px $Ideal;
color: $medium-gray;
}

h2 {
margin-top: 4em;
&:first-of-type {
Expand Down
17 changes: 16 additions & 1 deletion tests/py/test_www_npm_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,19 @@ 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 'with one of these email addresses' in body
assert 'using any email address on file' in body
assert '[email protected]' 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 'using any email address on file' in body
assert '[email protected]' in body
assert '[email protected]' 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, choice=0):
self.make_participant('bob', claimed_time='now')
self.sign_in('bob')
self.visit('/on/npm/foo/')
self.css('input[type=radio]')[0].click()
self.css('input[type=radio]')[choice].click()
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(choice=1)
20 changes: 14 additions & 6 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,22 @@ 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 }}">
<p>{{ _( 'Is this yours? You can claim it on Gratipay using any email address {a}on file{_a} in the maintainers field in the npm registry.'
, a=('<a href="https://registry.npmjs.com/' + package.name + '">')|safe
, _a='</a>'|safe
) }}
{% if nemails == 0 %}
<p class="sorry">{{ _("Sorry, we didn't find any email addresses on file.") }}</p>
{% else %}
<input type="hidden" name="package_id" value="{{ package.id }}">
<ul>
{% for i, email in enumerate(package.emails) %}
<li><input type="radio" name="email" value="{{ email }}" id="email-{{i}}">
<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>
<button type="submit" class="send">{{ _('Send confirmation link') }}</button>
<button type="submit" class="send selected">{{ _('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 0a16a01

Please sign in to comment.