Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow crowdfund issues #1597

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@
path('issue/accept', dashboard.views.accept_bounty, name='process_funding'),
path('issue/increase', dashboard.views.increase_bounty, name='increase_bounty'),
path('issue/cancel', dashboard.views.cancel_bounty, name='kill_bounty'),
path(
'issue/increase/changepayout/<int:amount>',
dashboard.views.request_change_payout_amount,
name='request_change_payout'
),

# Avatars
path('avatar/', include('avatar.urls', namespace='avatar')),
Expand Down
4 changes: 1 addition & 3 deletions app/assets/v2/js/pages/bounty_details.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,6 @@ var do_actions = function(result) {
var kill_bounty_enabled = isBountyOwner(result);
var submit_work_enabled = !isBountyOwner(result);
var start_stop_work_enabled = !isBountyOwner(result);
var increase_bounty_enabled = isBountyOwner(result);
var show_accept_submission = isBountyOwner(result) && !is_status_expired && !is_status_done;
var show_suspend_auto_approval = document.isStaff && result['permission_type'] == 'approval';
var show_admin_methods = document.isStaff;
Expand Down Expand Up @@ -662,9 +661,8 @@ var do_actions = function(result) {
}

if (show_increase_bounty) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't you need to update show_increase_bounty too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it needed? what I change here is the argument from enabled = increase_bounty_enabled; to enabled = true;, the show_increase_bounty is fine.

var enabled = increase_bounty_enabled;
var _entry = {
enabled: enabled,
enabled: true,
href: result['action_urls']['increase'],
text: gettext('Add Contribution'),
parent: 'right_actions',
Expand Down
45 changes: 40 additions & 5 deletions app/assets/v2/js/pages/increase_bounty.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ $(document).ready(function() {
mixpanel.track('Submit New Bounty Success', {});
document.location.href = '/funding/details/?url=' + issueURL;
}, 1000);

if (document.changePayoutAmount) {
$.get('/issue/increase/changepayout/' + amount + '/?pk=' + bountyId + '&network=' + document.web3network);
}
}

var bountyAmount = parseInt($('input[name=valueInToken]').val(), 10);
Expand All @@ -123,17 +127,27 @@ $(document).ready(function() {
if (bountyAmount == 0 || open == false) {
errormsg = gettext('No active funded issue found at this address on ' + document.web3network + '. Are you sure this is an active funded issue?');
}
if (fromAddress != web3.eth.coinbase) {
errormsg = gettext('Only the address that submitted this funded issue may increase the payout.');
}

if (errormsg) {
_alert({ message: errormsg });
unloading_button($('#submitBounty'));
return;
}

function do_bounty() {
function do_bounty_as_funder_changingFulfillment() {
bounty.changeBountyFulfillmentAmount(
bountyId,
bountyAmount + amount,
{
from: account,
value: 0,
gasPrice: web3.toHex($('#gasPrice').val() + Math.pow(10, 9))
},
web3Callback
);
}

function do_bounty_as_funder_increasingPayout() {
bounty.increasePayout(
bountyId,
bountyAmount + amount,
Expand All @@ -147,7 +161,28 @@ $(document).ready(function() {
);
}

do_bounty();
function do_bounty_as_contributor() {
bounty.contribute(
bountyId,
amount,
{
from: account,
value: ethAmount,
gasPrice: web3.toHex($('#gasPrice').val() + Math.pow(10, 9))
},
web3Callback
);
}

if (document.isFunder) {
if (document.changePayoutAmount) {
do_bounty_as_funder_increasingPayout();
} else {
do_bounty_as_funder_changingFulfillment();
}
} else {
do_bounty_as_contributor();
}

});
});
5 changes: 5 additions & 0 deletions app/dashboard/templates/increase_bounty.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ <h3>Increase Funding</h3>
</body>


<script>
document.isFunder = '{{is_funder}}' != 'False';
document.changePayoutAmount = '{{change_payout_amount}}' != 'False';
</script>

<!-- jQuery -->
<script src="{% static "v2/js/ipfs-api.js" %}"></script>
<script src="{% static "v2/js/ipfs.js" %}"></script>
Expand Down
30 changes: 28 additions & 2 deletions app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
get_auth_url, get_github_emails, get_github_primary_email, get_github_user_data, is_github_token_valid,
)
from marketing.mails import (
admin_contact_funder, bounty_uninterested, start_work_approved, start_work_new_applicant, start_work_rejected,
admin_contact_funder, bounty_uninterested, change_payout_amount, start_work_approved, start_work_new_applicant,
start_work_rejected,
admin_contact_funder, bounty_uninterested, start_work_approved, start_work_new_applicant, start_work_rejected
)
from marketing.models import Keyword
from ratelimit.decorators import ratelimit
Expand Down Expand Up @@ -665,13 +667,27 @@ def increase_bounty(request):

"""
bounty = handle_bounty_views(request)
user = request.user if request.user.is_authenticated else None
if user:
is_funder = bounty.is_funder(user.username.lower())
else:
is_funder = False

params = get_context(
ref_object=bounty,
user=request.user if request.user.is_authenticated else None,
user=user,
confirm_time_minutes_target=confirm_time_minutes_target,
active='increase_bounty',
title=_('Increase Bounty'),
)
change_payout_amount = request.GET.get('change_payout_amount')
if change_payout_amount:
params['change_payout_amount'] = change_payout_amount
else:
params['change_payout_amount'] = False

params['is_funder'] = is_funder

return TemplateResponse(request, 'increase_bounty.html', params)


Expand Down Expand Up @@ -1123,6 +1139,16 @@ def sync_web3(request):
return JsonResponse(result, status=result['status'])


def request_change_payout_amount(request, amount):
bounty = handle_bounty_views(request)
change_payout_amount(bounty, amount)
result = {
'status': '200',
'msg': 'email sent'
}

return JsonResponse(result, status=result['status'])

# LEGAL

def terms(request):
Expand Down
20 changes: 19 additions & 1 deletion app/marketing/mails.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@
from python_http_client.exceptions import HTTPError, UnauthorizedError
from retail.emails import (
render_admin_contact_funder, render_bounty_expire_warning, render_bounty_feedback,
render_bounty_startwork_expire_warning, render_bounty_unintersted, render_change_payout_amount,
render_faucet_rejected, render_faucet_request, render_gdpr_reconsent, render_gdpr_update, render_match_email,
render_new_bounty, render_new_bounty_acceptance, render_new_bounty_rejection, render_new_bounty_roundup,
render_new_work_submission, render_quarterly_stats, 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_tip_email,
render_bounty_startwork_expire_warning, render_bounty_unintersted, render_faucet_rejected, render_faucet_request,
render_gdpr_reconsent, render_gdpr_update, render_match_email, render_new_bounty, render_new_bounty_acceptance,
render_new_bounty_rejection, render_new_bounty_roundup, render_new_work_submission, render_quarterly_stats,
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_tip_email,
render_start_work_new_applicant, render_start_work_rejected, render_tip_email, render_change_payout_amount
)
from sendgrid.helpers.mail import Content, Email, Mail, Personalization

Expand Down Expand Up @@ -552,6 +558,18 @@ def start_work_applicant_expired(interest, bounty):
translation.activate(cur_language)


def change_payout_amount(bounty, value):
from_email = settings.CONTACT_EMAIL
to_email = bounty.bounty_owner_email
cur_language = translation.get_language()
try:
setup_lang(to_email)
text, subject = render_change_payout_amount(bounty, value)
send_mail(from_email, to_email, subject, text)
finally:
translation.activate(cur_language)


def setup_lang(to_email):
"""Activate the User's language preferences based on their email address.

Expand Down
11 changes: 11 additions & 0 deletions app/retail/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from django.shortcuts import redirect
from django.template.loader import render_to_string
from django.template.response import TemplateResponse
from django.urls import reverse
from django.utils import timezone
from django.utils.translation import gettext as _

Expand Down Expand Up @@ -588,6 +589,16 @@ def render_new_bounty_roundup(to_email):
return response_html, response_txt, subject


def render_change_payout_amount(bounty, value):
subject = 'Change payout amount'
form_link = reverse('request_change_payout', kwargs={'value': value, 'pk': bounty.id, 'network': bounty.network})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F841 local variable 'form_link' is assigned to but never used


response_text = """There is someone trying to increase the bounty on {value} on your issue,
can you change the payout amount of the bounty? The form to do it: {form_link}. You can
increase the payout amount in the value {value}."""

return response_text, subject

# DJANGO REQUESTS


Expand Down