From 543988a420bd89f6f82220b86963455d488c2751 Mon Sep 17 00:00:00 2001 From: Pierrick TURELIER Date: Tue, 30 Jul 2019 14:59:08 +0200 Subject: [PATCH 1/2] Add button to sync Github issue --- app/assets/v2/js/pages/bounty_details.js | 87 ++++++++++++++++----- app/dashboard/templates/bounty/details.html | 2 + app/dashboard/views.py | 29 +++---- 3 files changed, 83 insertions(+), 35 deletions(-) diff --git a/app/assets/v2/js/pages/bounty_details.js b/app/assets/v2/js/pages/bounty_details.js index def1efb4140..8255e9ef5c2 100644 --- a/app/assets/v2/js/pages/bounty_details.js +++ b/app/assets/v2/js/pages/bounty_details.js @@ -858,6 +858,57 @@ var show_extend_deadline_modal = function() { }); }; +const appendGithubSyncButton = function(result) { + if (isBountyOwner(result) || currentProfile.isStaff) { + const title = gettext('Sync Issue'); + + $('#github_actions').append(''); + + $('#github_actions [sync-github-issue]').on('click', function(e) { + const bountyId = result.pk; + + e.preventDefault(); + + $.get( + '/sync/get_issue_details?url=' + encodeURIComponent(result['github_url']) + '&token=' + currentProfile.githubToken + ).then(function(result) { + const payload = JSON.stringify({ + issue_description: result.description + }); + + return $.post('/bounty/change/' + bountyId, payload).then( + function(result) { + result = sanitizeAPIResults(result); + _alert({ message: result.msg }, 'success'); + + if (result.url) { + setTimeout(function() { + document.location.href = result.url; + }, 1000); + } + } + ).fail( + function(result) { + var alertMsg = result && result.responseJSON ? result.responseJSON.error : null; + + if (alertMsg === null) { + alertMsg = gettext('Failed to sync issue. Please reload the page and try again.'); + } + _alert({ message: alertMsg }, 'error'); + } + ); + }).fail(function(result) { + var alertMsg = result && result.responseJSON ? result.responseJSON.error : null; + + if (alertMsg === null) { + alertMsg = gettext('Failed to sync issue. Please reload the page and try again.'); + } + _alert({ message: alertMsg }, 'error'); + }); + }); + } +}; + var build_detail_page = function(result) { // setup @@ -932,6 +983,7 @@ var build_detail_page = function(result) { }); $('#bounty_details #issue_description code').parent().addClass('code-snippet'); + appendGithubSyncButton(result); }; const is_current_user_interested = function(result) { @@ -1027,7 +1079,7 @@ var do_actions = function(result) { enabled: enabled, href: result['action_urls']['fulfill'], text: gettext('Submit Work'), - parent: 'right_actions', + parent: 'bounty_actions', title: gettext('Submit work for the funder to review'), work_started: is_interested, id: 'submit' @@ -1043,7 +1095,7 @@ var do_actions = function(result) { enabled: enabled, href: '#', text: gettext('Send Payment Reminder'), - parent: 'right_actions', + parent: 'bounty_actions', title: gettext('Send Payment Reminder'), id: 'notifyFunder', clickhandler: show_modal_handler(url), @@ -1066,7 +1118,7 @@ var do_actions = function(result) { enabled: enabled, href: is_interested ? '/uninterested' : '/interested', text: text, - parent: 'right_actions', + parent: 'bounty_actions', title: is_interested ? gettext('Notify the funder that you will not be working on this project') : gettext('Notify the funder that you would like to take on this project'), color: is_interested ? '' : '', id: 'interest' @@ -1081,7 +1133,7 @@ var do_actions = function(result) { enabled: enabled, href: result['action_urls']['cancel'], text: gettext('Cancel Bounty'), - parent: 'right_actions', + parent: 'bounty_actions', title: gettext('Cancel bounty and reclaim funds for this issue'), buttonclass: 'button--warning' }; @@ -1096,7 +1148,7 @@ var do_actions = function(result) { href: result['action_urls']['payout'], text: gettext('Payout Bounty'), title: gettext('Payout the bounty to one or more submitters.'), - parent: 'right_actions' + parent: 'bounty_actions' }; actions.push(_entry); @@ -1109,7 +1161,7 @@ var do_actions = function(result) { enabled: enabled, href: result['action_urls']['contribute'], text: gettext('Contribute'), - parent: 'right_actions', + parent: 'bounty_actions', title: gettext('Help by funding or promoting this issue') }; @@ -1122,7 +1174,7 @@ var do_actions = function(result) { enabled: enabled, href: '/extend-deadlines', text: gettext('Extend Expiration'), - parent: 'right_actions', + parent: 'bounty_actions', title: gettext('Extend deadline of an issue') }; @@ -1134,7 +1186,7 @@ var do_actions = function(result) { enabled: true, href: result['action_urls']['invoice'], text: gettext('Show Invoice'), - parent: 'right_actions', + parent: 'bounty_actions', title: gettext('View an Invoice for this Issue') }; @@ -1147,16 +1199,9 @@ var do_actions = function(result) { enabled: true, href: '/bounty/change/' + result['pk'], text: gettext('Edit Issue Details'), - parent: 'right_actions', + parent: 'bounty_actions', title: gettext('Update your Bounty Settings to get the right Crowd') - }// , - // { - // enabled: true, - // href: '/issue/refund_request?pk=' + result['pk'], - // text: gettext('Request Fee Refund'), - // parent: 'right_actions', - // title: gettext('Raise a request if you believe you need your fee refunded') - // } + } ]; actions.push(..._entry); @@ -1173,9 +1218,9 @@ var do_actions = function(result) { enabled: true, href: github_url, text: (result['repo_type'] === 'private' ? ' ' + - gettext('Private Repo') : gettext('View On Github')) + - (result['is_issue_closed'] ? gettext(' (Issue is closed)') : ''), - parent: 'right_actions', + gettext('Private Repo') : gettext('View On Github')) + + (result['is_issue_closed'] ? gettext(' (Issue is closed)') : ''), + parent: 'github_actions', title: gettext('View issue details and comments on Github'), comments: result['github_comments'], color: 'white' @@ -1191,7 +1236,7 @@ var do_actions = function(result) { enabled: true, href: job_url, text: gettext('View Attached Job Description'), - parent: 'right_actions', + parent: 'bounty_actions', title: gettext('This bounty funder is hiring for a full time, part time, or contract role and has attached that to this bounty.'), color: 'white' }; diff --git a/app/dashboard/templates/bounty/details.html b/app/dashboard/templates/bounty/details.html index 05f6e87d674..2d2a482472f 100644 --- a/app/dashboard/templates/bounty/details.html +++ b/app/dashboard/templates/bounty/details.html @@ -142,6 +142,8 @@

+
+
diff --git a/app/dashboard/views.py b/app/dashboard/views.py index 8750df7712c..ca11fb41e19 100644 --- a/app/dashboard/views.py +++ b/app/dashboard/views.py @@ -2594,7 +2594,7 @@ def change_bounty(request, bounty_id): else: raise Http404 - keys = ['experience_level', 'project_length', 'bounty_type', 'featuring_date', 'bounty_categories', + keys = ['experience_level', 'project_length', 'bounty_type', 'featuring_date', 'bounty_categories', 'issue_description', 'permission_type', 'project_type', 'reserved_for_user_handle', 'is_featured', 'admin_override_suspend_auto_approval'] if request.body: @@ -2621,18 +2621,19 @@ def change_bounty(request, bounty_id): new_reservation = False for key in keys: value = params.get(key, 0) - if key == 'featuring_date': - value = timezone.make_aware( - timezone.datetime.fromtimestamp(int(value)), - timezone=UTC) - if key == 'bounty_categories': - value = value.split(',') - old_value = getattr(bounty, key) - if value != old_value: - setattr(bounty, key, value) - bounty_changed = True - if key == 'reserved_for_user_handle' and value: - new_reservation = True + if value != 0: + if key == 'featuring_date': + value = timezone.make_aware( + timezone.datetime.fromtimestamp(int(value)), + timezone=UTC) + if key == 'bounty_categories': + value = value.split(',') + old_value = getattr(bounty, key) + if value != old_value: + setattr(bounty, key, value) + bounty_changed = True + if key == 'reserved_for_user_handle' and value: + new_reservation = True if not bounty_changed: return JsonResponse({ @@ -2838,7 +2839,7 @@ def change_user_profile_banner(request): profile.save() except (ProfileNotFoundException, ProfileHiddenException): raise Http404 - + response = { 'status': 200, 'message': 'User banner image has been updated.' From af7d995dcd947931af7cae7ad828e83dd8455731 Mon Sep 17 00:00:00 2001 From: Pierrick TURELIER Date: Wed, 31 Jul 2019 11:02:39 +0200 Subject: [PATCH 2/2] Update Github sync alert messages syntax --- app/assets/v2/js/pages/bounty_details.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/app/assets/v2/js/pages/bounty_details.js b/app/assets/v2/js/pages/bounty_details.js index 2f5407eb21a..cb50c052968 100644 --- a/app/assets/v2/js/pages/bounty_details.js +++ b/app/assets/v2/js/pages/bounty_details.js @@ -890,20 +890,14 @@ const appendGithubSyncButton = function(result) { } ).fail( function(result) { - var alertMsg = result && result.responseJSON ? result.responseJSON.error : null; + const alertMsg = result && result.responseJSON ? result.responseJSON.error : gettext('Failed to sync issue. Please reload the page and try again.'); - if (alertMsg === null) { - alertMsg = gettext('Failed to sync issue. Please reload the page and try again.'); - } _alert({ message: alertMsg }, 'error'); } ); }).fail(function(result) { - var alertMsg = result && result.responseJSON ? result.responseJSON.error : null; + const alertMsg = result && result.responseJSON ? result.responseJSON.error : gettext('Failed to sync issue. Please reload the page and try again.'); - if (alertMsg === null) { - alertMsg = gettext('Failed to sync issue. Please reload the page and try again.'); - } _alert({ message: alertMsg }, 'error'); }); });