Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Grants txn Failed Email #6791

Merged
merged 7 commits into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
32 changes: 32 additions & 0 deletions app/dashboard/management/commands/grant_txn_failed_email.py
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
'''
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)
21 changes: 20 additions & 1 deletion app/marketing/mails.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
24 changes: 24 additions & 0 deletions app/retail/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')),
]


Expand Down Expand Up @@ -887,6 +888,24 @@ def render_grant_recontribute(to_email, prev_round_start=(2020, 3, 23), prev_rou

return response_html, response_txt

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for the future: we'll have to update this to use other block explorers once we support other chains

'bulk_add_url': "https://gitcoin.co/grants/cart/bulk-add/" + str(grant.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

def render_wallpost(to_email, activity):
params = {
'activity': activity,
Expand Down Expand Up @@ -1375,6 +1394,11 @@ def grant_update(request):
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)
return HttpResponse(response_html)

@staff_member_required
def wallpost(request):
Expand Down
59 changes: 59 additions & 0 deletions app/retail/templates/emails/grant_txn_failed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{% 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 <http://www.gnu.org/licenses/>.
{% endcomment %}
{% load i18n humanize %}

{% block content %}

<style>
.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;
}
</style>

<h1>Grants transaction failed, try again?</h1>

<div class="grant-txn-msg">
<p>
Your contribution to <b>{{ grant_title }}</b> failed due to a technical issue.
</p>
</div>

<div class="grant-txn-id">
<p>
Transaction ID: <br>
<a href="{{ tx_url }}">{{ tx_id }}</a>
</p>
</div>

<div style="margin-bottom: 3em; margin-top: 3em;">
<a class="button" href="{{ bulk_add_url }}">{% trans "Resubmit Transaction" %}</a>
<br>
<a class="etherscan-link" href="{{ tx_url }}">View on Etherscan</a>
</div>

{% endblock %}
7 changes: 7 additions & 0 deletions app/retail/templates/emails/grant_txn_failed.txt
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions app/retail/templates/emails/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,18 @@
}
}

@media (min-width: 768px) {
.grant-txn-msg {
width: 70%;
}
}

@media (min-width: 1200px) {
.grant-txn-msg {
width: 60%;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ could we move this to the needed email files!
Else it would be imported by every mail

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thelostone-mc Gmail seems to have an issue while using media queries in emails. It only considers the first set of media queries it sees and ignores media queries seen anywhere else afterwards. I found this behaviour while working on the daily email redesign and also found on the Internet that others have experienced this behaviour too.

The workaround is to include all the media queries in the first place (first <style> tag) and that would be the one in template.html. This is why the media queries and the corresponding styles are all placed in template.html itself.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay that makes sense !
But if by placing it here, wouldn't every other email which has media query styles not be applied (not sure if there are other mails which get affected by this )

If we are doing this, we should collect it from all emails and add that in

Could we move these though into the grant specific mail ?

  .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;
  }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay that makes sense !
But if by placing it here, wouldn't every other email which has media query styles not be applied (not sure if there are other mails which get affected by this )

If we are doing this, we should collect it from all emails and add that in

Could we move these though into the grant specific mail ?

  .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;
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we move these though into the grant specific mail ?

  .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;
  }

@thelostone-mc Done in e444c77

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay that makes sense !
But if by placing it here, wouldn't every other email which has media query styles not be applied (not sure if there are other mails which get affected by this )

If we are doing this, we should collect it from all emails and add that in

I do doubt that the media query styles present inside specific email templates are actually being rendered correctly by Gmail. That may have to be tested and taken care of. But the commits in this PR wont affect the other emails.


/* Bootstrap styles used for activities -- START */

*,
Expand Down