Skip to content

Commit

Permalink
4695 - Bounty request when nothing has been found
Browse files Browse the repository at this point in the history
  • Loading branch information
vince0656 committed Sep 30, 2019
1 parent 099e37b commit 20c4955
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 21 deletions.
14 changes: 13 additions & 1 deletion app/assets/v2/js/pages/bounty_request_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,22 @@ $(document).ready(function() {
submitHandler: function(form) {
const inputElements = $(form).find(':input');
const formData = {};
let githubOrgName = '';

inputElements.removeAttr('disabled');
$.each($(form).serializeArray(), function() {
formData[this.name] = this.value;
if (this.name === 'github_url') {
formData['github_url'] = this.value;

const url = new URL(this.value);
const urlParts = url.pathname.split('/');

githubOrgName = urlParts[1] || '';
formData['github_org_name'] = githubOrgName;
} else if (this.name !== 'github_org_name') {
// Ignore 'github_org_name' value from the form as this is already handled 2 lines above
formData[this.name] = this.value;
}
});

inputElements.attr('disabled', 'disabled');
Expand Down
6 changes: 4 additions & 2 deletions app/bounty_requests/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ class BountyRequestForm(forms.ModelForm):

class Meta:
model = BountyRequest
fields = ['github_url', 'eth_address', 'amount', 'comment']
fields = ['github_url', 'eth_address', 'amount', 'comment', 'github_org_name']
labels = {
'eth_address': _('Your ETH Address (Optional)'),
'amount': _('Proposed Funding Amount (USD)'),
'comment': _('Comment')
'comment': _('Comment'),
'github_org_name': ''
}
widgets = {'github_org_name': forms.HiddenInput()}

def __init__(self, *args, **kwargs):
super(BountyRequestForm, self).__init__(*args, **kwargs)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.1.7 on 2019-09-24 20:22

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('bounty_requests', '0002_auto_20181226_1716'),
]

operations = [
migrations.AddField(
model_name='bountyrequest',
name='github_org_name',
field=models.CharField(default='', max_length=50),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.1.7 on 2019-09-24 20:57

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('bounty_requests', '0003_bountyrequest_github_org_name'),
]

operations = [
migrations.AddField(
model_name='bountyrequest',
name='github_org_email',
field=models.CharField(default='', max_length=255),
),
]
3 changes: 3 additions & 0 deletions app/bounty_requests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ class BountyRequest(SuperModel):
related_name='bounty_requests',
)
github_url = models.CharField(max_length=255, default='')
github_org_name = models.CharField(max_length=50, default='')
eth_address = models.CharField(max_length=50, blank=True)
comment = models.TextField(max_length=500, default='')
comment_admin = models.TextField(max_length=500, blank=True)
amount = models.FloatField(blank=False, validators=[MinValueValidator(1.0)])

github_org_email = models.CharField(max_length=255, default='')

objects = BountyQuerySet.as_manager()

def __str__(self):
Expand Down
10 changes: 10 additions & 0 deletions app/bounty_requests/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from django.utils.translation import gettext_lazy as _
from django.views.decorators.csrf import csrf_exempt

import requests
from linkshortener.models import Link
from marketing.mails import new_bounty_request
from ratelimit.decorators import ratelimit
Expand Down Expand Up @@ -60,7 +61,16 @@ def bounty_request(request):
return JsonResponse({'error': 'Invalid JSON.'}, status=400)

model = result.save(commit=False)

gh_org_api_url = 'https://api.github.com/orgs/' + model.github_org_name
gh_org_api_resp = requests.get(url=gh_org_api_url).json()

gh_org_email = ''
if gh_org_api_resp is not None and gh_org_api_resp['email'] is not None:
gh_org_email = gh_org_api_resp['email']

model.requested_by = profile
model.github_org_email = gh_org_email
model.save()
new_bounty_request(model)
return JsonResponse({'msg': _('Bounty Request received.')}, status=200)
Expand Down
9 changes: 7 additions & 2 deletions app/dashboard/templates/dashboard/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ <h1 class="font-bigger-1">Issue Explorer - Freelance Code Bounties</h1>
<div class="row nonefound mx-auto" style="display:none;">
<img src="{% static "v2/images/shrug_bot.png" %}" alt="Shrug bot">
<h3>{% trans "No results found." %}</h3>
<p>{% trans "Please try another query" %}</p>
<p>{% trans "Request an organisation to fund an issue" %}</p>
<div class="mt-3">
<a class="button button--primary white-txt" role="button" href="/requests">
{% trans "Request bounty" %}
</a>
</div>
</div>
{% include 'dashboard/featured_bounties.html' %}

Expand All @@ -121,7 +126,7 @@ <h3>{% trans "No results found." %}</h3>
{% include 'shared/analytics.html' %}
{% include 'shared/footer_scripts.html' %}
{% include 'shared/footer.html' %}


<script>
$('[data-toggle="popover"]').popover()
Expand Down
43 changes: 28 additions & 15 deletions app/marketing/mails.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@
from python_http_client.exceptions import HTTPError, UnauthorizedError
from retail.emails import (
render_admin_contact_funder, render_bounty_changed, render_bounty_expire_warning, render_bounty_feedback,
render_bounty_startwork_expire_warning, render_bounty_unintersted, 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_kudos_email, render_match_email, 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,
render_quarterly_stats, render_reserved_issue, render_share_bounty, render_start_work_applicant_about_to_expire,
render_start_work_applicant_expired, render_start_work_approved, render_start_work_new_applicant,
render_start_work_rejected, render_subscription_terminated_email, render_successful_contribution_email,
render_support_cancellation_email, render_thank_you_for_supporting_email, render_tip_email,
render_unread_notification_email_weekly_roundup, render_weekly_recap,
render_bounty_request, render_bounty_startwork_expire_warning, render_bounty_unintersted, 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_kudos_email, render_match_email,
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, render_quarterly_stats, render_reserved_issue, render_share_bounty,
render_start_work_applicant_about_to_expire, render_start_work_applicant_expired, render_start_work_approved,
render_start_work_new_applicant, render_start_work_rejected, render_subscription_terminated_email,
render_successful_contribution_email, render_support_cancellation_email, render_thank_you_for_supporting_email,
render_tip_email, render_unread_notification_email_weekly_roundup, render_weekly_recap,
)
from sendgrid.helpers.mail import Content, Email, Mail, Personalization
from sendgrid.helpers.stats import Category
Expand Down Expand Up @@ -1093,20 +1093,33 @@ def new_bounty_request(model):
to_email = '[email protected]'
from_email = model.requested_by.email or settings.SERVER_EMAIL
cur_language = translation.get_language()

try:
setup_lang(to_email)
subject = _("New Bounty Request")
body_str = _("New Bounty Request from")
body = f"{body_str} {model.requested_by}: "\
f"{settings.BASE_URL}_administrationbounty_requests/bountyrequest/{model.pk}/change"
html, text, subject = render_bounty_request(to_email, model, settings.BASE_URL)

send_mail(
from_email,
to_email,
subject,
body,
text,
html,
from_name=_("No Reply from Gitcoin.co"),
categories=['admin', 'new_bounty_request'],
)

if model.github_org_email != '':
to_email = model.github_org_email
setup_lang(to_email)
send_mail(
from_email,
to_email,
subject,
text,
html,
from_name=_("No Reply from Gitcoin.co"),
categories=['admin', 'new_bounty_request'],
)
finally:
translation.activate(cur_language)

Expand Down
14 changes: 13 additions & 1 deletion app/retail/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,18 @@ def render_reserved_issue(to_email, user, bounty):
return response_html, response_txt, subject


def render_bounty_request(to_email, model, base_url):
params = {
'subscriber': get_or_save_email_subscriber(to_email, 'internal'),
'model': model,
'base_url': base_url
}
subject = _("New Bounty Request")
response_html = premailer_transform(render_to_string("emails/bounty_request.html", params))
response_txt = render_to_string("emails/bounty_request.txt", params)
return response_html, response_txt, subject


def render_start_work_approved(interest, bounty):
to_email = interest.profile.email
params = {
Expand Down Expand Up @@ -932,7 +944,7 @@ def render_new_bounty_roundup(to_email):
</p>
'''
highlights = [{
'who': 'mirshko',
'who': 'mirshko',
'who_link': True,
'what': 'Fix Metadata For Subpages',
'link': 'https://gitcoin.co/issue/centrifuge/website/144/3449',
Expand Down
34 changes: 34 additions & 0 deletions app/retail/templates/emails/bounty_request.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{% 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 %}
{% load static %}
{% block content %}
<h1>{% trans "New Bounty Request" %}</h1>
<div style="text-align: left! important">
<p>{% trans "New Gitcoin bounty funding request from" %} {{model.requested_by.github_url}}:</p>
<br/>
<p>{% trans "Link to the issue" %}: {{model.github_url}}.</p>
<br/>
<p>{% trans "The user proposes funding of" %} {{model.amount}} ({% trans "USD" %}) {% trans "and has attached the following comment along with the funding request" %}:</p>
<p>"{{model.comment}}"</p>
<br/>
<p>{% trans "Should you wish to fund the aforementioned issue, you can follow this URL" %}:</p>
<a href="{{base_url}}bounty/new?invite={{model.requested_by.pk}}&source={{model.github_url}}">{{base_url}}bounty/new?invite={{model.requested_by.pk}}&source={{model.github_url}}</a>
</div>
{% endblock %}
9 changes: 9 additions & 0 deletions app/retail/templates/emails/bounty_request.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
New Gitcoin bounty funding request from {{model.requested_by.github_url}}}:

Link to the issue: {{model.github_url}}.

The user proposes funding of {{model.amount}} (USD) and has attached the following comment along with the funding request:
"{{model.comment}}"

Should you wish to fund the aforementioned issue, you can follow this URL:
{{settings.BASE_URL}}bounty/new?invite={{model.requested_by.pk}}&source={{model.github_url}}

0 comments on commit 20c4955

Please sign in to comment.