diff --git a/app/assets/v2/js/pages/bounty_request_form.js b/app/assets/v2/js/pages/bounty_request_form.js index 2c29be53022..a1347c04935 100644 --- a/app/assets/v2/js/pages/bounty_request_form.js +++ b/app/assets/v2/js/pages/bounty_request_form.js @@ -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'); diff --git a/app/bounty_requests/forms.py b/app/bounty_requests/forms.py index 3586feefc77..e38e5370367 100644 --- a/app/bounty_requests/forms.py +++ b/app/bounty_requests/forms.py @@ -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) diff --git a/app/bounty_requests/migrations/0003_bountyrequest_github_org_name.py b/app/bounty_requests/migrations/0003_bountyrequest_github_org_name.py new file mode 100644 index 00000000000..52877ca73a6 --- /dev/null +++ b/app/bounty_requests/migrations/0003_bountyrequest_github_org_name.py @@ -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), + ), + ] diff --git a/app/bounty_requests/migrations/0004_bountyrequest_github_org_email.py b/app/bounty_requests/migrations/0004_bountyrequest_github_org_email.py new file mode 100644 index 00000000000..b2480fc386f --- /dev/null +++ b/app/bounty_requests/migrations/0004_bountyrequest_github_org_email.py @@ -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), + ), + ] diff --git a/app/bounty_requests/models.py b/app/bounty_requests/models.py index c47f41c351a..1017acb8a82 100644 --- a/app/bounty_requests/models.py +++ b/app/bounty_requests/models.py @@ -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): diff --git a/app/bounty_requests/views.py b/app/bounty_requests/views.py index 34195a86531..d0825a10ed4 100644 --- a/app/bounty_requests/views.py +++ b/app/bounty_requests/views.py @@ -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 @@ -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) diff --git a/app/dashboard/templates/dashboard/index.html b/app/dashboard/templates/dashboard/index.html index 0f70b8a6b08..234c2d2c85d 100644 --- a/app/dashboard/templates/dashboard/index.html +++ b/app/dashboard/templates/dashboard/index.html @@ -96,7 +96,12 @@