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 29, 2019
1 parent 18a0352 commit 747c45e
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 8 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
22 changes: 19 additions & 3 deletions app/marketing/mails.py
Original file line number Diff line number Diff line change
Expand Up @@ -1096,9 +1096,13 @@ def new_bounty_request(model):
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"
body_str = _("New Gitcoin bounty funding request from")
body = f"{body_str} {model.requested_by.github_url}: \n\n"\
f"Link to the issue: {model.github_url}. \nThe user proposes funding of {model.amount} (USD) "\
f"and has attached the following comment along with the funding request:\n \"{model.comment}\".\n\n "\
f"Should you wish to fund the aforementioned issue, you can follow this URL:\n\n "\
f"{settings.BASE_URL}bounty/new?invite={model.requested_by.pk}&source={model.github_url}"

send_mail(
from_email,
to_email,
Expand All @@ -1107,6 +1111,18 @@ def new_bounty_request(model):
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,
body,
from_name=_("No Reply from Gitcoin.co"),
categories=['admin', 'new_bounty_request'],
)
finally:
translation.activate(cur_language)

Expand Down

0 comments on commit 747c45e

Please sign in to comment.