From 62684db6815ff89346b219c46151199cb671e3bc Mon Sep 17 00:00:00 2001 From: aamustapha Date: Fri, 18 Dec 2020 11:25:14 +0100 Subject: [PATCH 1/8] Include description in URL params --- app/assets/v2/js/grants/_new.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/assets/v2/js/grants/_new.js b/app/assets/v2/js/grants/_new.js index 457391294cf..dc8eb2859d6 100644 --- a/app/assets/v2/js/grants/_new.js +++ b/app/assets/v2/js/grants/_new.js @@ -375,6 +375,7 @@ if (document.getElementById('gc-new-grant')) { const writeToRoot = ['chainId']; const writeToBody = [ 'title', + 'description_rich', 'reference_url', 'twitter_handle_1', 'twitter_handle_2', From 4eec6b146de71d2976ef6a1abfb91b3f7744fb57 Mon Sep 17 00:00:00 2001 From: aamustapha Date: Fri, 18 Dec 2020 11:51:52 +0100 Subject: [PATCH 2/8] Add URL params to prefill grant --- app/dashboard/templates/project/detail/info.html | 1 + 1 file changed, 1 insertion(+) diff --git a/app/dashboard/templates/project/detail/info.html b/app/dashboard/templates/project/detail/info.html index afa579df0e5..9c438c16ce8 100644 --- a/app/dashboard/templates/project/detail/info.html +++ b/app/dashboard/templates/project/detail/info.html @@ -50,6 +50,7 @@ {% endif %} {% if is_member %} + CONVERT TO GRANT {% endif %} From 98e53755b3ee8f1ff87a82a44db4c338d2c2cd9c Mon Sep 17 00:00:00 2001 From: aamustapha Date: Fri, 18 Dec 2020 12:20:16 +0100 Subject: [PATCH 3/8] Add created to hackathon project when convert2grant button used. --- app/grants/views.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/grants/views.py b/app/grants/views.py index 066e057a87b..82e7e9aa8c5 100644 --- a/app/grants/views.py +++ b/app/grants/views.py @@ -33,7 +33,7 @@ from django.contrib.contenttypes.models import ContentType from django.contrib.humanize.templatetags.humanize import intword, naturaltime from django.core.paginator import EmptyPage, Paginator -from django.db import connection +from django.db import connection, transaction from django.db.models import Avg, Count, Max, Q, Subquery from django.http import Http404, HttpResponse, JsonResponse from django.shortcuts import get_object_or_404, redirect @@ -1656,6 +1656,7 @@ def grant_new_whitelabel(request): @login_required +@transaction.atomic def grant_new(request): """Handle new grant.""" @@ -1761,6 +1762,13 @@ def grant_new(request): grant = Grant.objects.create(**grant_kwargs) + hackathon_project_id = request.GET.get('related_hackathon_project_id') + if hackathon_project_id: + hackathon_project = HackathonProject.objects.filter(id=hackathon_project_id).first() + if hackathon_project: + hackathon_project.grant_obj = grant + hackathon_project.save() + team_members = (team_members[0].split(',')) team_members.append(profile.id) team_members = list(set(team_members)) From e0a6ec18ff0477c72ee081da2e9fde0c197906cd Mon Sep 17 00:00:00 2001 From: aamustapha Date: Fri, 18 Dec 2020 12:20:46 +0100 Subject: [PATCH 4/8] Add related hackathon project to URL get params when using convert to grant --- app/assets/v2/js/grants/_new.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/assets/v2/js/grants/_new.js b/app/assets/v2/js/grants/_new.js index dc8eb2859d6..38e6016a256 100644 --- a/app/assets/v2/js/grants/_new.js +++ b/app/assets/v2/js/grants/_new.js @@ -184,8 +184,10 @@ Vue.mixin({ 'X-CSRFToken': $("input[name='csrfmiddlewaretoken']").val() }; - const apiUrlGrant = '/grants/new'; - + let apiUrlGrant = '/grants/new'; + if (vm.queryParams.get('related_hackathon_project_id')) { + apiUrlGrant += `?related_hackathon_project_id=${vm.queryParams.get('related_hackathon_project_id')}` + } $.ajax({ type: 'post', url: apiUrlGrant, @@ -382,6 +384,7 @@ if (document.getElementById('gc-new-grant')) { 'github_project_url', 'eth_payout_address', 'grant_type', + 'team_members', 'grant_categories' ]; From 9529544c83f83a0b365c2d7629e73fdf5c33dbd5 Mon Sep 17 00:00:00 2001 From: aamustapha Date: Fri, 18 Dec 2020 12:25:28 +0100 Subject: [PATCH 5/8] Prevent unauthorized convert2grant --- app/grants/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/grants/views.py b/app/grants/views.py index 82e7e9aa8c5..d5c1fc1ed26 100644 --- a/app/grants/views.py +++ b/app/grants/views.py @@ -1765,7 +1765,7 @@ def grant_new(request): hackathon_project_id = request.GET.get('related_hackathon_project_id') if hackathon_project_id: hackathon_project = HackathonProject.objects.filter(id=hackathon_project_id).first() - if hackathon_project: + if hackathon_project and hackathon_project.profiles.filter(pk=profile.id).exists(): hackathon_project.grant_obj = grant hackathon_project.save() From 198889749f0c894f93a6e287786ca39214a43984 Mon Sep 17 00:00:00 2001 From: aamustapha Date: Fri, 18 Dec 2020 14:28:25 +0100 Subject: [PATCH 6/8] Hide convert grant button if already created. --- app/dashboard/templates/project/detail/info.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/dashboard/templates/project/detail/info.html b/app/dashboard/templates/project/detail/info.html index 9c438c16ce8..81e27a5592e 100644 --- a/app/dashboard/templates/project/detail/info.html +++ b/app/dashboard/templates/project/detail/info.html @@ -50,7 +50,9 @@ {% endif %} {% if is_member %} - CONVERT TO GRANT + {% if not project_obj.grant_url %} + CONVERT TO GRANT + {% endif %} {% endif %} From d2b3cc354ec983bbb7d8e5b59f200f67e201ee95 Mon Sep 17 00:00:00 2001 From: aamustapha Date: Fri, 18 Dec 2020 14:29:16 +0100 Subject: [PATCH 7/8] Ignore dist folder --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index dfb30a1bcae..cda64499fcb 100644 --- a/.gitignore +++ b/.gitignore @@ -51,3 +51,4 @@ app/cache/ # Autogenerated Documentation _build/ **/.vs +**/dist From 1da3f2857c1c7f5ee48b3202dc78b501cbda94ee Mon Sep 17 00:00:00 2001 From: aamustapha Date: Sat, 19 Dec 2020 21:14:24 +0100 Subject: [PATCH 8/8] Make grant creation work on matic page --- app/assets/v2/js/grants/new.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/assets/v2/js/grants/new.js b/app/assets/v2/js/grants/new.js index a6ccbac6ee9..859148b0761 100644 --- a/app/assets/v2/js/grants/new.js +++ b/app/assets/v2/js/grants/new.js @@ -204,10 +204,15 @@ function saveGrant(grantData, isFinal) { let csrftoken = $("#create-grant input[name='csrfmiddlewaretoken']").val(); $('#new_button').attr('disabled', 'disabled'); + let newGrantURL = '/grants/new'; + const queryParams = new URLSearchParams(window.location.search) + if (queryParams.get('related_hackathon_project_id')) { + newGrantURL += `?related_hackathon_project_id=${queryParams.get('related_hackathon_project_id')}` + } $.ajax({ type: 'post', - url: '/grants/new', + url: newGrantURL, processData: false, contentType: false, data: grantData,