From d7c4554d774541c7b69d55e99c6e77c8ed9519ed Mon Sep 17 00:00:00 2001 From: Sebastian T F Date: Sat, 6 Jun 2020 19:48:47 +0530 Subject: [PATCH 1/7] setup web preview url --- app/app/urls.py | 1 + app/retail/emails.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/app/app/urls.py b/app/app/urls.py index 94632f365e4..e6118502ede 100644 --- a/app/app/urls.py +++ b/app/app/urls.py @@ -540,6 +540,7 @@ path('_administration/email/wallpost', retail.emails.wallpost, name='wallpost_email'), path('_administration/email/grant_update', retail.emails.grant_update, name='grant_update_email'), path('_administration/email/grant_recontribute', retail.emails.grant_recontribute, name='grant_recontribute_email'), + path('_administration/email/grant_txn_failed', retail.emails.grant_txn_failed, name='grant_txn_failed_email'), path( '_administration/email/new_bounty_acceptance', retail.emails.new_bounty_acceptance, diff --git a/app/retail/emails.py b/app/retail/emails.py index 70b8ef49888..06ddfcd4537 100644 --- a/app/retail/emails.py +++ b/app/retail/emails.py @@ -1374,6 +1374,9 @@ def grant_update(request): @staff_member_required def grant_recontribute(request): response_html, _ = render_grant_recontribute(settings.CONTACT_EMAIL) +def grant_txn_failed(request): + failed_contrib = Contribution.objects.filter(subscription__contributor_profile__user__email=settings.CONTACT_EMAIL).exclude(validator_passed=True).first() + response_html, _ = render_grant_txn_failed(settings.CONTACT_EMAIL, failed_contrib.subscription.grant, failed_contrib.tx_id) return HttpResponse(response_html) @staff_member_required From 86116326fc8d637648adc469700a925865b6069e Mon Sep 17 00:00:00 2001 From: Sebastian T F Date: Sat, 6 Jun 2020 19:51:31 +0530 Subject: [PATCH 2/7] implement render_grant_txn_failed --- app/retail/emails.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/retail/emails.py b/app/retail/emails.py index 06ddfcd4537..8906bbe4a27 100644 --- a/app/retail/emails.py +++ b/app/retail/emails.py @@ -69,6 +69,7 @@ ('comment', _('Comment Emails'), _('Only when you are sent a comment')), ('wall_post', _('Wall Post Emails'), _('Only when someone writes on your wall')), ('grant_updates', _('Grant Update Emails'), _('Updates from Grant Owners about grants you\'ve funded.')), + ('grant_txn_failed', _('Grant Transaction Failed Emails'), _('Notifies Grant contributors when their contribution txn has failed.')), ] @@ -884,6 +885,19 @@ def render_grant_recontribute(to_email, prev_round_start=(2020, 3, 23), prev_rou response_html = premailer_transform(render_to_string("emails/grant_recontribute.html", params)) response_txt = render_to_string("emails/grant_recontribute.txt", params) +def render_grant_txn_failed(to_email, grant, tx_id): + email_style = 27 + + params = { + 'grant_title': grant.title, + 'tx_id': tx_id, + 'tx_url': "https://etherscan.io/tx/"+tx_id, + 'email_style': email_style, + 'hide_bottom_logo': True, + } + + response_html = premailer_transform(render_to_string("emails/grant_txn_failed.html", params)) + response_txt = render_to_string("emails/grant_txn_failed.txt", params) return response_html, response_txt From ec5a0e5c056278205bc618d44a737f7835682e85 Mon Sep 17 00:00:00 2001 From: Sebastian T F Date: Sat, 6 Jun 2020 19:53:36 +0530 Subject: [PATCH 3/7] build template grant_txn_failed.html --- .../templates/emails/grant_txn_failed.html | 43 +++++++++++++++++++ .../templates/emails/grant_txn_failed.txt | 7 +++ app/retail/templates/emails/template.html | 27 ++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 app/retail/templates/emails/grant_txn_failed.html create mode 100644 app/retail/templates/emails/grant_txn_failed.txt diff --git a/app/retail/templates/emails/grant_txn_failed.html b/app/retail/templates/emails/grant_txn_failed.html new file mode 100644 index 00000000000..5ae302ee7a0 --- /dev/null +++ b/app/retail/templates/emails/grant_txn_failed.html @@ -0,0 +1,43 @@ +{% extends 'emails/template.html' %} +{% comment %} + Copyright (C) 2018 Gitcoin Core + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +{% endcomment %} +{% load i18n humanize %} + +{% block content %} + +

Grants transaction failed, try again?

+ +
+

+ Your contribution to {{ grant_title }} failed due to a technical issue. +

+
+ +
+

+ Transaction ID:
+ {{ tx_id }} +

+
+ +
+ {% trans "Resubmit Transaction" %} +
+ View on Etherscan +
+ +{% endblock %} \ No newline at end of file diff --git a/app/retail/templates/emails/grant_txn_failed.txt b/app/retail/templates/emails/grant_txn_failed.txt new file mode 100644 index 00000000000..8a0f1241089 --- /dev/null +++ b/app/retail/templates/emails/grant_txn_failed.txt @@ -0,0 +1,7 @@ +Grants transaction failed, try again? + + Your contribution to {{ grant_title }} failed due to a technical issue. + + Transaction ID: {{ tx_id }} + + View on Etherscan \ No newline at end of file diff --git a/app/retail/templates/emails/template.html b/app/retail/templates/emails/template.html index fb85fb71768..3fde588d817 100644 --- a/app/retail/templates/emails/template.html +++ b/app/retail/templates/emails/template.html @@ -323,6 +323,33 @@ } } + + .etherscan-link { + display: inline-block; + font-family: 'Muli', sans-serif; + color: #3E00FF; + } + + .grant-txn-msg, .grant-txn-id { + margin: 0 auto; + } + + .grant-txn-id a { + overflow-wrap: break-word; + } + + @media (min-width: 768px) { + .grant-txn-msg { + width: 70%; + } + } + + @media (min-width: 1200px) { + .grant-txn-msg { + width: 60%; + } + } + /* Bootstrap styles used for activities -- START */ *, From 9486ad949d5b7e7efe8010136b1ba1639b15efbd Mon Sep 17 00:00:00 2001 From: Sebastian T F Date: Sat, 6 Jun 2020 19:55:21 +0530 Subject: [PATCH 4/7] management command for grant_txn_failed_email --- .../commands/grant_txn_failed_email.py | 32 +++++++++++++++++++ app/marketing/mails.py | 21 +++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 app/dashboard/management/commands/grant_txn_failed_email.py diff --git a/app/dashboard/management/commands/grant_txn_failed_email.py b/app/dashboard/management/commands/grant_txn_failed_email.py new file mode 100644 index 00000000000..cea356c3898 --- /dev/null +++ b/app/dashboard/management/commands/grant_txn_failed_email.py @@ -0,0 +1,32 @@ +''' + Copyright (C) 2019 Gitcoin Core + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +''' +from django.conf import settings +from django.core.management.base import BaseCommand + +from grants.models import Contribution +from marketing.mails import grant_txn_failed + + +class Command(BaseCommand): + help = 'sends emails for grant contributors whose contribution txns have failed' + + def handle(self, *args, **options): + if settings.DEBUG: + print("not active in non prod environments") + return + + failed_contribs = Contribution.objects.exclude(validator_passed=True) + + for failed_contrib in failed_contribs: + grant_txn_failed(failed_contrib.subscription.contributor_profile, failed_contrib.subscription.grant, failed_contrib.tx_id) diff --git a/app/marketing/mails.py b/app/marketing/mails.py index 99ba2fb662e..a36d3bdd938 100644 --- a/app/marketing/mails.py +++ b/app/marketing/mails.py @@ -36,7 +36,7 @@ render_bounty_expire_warning, render_bounty_feedback, render_bounty_request, render_bounty_startwork_expire_warning, render_bounty_unintersted, render_comment, render_faucet_rejected, render_faucet_request, render_featured_funded_bounty, render_funder_payout_reminder, render_funder_stale, render_gdpr_reconsent, - render_gdpr_update, render_grant_cancellation_email, render_grant_recontribute, render_grant_update, + render_gdpr_update, render_grant_cancellation_email, render_grant_recontribute, render_grant_txn_failed, render_grant_update, render_kudos_email, render_match_distribution, render_match_email, render_mention, render_new_bounty, render_new_bounty_acceptance, render_new_bounty_rejection, render_new_bounty_roundup, render_new_grant_email, render_new_supporter_email, render_new_work_submission, render_no_applicant_reminder, render_nth_day_email_campaign, @@ -288,6 +288,25 @@ def grant_cancellation(grant, subscription): finally: translation.activate(cur_language) +def grant_txn_failed(profile, grant, tx_id): + from_email = settings.CONTACT_EMAIL + to_email = profile.email + if not to_email: + if profile and profile.user: + to_email = profile.user.email + if not to_email: + return + + cur_language = translation.get_language() + + subject = f"Your Grant transaction failed. Wanna try again?" + + try: + setup_lang(to_email) + html, text = render_grant_txn_failed(to_email, grant, tx_id) + send_mail(from_email, to_email, subject, text, html, categories=['transactional', func_name()]) + finally: + translation.activate(cur_language) def subscription_terminated(grant, subscription): if subscription and subscription.negative: From 2f60d92a366a00b424493b529c95be83a072e95f Mon Sep 17 00:00:00 2001 From: Sebastian T F Date: Wed, 17 Jun 2020 11:39:53 +0530 Subject: [PATCH 5/7] fix missing returns after resolving conflicts --- app/retail/emails.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/retail/emails.py b/app/retail/emails.py index 8906bbe4a27..ff0c670489e 100644 --- a/app/retail/emails.py +++ b/app/retail/emails.py @@ -885,6 +885,9 @@ def render_grant_recontribute(to_email, prev_round_start=(2020, 3, 23), prev_rou response_html = premailer_transform(render_to_string("emails/grant_recontribute.html", params)) response_txt = render_to_string("emails/grant_recontribute.txt", params) + + return response_html, response_txt + def render_grant_txn_failed(to_email, grant, tx_id): email_style = 27 @@ -1388,6 +1391,8 @@ def grant_update(request): @staff_member_required def grant_recontribute(request): response_html, _ = render_grant_recontribute(settings.CONTACT_EMAIL) + return HttpResponse(response_html) + def grant_txn_failed(request): failed_contrib = Contribution.objects.filter(subscription__contributor_profile__user__email=settings.CONTACT_EMAIL).exclude(validator_passed=True).first() response_html, _ = render_grant_txn_failed(settings.CONTACT_EMAIL, failed_contrib.subscription.grant, failed_contrib.tx_id) From 902f5486a51fe028c83439595fa614a38c036094 Mon Sep 17 00:00:00 2001 From: Sebastian T F Date: Tue, 23 Jun 2020 17:37:12 +0530 Subject: [PATCH 6/7] add bulk_add_url --- app/retail/emails.py | 2 ++ app/retail/templates/emails/grant_txn_failed.html | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/retail/emails.py b/app/retail/emails.py index ff0c670489e..3b7f70db64a 100644 --- a/app/retail/emails.py +++ b/app/retail/emails.py @@ -892,9 +892,11 @@ def render_grant_txn_failed(to_email, grant, tx_id): email_style = 27 params = { + 'id': grant.id, 'grant_title': grant.title, 'tx_id': tx_id, 'tx_url': "https://etherscan.io/tx/"+tx_id, + 'bulk_add_url': "https://gitcoin.co/grants/cart/bulk-add/" + str(grant.id), 'email_style': email_style, 'hide_bottom_logo': True, } diff --git a/app/retail/templates/emails/grant_txn_failed.html b/app/retail/templates/emails/grant_txn_failed.html index 5ae302ee7a0..152691e222f 100644 --- a/app/retail/templates/emails/grant_txn_failed.html +++ b/app/retail/templates/emails/grant_txn_failed.html @@ -35,7 +35,7 @@

Grants transaction failed, try again?

From e444c77057a3ebcb39b4e2b78cc116288ef9479f Mon Sep 17 00:00:00 2001 From: Sebastian T F Date: Tue, 23 Jun 2020 17:46:16 +0530 Subject: [PATCH 7/7] move email specific style to grant_txn_failed.html --- .../templates/emails/grant_txn_failed.html | 16 ++++++++++++++++ app/retail/templates/emails/template.html | 15 --------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/app/retail/templates/emails/grant_txn_failed.html b/app/retail/templates/emails/grant_txn_failed.html index 152691e222f..be3b3d837c5 100644 --- a/app/retail/templates/emails/grant_txn_failed.html +++ b/app/retail/templates/emails/grant_txn_failed.html @@ -19,6 +19,22 @@ {% block content %} + +

Grants transaction failed, try again?

diff --git a/app/retail/templates/emails/template.html b/app/retail/templates/emails/template.html index 3fde588d817..78288e1f1f7 100644 --- a/app/retail/templates/emails/template.html +++ b/app/retail/templates/emails/template.html @@ -323,21 +323,6 @@ } } - - .etherscan-link { - display: inline-block; - font-family: 'Muli', sans-serif; - color: #3E00FF; - } - - .grant-txn-msg, .grant-txn-id { - margin: 0 auto; - } - - .grant-txn-id a { - overflow-wrap: break-word; - } - @media (min-width: 768px) { .grant-txn-msg { width: 70%;