Merge branch 'develop' into admin-users

This commit is contained in:
William O'Beirne 2019-02-23 16:08:06 -05:00 committed by GitHub
commit 076bcc67bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 95 additions and 61 deletions

View File

@ -9,9 +9,9 @@ from .subscription_settings import EmailSubscription, is_subscribed
default_template_args = {
'home_url': make_url('/'),
'account_url': make_url('/user'),
'email_settings_url': make_url('/settings'),
'unsubscribe_url': make_url('/unsubscribe'),
'account_url': make_url('/profile'),
'email_settings_url': make_url('/profile/settings?tab=emails'),
'unsubscribe_url': make_url('/profile/settings?tab=emails'),
}
@ -113,6 +113,7 @@ def proposal_failed(email_args):
'preview': 'Your proposal entitled {} failed to get enough funding by the deadline'.format(
email_args['proposal'].title,
),
'subscription': EmailSubscription.MY_PROPOSAL_FUNDED,
}
@ -267,7 +268,7 @@ get_info_lookup = {
}
def generate_email(type, email_args):
def generate_email(type, email_args, user=None):
info = get_info_lookup[type](email_args)
body_text = render_template(
'emails/%s.txt' % (type),
@ -280,10 +281,15 @@ def generate_email(type, email_args):
UI=UI,
)
template_args = { **default_template_args }
if user:
template_args['unsubscribe_url'] = make_url('/email/unsubscribe?code={}'.format(user.email_verification.code))
html = render_template(
'emails/template.html',
args={
**default_template_args,
**template_args,
**info,
'body': Markup(body_html),
},
@ -292,7 +298,7 @@ def generate_email(type, email_args):
text = render_template(
'emails/template.txt',
args={
**default_template_args,
**template_args,
**info,
'body': body_text,
},
@ -310,17 +316,18 @@ def send_email(to, type, email_args):
if current_app and current_app.config.get("TESTING"):
return
from grant.user.models import User
user = User.get_by_email(to)
info = get_info_lookup[type](email_args)
if 'subscription' in info and 'user' in email_args:
user = email_args['user']
if user and 'subscription' in info:
sub = info['subscription']
if not is_subscribed(user.settings.email_subscriptions, sub):
if user and not is_subscribed(user.settings.email_subscriptions, sub):
print(f'Ignoring send_email to {to} of type {type} because user is unsubscribed.')
return
try:
email = generate_email(type, email_args)
email = generate_email(type, email_args, user)
sg = sendgrid.SendGridAPIClient(apikey=SENDGRID_API_KEY)
mail = Mail(

View File

@ -700,7 +700,12 @@ class ProposalContributionSchema(ma.Schema):
return dt_to_unix(obj.date_created)
def get_addresses(self, obj):
return blockchain_get('/contribution/addresses', {'contributionId': obj.id})
# Omit 'memo' and 'sprout' for now
# TODO: Add back in 'sapling' when ready
addresses = blockchain_get('/contribution/addresses', {'contributionId': obj.id})
return {
'transparent': addresses['transparent'],
}
proposal_contribution_schema = ProposalContributionSchema()

View File

@ -183,7 +183,7 @@
<td align="center" bgcolor="#f4f4f4"
style="padding: 0px 30px 30px 30px; color: #666666; font-family: 'Nunito Sans', Helvetica, Arial, sans-serif; font-size: 14px; font-weight: 400; line-height: 18px;">
<p style="margin: 0;">
Dont want anymore emails?
Dont want any more emails?
<a href="{{ args.unsubscribe_url }}" style="color: #221F1F; font-weight: 700;"
target="_blank">
Click here to unsubscribe

View File

@ -6,4 +6,4 @@
123 Address Street
City, ST 12345
Unsubscribe here: {{ args.unsubscribe_url }}
Don't want any more emails? Unsubscribe here: {{ args.unsubscribe_url }}

View File

@ -1,6 +1,6 @@
import React, { ReactNode } from 'react';
import classnames from 'classnames';
import { Button, Form, Icon, Radio } from 'antd';
import { Button, Form, Icon, Radio, Alert } from 'antd';
import { RadioChangeEvent } from 'antd/lib/radio';
import QRCode from 'qrcode.react';
import { formatZcashCLI, formatZcashURI } from 'utils/formatters';
@ -22,7 +22,7 @@ interface State {
export default class PaymentInfo extends React.Component<Props, State> {
state: State = {
sendType: 'sprout',
sendType: 'transparent',
};
render() {
@ -36,33 +36,32 @@ export default class PaymentInfo extends React.Component<Props, State> {
if (contribution) {
if (sendType !== 'transparent') {
memo = contribution.addresses.memo;
memo = 'Fix me';
// memo = contribution.addresses.memo;
}
address = contribution.addresses[sendType];
// address = contribution.addresses[sendType];
address = contribution.addresses.transparent;
amount = contribution.amount;
cli = formatZcashCLI(address, amount, memo);
uri = formatZcashURI(address, amount, memo);
}
return (
<Form className="PaymentInfo" layout="vertical">
<div className="PaymentInfo-text">
{text ||
`
Thank you for contributing! Just send using whichever method works best for
you, and we'll let you know when your contribution has been confirmed.
let content;
if (sendType === 'sprout') {
content = (
<Alert
type="warning"
message="Not yet supported"
description={`
Unfortunately, sapling addresses aren't yet supported, and sprout addresses
have been deprecated. We hope to add support in the near future!
`}
</div>
<Radio.Group
className="PaymentInfo-types"
onChange={this.handleChangeSendType}
value={sendType}
>
<Radio.Button value="sprout">Z Address (Private)</Radio.Button>
<Radio.Button value="transparent">T Address (Public)</Radio.Button>
</Radio.Group>
showIcon
/>
);
} else {
content = (
<>
<div className="PaymentInfo-uri">
<div className={classnames('PaymentInfo-uri-qr', !uri && 'is-loading')}>
<span style={{ opacity: uri ? 1 : 0 }}>
@ -100,6 +99,28 @@ export default class PaymentInfo extends React.Component<Props, State> {
/>
</div>
</div>
</>
);
}
return (
<Form className="PaymentInfo" layout="vertical">
<div className="PaymentInfo-text">
{text ||
`
Thank you for contributing! Just send using whichever method works best for
you, and we'll let you know when your contribution has been confirmed.
`}
</div>
<Radio.Group
className="PaymentInfo-types"
onChange={this.handleChangeSendType}
value={sendType}
>
<Radio.Button value="transparent">T Address (Public)</Radio.Button>
<Radio.Button value="sprout">Z Address (Private)</Radio.Button>
</Radio.Group>
{content}
</Form>
);
}

View File

@ -31,7 +31,7 @@ export const EMAIL_SUBSCRIPTIONS: { [key in ESKey]: EmailSubscriptionInfo } = {
value: false,
},
fundedProposalFunded: {
description: 'gets full funding',
description: 'gets fully funded or fails to get funding',
category: EMAIL_SUBSCRIPTION_CATEGORY.FUNDED,
value: false,
},
@ -63,7 +63,7 @@ export const EMAIL_SUBSCRIPTIONS: { [key in ESKey]: EmailSubscriptionInfo } = {
value: false,
},
myProposalFunded: {
description: 'gets fully funded',
description: 'gets fully funded or fails to get funding',
category: EMAIL_SUBSCRIPTION_CATEGORY.PROPOSAL,
value: false,
},

View File

@ -11,9 +11,10 @@ export interface Contribution {
export interface ContributionWithAddresses extends Contribution {
addresses: {
sprout: string;
transparent: string;
memo: string;
// TODO: Add sapling and memo in when ready
// sprout: string;
// memo: string;
};
}