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

Commit

Permalink
Checkpoint 2
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed May 5, 2017
1 parent 758394c commit 9898a38
Show file tree
Hide file tree
Showing 89 changed files with 2,318 additions and 587 deletions.
3 changes: 2 additions & 1 deletion 401.spt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ banner = "401"
[---] text/html via jinja2
{% extends "templates/base.html" %}
{% block content %}
Please {% include "templates/sign-in-using.html" %} to continue.
<p>{{ _('Please sign in to continue.') }}</p>
<p>{{ sign_in_using() }}</p>
{% endblock %}
[---] application/json via stdlib_percent
{ "error_code": 401
Expand Down
3 changes: 2 additions & 1 deletion 410.spt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ title = _('Closed') if 'username' in request.path else '410'
<p>{{ _("The account owner has closed this account.") }}</p>
{% if user.ANON %}
<h2>{{ _("Are you the account owner?") }}</h2>
<p>{% include "templates/sign-in-using.html" %} {{ _("to reopen your account.") }}</p>
<p>{{ _("You may reopen your account by signing in.") }}</p>
<p>{{ sign_in_using() }}</p>
{% endif %}
{% else %}
<p>{{ status_strings[410] }}</p>
Expand Down
8 changes: 4 additions & 4 deletions defaults.env
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ ASPEN_WWW_ROOT=www/
# https://github.com/benoitc/gunicorn/issues/186
GUNICORN_OPTS="--workers=1 --timeout=99999999"

# For testing Team review ticket posting
# For testing project review ticket posting
# Set your own username and an access token in local.env
TEAM_REVIEW_REPO=gratipay/test-gremlin
TEAM_REVIEW_USERNAME=
TEAM_REVIEW_TOKEN=
PROJECT_REVIEW_REPO=
PROJECT_REVIEW_USERNAME=
PROJECT_REVIEW_TOKEN=

RAISE_SIGNIN_NOTIFICATIONS=no

Expand Down
72 changes: 72 additions & 0 deletions emails/verification-notice.spt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{{ _("New activity on your account") }}

[---] text/html
{% if new_email_verified %}
{{ ngettext( "We are connecting the {package_name} npm package to the {username} account on "
"Gratipay. This is a notification sent to {email_address} because that is the "
"primary email address we have on file."
, "We are connecting {n} npm packages to the {username} account on Gratipay. This is "
"a notification sent to {email_address} because that is the primary email address "
"we have on file."
, n=npackages
, package_name=('<b>{}</b>'|safe).format(package_name)
, username=('<b><a href="https://gratipay.com/{0}/">{0}</a></b>'|safe).format(username)
, email_address=('<b>{}</b>'|safe).format(email)
) }}
{% elif npackages > 0 %}
{{ ngettext( "We are connecting {email_address} and the {package_name} npm package to the "
"{username} account on Gratipay. This is a notification sent to {email_address_2} "
"because that is the primary email address we have on file."
, "We are connecting {email_address} and {n} npm packages to the {username} account on "
"Gratipay. This is a notification sent to {email_address_2} because that is the "
"primary email address we have on file."
, n=npackages
, package_name=('<b>{}</b>'|safe).format(package_name)
, username=('<b><a href="https://gratipay.com/{0}/">{0}</a></b>'|safe).format(username)
, email_address=('<b>{}</b>'|safe).format(new_email)
, email_address_2=('<b>{}</b>'|safe).format(email)
) }}
{% else %}
{{ _( "We are connecting {email_address} to the {username} account on Gratipay. This is a "
"notification sent to {email_address_2} because that is the primary email address we have "
"on file."
, username=('<b><a href="https://gratipay.com/{0}/">{0}</a></b>'|safe).format(username)
, email_address=('<b>{}</b>'|safe).format(new_email)
, email_address_2=('<b>{}</b>'|safe).format(email)
) }}
{% endif %}
[---] text/plain
{% if new_email_verified %}
{{ ngettext( "We are connecting the {package_name} npm package to the {username} account on "
"Gratipay. This is a notification sent to {email_address} because that is the "
"primary email address we have on file."
, "We are connecting {n} npm packages to the {username} account on Gratipay. This is "
"a notification sent to {email_address} because that is the primary email address "
"we have on file."
, n=npackages
, package_name=package_name
, username=username
, email_address=email
) }}
{% elif npackages > 0 %}
{{ ngettext( "We are connecting {email_address} and the {package_name} npm package to the "
"{username} account on Gratipay. This is a notification sent to {email_address_2} "
"because that is the primary email address we have on file."
, "We are connecting {email_address} and {n} npm packages to the {username} account on "
"Gratipay. This is a notification sent to {email_address_2} because that is the "
"primary email address we have on file."
, n=npackages
, package_name=package_name
, username=username
, email_address=new_email
, email_address_2=email
) }}
{% else %}
{{ _( "We are connecting {email_address} to the {username} account on Gratipay. This is a "
"notification sent to {email_address_2} because that is the primary email address we have "
"on file."
, username=username
, email_address=new_email
, email_address_2=email
) }}
{% endif %}
59 changes: 53 additions & 6 deletions emails/verification.spt
Original file line number Diff line number Diff line change
@@ -1,17 +1,64 @@
{{ _("Connect to {0} on Gratipay?", username) }}

[---] text/html
{{ _("We've received a request to connect {0} to the {1} account on Gratipay. Sound familiar?",
('<b>%s</b>'|safe) % email,
('<b><a href="https://gratipay.com/~{0}/">{0}</a></b>'|safe).format(username)) }}
{% if new_email_verified %}
{{ ngettext( "We've received a request to connect the {package_name} npm package to the "
"{username} account on Gratipay. Sound familiar?"
, "We've received a request to connect {n} npm packages to the {username} account "
"on Gratipay. Sound familiar?"
, n=npackages
, package_name=('<b>{}</b>'|safe).format(package_name)
, username=('<b><a href="https://gratipay.com/~{0}/">{0}</a></b>'|safe).format(username)
) }}
{% elif npackages > 0 %}
{{ ngettext( "We've received a request to connect {email_address} and the {package_name} npm "
"package to the {username} account on Gratipay. Sound familiar?"
, "We've received a request to connect {email_address} and {n} npm packages to the "
"{username} account on Gratipay. Sound familiar?"
, n=npackages
, package_name=('<b>{}</b>'|safe).format(package_name)
, email_address=('<b>{}</b>'|safe).format(new_email)
, username=('<b><a href="https://gratipay.com/~{0}/">{0}</a></b>'|safe).format(username)
) }}
{% else %}
{{ _( "We've received a request to connect {email_address} to the {username} account on Gratipay. "
"Sound familiar?"
, email_address=('<b>{}</b>'|safe).format(new_email)
, username=('<b><a href="https://gratipay.com/~{0}/">{0}</a></b>'|safe).format(username)
) }}
{% endif %}
<br>
<br>
<a href="{{ link }}" style="{{ button_style }}">{{ _("Yes, proceed!") }}</a>

[---] text/plain
{{ _("We've received a request to connect {0} to the {1} account on Gratipay. Sound familiar?",
email, username) }}
{% if new_email_verified %}
{{ ngettext( "We've received a request to connect the {package_name} npm package to the "
"{username} account on Gratipay. Sound familiar?"
, "We've received a request to connect {n} npm packages to the {username} account "
"on Gratipay. Sound familiar?"
, n=npackages
, package_name=package_name
, username=username
) }}
{% elif npackages > 0 %}
{{ ngettext( "We've received a request to connect {email_address} and the {package_name} npm "
"package to the {username} account on Gratipay. Sound familiar?"
, "We've received a request to connect {email_address} and {n} npm packages to the "
"{username} account on Gratipay. Sound familiar?"
, n=npackages
, package_name=package_name
, email_address=new_email
, username=username
) }}
{% else %}
{{ _( "We've received a request to connect {email_address} to the {username} account on Gratipay. "
"Sound familiar?"
, email_address=new_email
, username=username
) }}
{% endif %}

{{ _("Follow this link to finish connecting your email:") }}
{{ _("Follow this link to finish connecting:") }}

{{ link }}
13 changes: 0 additions & 13 deletions emails/verification_notice.spt

This file was deleted.

5 changes: 2 additions & 3 deletions error.spt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ from __future__ import absolute_import, division, print_function, unicode_litera

from aspen.http import status_strings

from gratipay.utils import LazyResponse
from gratipay.utils.i18n import HTTP_ERRORS
from gratipay.utils.i18n import HTTP_ERRORS, LocalizedErrorResponse

[----------------------------------------]

Expand All @@ -19,7 +18,7 @@ try:
except Exception as e:
website.tell_sentry(e, state)

if isinstance(response, LazyResponse):
if isinstance(response, LocalizedErrorResponse):
response.render_body(state)
err = response.body
if code == 500 and not err:
Expand Down
5 changes: 3 additions & 2 deletions gratipay/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .cron import Cron
from .models import GratipayDB
from .payday_runner import PaydayRunner
from .project_review_repo import ProjectReviewRepo
from .website import Website


Expand Down Expand Up @@ -35,7 +36,6 @@ def __init__(self):
wireup.base_url(website, env)
wireup.secure_cookies(env)
wireup.billing(env)
wireup.team_review(env)
wireup.username_restrictions(website)
wireup.load_i18n(website.project_root, tell_sentry)
wireup.other_stuff(website, env)
Expand All @@ -46,6 +46,7 @@ def __init__(self):
self.install_periodic_jobs(website, env, db)
self.website = website
self.payday_runner = PaydayRunner(self)
self.project_review_repo = ProjectReviewRepo(env)


def install_periodic_jobs(self, website, env, db):
Expand All @@ -62,7 +63,7 @@ def add_event(self, c, type, payload):
This is the function we use to capture interesting events that happen
across the system in one place, the ``events`` table.
:param c: a :py:class:`Postres` or :py:class:`Cursor` instance
:param c: a :py:class:`Postgres` or :py:class:`Cursor` instance
:param unicode type: an indicator of what type of event it is--either ``participant``,
``team`` or ``payday``
:param payload: an arbitrary JSON-serializable data structure; for ``participant`` type,
Expand Down
6 changes: 3 additions & 3 deletions gratipay/elsewhere/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from requests_oauthlib import OAuth1Session, OAuth2Session

from gratipay.elsewhere._extractors import not_available
from gratipay.utils import LazyResponse
from gratipay.utils.i18n import LocalizedErrorResponse


ACTIONS = {'opt-in', 'connect'}
Expand Down Expand Up @@ -137,13 +137,13 @@ def msg(_, to_age):
return _("You've consumed your quota of requests, you can try again in {0}.", to_age(reset))
else:
return _("You're making requests too fast, please try again later.")
raise LazyResponse(status, msg)
raise LocalizedErrorResponse(status, msg)
if status != 200:
log('{} api responded with {}:\n{}'.format(self.name, status, response.text)
, level=logging.ERROR)
msg = lambda _: _("{0} returned an error, please try again later.",
self.display_name)
raise LazyResponse(502, msg)
raise LocalizedErrorResponse(502, msg)

return response

Expand Down
33 changes: 22 additions & 11 deletions gratipay/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from __future__ import print_function, unicode_literals

from aspen import Response
from gratipay.utils.i18n import LocalizedErrorResponse


class ProblemChangingUsername(Exception):
Expand All @@ -27,28 +27,37 @@ class UsernameAlreadyTaken(ProblemChangingUsername):
msg = "The username '{}' is already taken."


class ProblemChangingEmail(Response):
def __init__(self, *args):
Response.__init__(self, 400, self.msg.format(*args))
class ProblemChangingEmail(LocalizedErrorResponse):
pass

class EmailAlreadyVerified(ProblemChangingEmail):
msg = "{} is already verified for this Gratipay account."
def lazy_body(self, _):
return _("You have already added and verified that address.")

class EmailTaken(ProblemChangingEmail):
msg = "{} is already connected to a different Gratipay account."
def lazy_body(self, _):
return _("That address is already linked to a different Gratipay account.")

class CannotRemovePrimaryEmail(ProblemChangingEmail):
msg = "You cannot remove your primary email address."
def lazy_body(self, _):
return _("You cannot remove your primary email address.")

class EmailNotOnFile(ProblemChangingEmail):
def lazy_body(self, _):
return _("That email address is not on file for this package.")

class EmailNotVerified(ProblemChangingEmail):
msg = "The email address '{}' is not verified."
def lazy_body(self, _):
return _("That email address is not verified.")

class TooManyEmailAddresses(ProblemChangingEmail):
msg = "You've reached the maximum number of email addresses we allow."
def lazy_body(self, _):
return _("You've reached the maximum number of email addresses we allow.")


class Throttled(Exception):
msg = "You've initiated too many emails too quickly. Please try again in a minute or two."
class Throttled(LocalizedErrorResponse):
def lazy_body(self, _):
return _("You've initiated too many emails too quickly. Please try again in a minute or two.")


class ProblemChangingNumber(Exception):
Expand Down Expand Up @@ -78,3 +87,5 @@ def __str__(self):
return "Negative balance not allowed in this context."

class NotWhitelisted(Exception): pass
class NoPackages(Exception): pass
class NoTeams(Exception): pass
Loading

0 comments on commit 9898a38

Please sign in to comment.