Merge pull request #304 from grant-project/expired-notif
Contribution expired notification
This commit is contained in:
commit
ad632dd4f9
|
@ -92,6 +92,11 @@ export default [
|
|||
title: 'Contribution proposal canceled',
|
||||
description: 'Sent to contributors when an admin cancels the proposal after funding',
|
||||
},
|
||||
{
|
||||
id: 'contribution_expired',
|
||||
title: 'Contribution expired',
|
||||
description: 'Sent 24 hours after a contribution is made with no confirmation',
|
||||
},
|
||||
{
|
||||
id: 'comment_reply',
|
||||
title: 'Comment reply',
|
||||
|
|
|
@ -126,6 +126,13 @@ example_email_args = {
|
|||
'refund_address': 'ztqdzvnK2SE27FCWg69EdissCBn7twnfd1XWLrftiZaT4rSFCkp7eQGQDSWXBF43sM5cyA4c8qyVjBP9Cf4zTcFJxf71ve8',
|
||||
'account_settings_url': 'http://accountsettingsurl.com/',
|
||||
},
|
||||
'contribution_expired': {
|
||||
'proposal': proposal,
|
||||
'contribution': contribution,
|
||||
'contact_url': 'http://somecontacturl.com',
|
||||
'profile_url': 'http://someprofile.com',
|
||||
'proposal_url': 'http://someproposal.com',
|
||||
},
|
||||
'comment_reply': {
|
||||
'author': user,
|
||||
'proposal': proposal,
|
||||
|
|
|
@ -199,6 +199,18 @@ def contribution_proposal_canceled(email_args):
|
|||
}
|
||||
|
||||
|
||||
def contribution_expired(email_args):
|
||||
return {
|
||||
'subject': 'Your contribution expired',
|
||||
'title': 'Contribution expired',
|
||||
'preview': 'Your {} ZEC contribution to {} could not be confirmed, and has expired'.format(
|
||||
email_args['contribution'].amount,
|
||||
email_args['proposal'].title,
|
||||
),
|
||||
'subscription': EmailSubscription.FUNDED_PROPOSAL_CONTRIBUTION,
|
||||
}
|
||||
|
||||
|
||||
def comment_reply(email_args):
|
||||
return {
|
||||
'subject': 'New reply from {}'.format(email_args['author'].display_name),
|
||||
|
@ -282,6 +294,7 @@ get_info_lookup = {
|
|||
'contribution_refunded': contribution_refunded,
|
||||
'contribution_proposal_failed': contribution_proposal_failed,
|
||||
'contribution_proposal_canceled': contribution_proposal_canceled,
|
||||
'contribution_expired': contribution_expired,
|
||||
'comment_reply': comment_reply,
|
||||
'proposal_arbiter': proposal_arbiter,
|
||||
'milestone_request': milestone_request,
|
||||
|
|
|
@ -21,6 +21,7 @@ from grant.utils.enums import (
|
|||
MilestoneStage
|
||||
)
|
||||
from grant.utils.stubs import anonymous_user
|
||||
from grant.task.jobs import ContributionExpired
|
||||
|
||||
proposal_team = db.Table(
|
||||
'proposal_team', db.Model.metadata,
|
||||
|
@ -362,6 +363,10 @@ class Proposal(db.Model):
|
|||
staking=staking,
|
||||
)
|
||||
db.session.add(contribution)
|
||||
db.session.flush()
|
||||
if user_id:
|
||||
task = ContributionExpired(contribution)
|
||||
task.make_task()
|
||||
db.session.commit()
|
||||
return contribution
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ from datetime import datetime, timedelta
|
|||
|
||||
from grant.extensions import db
|
||||
from grant.email.send import send_email
|
||||
from grant.utils.enums import ProposalStage
|
||||
from grant.utils.enums import ProposalStage, ContributionStatus
|
||||
from grant.utils.misc import make_url
|
||||
|
||||
|
||||
|
@ -86,8 +86,48 @@ class ProposalDeadline:
|
|||
'account_settings_url': make_url('/profile/settings?tab=account')
|
||||
})
|
||||
|
||||
class ContributionExpired:
|
||||
JOB_TYPE = 3
|
||||
|
||||
def __init__(self, contribution):
|
||||
self.contribution = contribution
|
||||
|
||||
def blobify(self):
|
||||
return {
|
||||
"contribution_id": self.contribution.id,
|
||||
}
|
||||
|
||||
def make_task(self):
|
||||
from .models import Task
|
||||
task = Task(
|
||||
job_type=self.JOB_TYPE,
|
||||
blob=self.blobify(),
|
||||
execute_after=self.contribution.date_created + timedelta(hours=24),
|
||||
)
|
||||
db.session.add(task)
|
||||
db.session.commit()
|
||||
|
||||
@staticmethod
|
||||
def process_task(task):
|
||||
from grant.proposal.models import ProposalContribution
|
||||
contribution = ProposalContribution.query.filter_by(id=task.blob["contribution_id"]).first()
|
||||
|
||||
# If it's missing or not pending, noop out
|
||||
if not contribution or contribution.status != ContributionStatus.PENDING:
|
||||
return
|
||||
|
||||
# Otherwise, inform the user (if not anonymous)
|
||||
if contribution.user:
|
||||
send_email(contribution.user.email_address, 'contribution_expired', {
|
||||
'contribution': contribution,
|
||||
'proposal': contribution.proposal,
|
||||
'contact_url': make_url('/contact'),
|
||||
'profile_url': make_url(f'/profile/{contribution.user.id}'),
|
||||
'proposal_url': make_url(f'/proposals/{contribution.proposal.id}'),
|
||||
})
|
||||
|
||||
JOBS = {
|
||||
1: ProposalReminder.process_task,
|
||||
2: ProposalDeadline.process_task,
|
||||
3: ContributionExpired.process_task,
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
<p style="margin: 0 0 20px;">
|
||||
Your <strong>{{ args.contribution.amount }} ZEC</strong> contribution to
|
||||
<strong>{{ args.proposal.title}}</strong> could not be confirmed on-chain,
|
||||
and has expired.
|
||||
</p>
|
||||
|
||||
<p style="margin: 0 0 20px;">
|
||||
<strong>If you did not send the contribution</strong>:
|
||||
You have nothing to worry about, you can simply delete the contribution from
|
||||
<a href="{{ args.profile_url }}">your profile</a>. Just make that sure you do
|
||||
not send any money to the contribution address. If you'd still like to make a
|
||||
contribution, you can start a new one on the
|
||||
<a href="{{ args.proposal_url }}">proposal page</a>.
|
||||
</p>
|
||||
|
||||
<p style="margin: 0;">
|
||||
<strong>If you're sure you sent the contribution</strong>:
|
||||
Please contact our team using a method from the
|
||||
<a href="{{ args.contact_url }}">contact page</a> with details about the
|
||||
contribution, such as a transaction ID or payment
|
||||
disclosure from the transaction.
|
||||
</p>
|
|
@ -0,0 +1,13 @@
|
|||
Your {{ args.contribution.amount }} ZEC contribution to "{{ args.proposal.title}}"
|
||||
could not be confirmed on-chain, and has expired.
|
||||
|
||||
If you did not send the contribution, you have nothing to worry about, you can
|
||||
simply delete the contribution from your profile. Just make that sure you do not
|
||||
send any money to the contribution address. If you'd still like to make a
|
||||
contribution, you can start a new one on the proposal page.
|
||||
|
||||
If you're sure you've sent the contribution, please contact our team using a method
|
||||
from the link below with details about the contribution, such as a transaction ID or
|
||||
payment disclosure from the transaction.
|
||||
|
||||
Contact us at {{ args.contact_url }}
|
Loading…
Reference in New Issue