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

Action URLS Cleanup (and other goodies) #983

Merged
merged 16 commits into from
Apr 26, 2018
Merged
31 changes: 20 additions & 11 deletions app/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,35 +66,46 @@

url(r'^dashboard/?', dashboard.views.dashboard, name='dashboard'),
url(r'^explorer/?', dashboard.views.dashboard, name='explorer'),

# action URLs
url(r'^bounty/new/?', dashboard.views.new_bounty, name='new_bounty'),
url(r'^funding/new/?', dashboard.views.new_bounty, name='new_funding'),
url(r'^new/?', dashboard.views.new_bounty, name='new_funding_short'),
re_path(r'^issue/fulfill/(?P<pk>.*)?', dashboard.views.fulfill_bounty, name='fulfill_bounty'),
re_path(r'^issue/accept/(?P<pk>.*)?', dashboard.views.accept_bounty, name='process_funding'),
re_path(r'^issue/increase/(?P<pk>.*)?', dashboard.views.increase_bounty, name='increase_bounty'),
re_path(r'^issue/cancel/(?P<pk>.*)?', dashboard.views.cancel_bounty, name='kill_bounty'),

# Interests
path('actions/bounty/<int:bounty_id>/interest/new/', dashboard.views.new_interest, name='express-interest'),
path('actions/bounty/<int:bounty_id>/interest/remove/', dashboard.views.remove_interest, name='remove-interest'),
path('actions/bounty/<int:bounty_id>/interest/<int:profile_id>/uninterested/', dashboard.views.uninterested, name='uninterested'),

Choose a reason for hiding this comment

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

E501 line too long (134 > 120 characters)


url(r'^bounty/fulfill/?', dashboard.views.fulfill_bounty, name='fulfill_bounty'),
url(r'^funding/fulfill/?', dashboard.views.fulfill_bounty, name='fulfill_funding'),
url(r'^bounty/process/?', dashboard.views.process_bounty, name='process_bounty'),
url(r'^funding/process/?', dashboard.views.process_bounty, name='process_funding'),
# View Bounty
url(r'^bounty/details/(?P<ghuser>.*)/(?P<ghrepo>.*)/(?P<ghissue>.*)', dashboard.views.bounty_details, name='bounty_details_new'),
url(r'^funding/details/(?P<ghuser>.*)/(?P<ghrepo>.*)/(?P<ghissue>.*)', dashboard.views.bounty_details, name='funding_details_new'),
url(r'^issue/(?P<ghuser>.*)/(?P<ghrepo>.*)/(?P<ghissue>.*)/(?P<stdbounties_id>.*)', dashboard.views.bounty_details, name='issue_details_new3'),
url(r'^issue/(?P<ghuser>.*)/(?P<ghrepo>.*)/(?P<ghissue>.*)', dashboard.views.bounty_details, name='issue_details_new2'),
url(r'^bounty/details/?', dashboard.views.bounty_details, name='bounty_details'),
url(r'^funding/details/?', dashboard.views.bounty_details, name='funding_details'),
url(r'^legacy/funding/details/?', dashboard.views.bounty_details, name='legacy_funding_details'),
url(r'^funding/increase/?', dashboard.views.increase_bounty, name='increase_bounty'),
url(r'^funding/kill/?', dashboard.views.kill_bounty, name='kill_bounty'),

# Tips
url(r'^tip/receive/?', dashboard.views.receive_tip, name='receive_tip'),
url(r'^tip/send/2/?', dashboard.views.send_tip_2, name='send_tip_2'),
url(r'^tip/send/?', dashboard.views.send_tip, name='send_tip'),
url(r'^send/?', dashboard.views.send_tip, name='tip'),
url(r'^tip/?', dashboard.views.send_tip, name='tip'),

# Legal
url(r'^legal/?', dashboard.views.terms, name='legal'),
url(r'^terms/?', dashboard.views.terms, name='_terms'),
url(r'^legal/terms/?', dashboard.views.terms, name='terms'),
url(r'^legal/privacy/?', dashboard.views.privacy, name='privacy'),
url(r'^legal/cookie/?', dashboard.views.cookie, name='cookie'),
url(r'^legal/prirp/?', dashboard.views.prirp, name='prirp'),
url(r'^legal/apitos/?', dashboard.views.apitos, name='apitos'),

# Alpha functionality
url(r'^profile/(.*)?', dashboard.views.profile, name='profile'),
url(r'^toolbox/?', dashboard.views.toolbox, name='toolbox'),
path('actions/tool/<int:tool_id>/voteUp', dashboard.views.vote_tool_up, name='vote_tool_up'),
Expand All @@ -113,6 +124,7 @@
url(r'^sync/get_amount?', dashboard.helpers.amount, name='helpers_amount'),
url(r'^sync/get_issue_details?', dashboard.helpers.issue_details, name='helpers_issue_details'),
url(r'^sync/search_save?', dashboard.views.save_search, name='save_search'),

# brochureware views
url(r'^about/?', retail.views.about, name='about'),
url(r'^mission/?', retail.views.mission, name='mission'),
Expand All @@ -128,6 +140,7 @@
url(r'^extension/chrome?', retail.views.browser_extension_chrome, name='browser_extension_chrome'),
url(r'^extension/firefox?', retail.views.browser_extension_firefox, name='browser_extension_firefox'),
url(r'^extension/?', retail.views.browser_extension_chrome, name='browser_extension'),

# basic redirect retail views
url(r'^press/?', retail.views.presskit, name='press'),
url(r'^presskit/?', retail.views.presskit, name='presskit'),
Expand Down Expand Up @@ -200,10 +213,6 @@
# for robots
url(r'^robots.txt/?', retail.views.robotstxt, name='robotstxt'),
url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps}, name='django.contrib.sitemaps.views.sitemap'),
# Interests
path('actions/bounty/<int:bounty_id>/interest/new/', dashboard.views.new_interest, name='express-interest'),
path('actions/bounty/<int:bounty_id>/interest/remove/', dashboard.views.remove_interest, name='remove-interest'),
path('actions/bounty/<int:bounty_id>/interest/<int:profile_id>/uninterested/', dashboard.views.uninterested, name='uninterested'),
# Legacy Support
path('legacy/', include('legacy.urls', namespace='legacy')),
re_path(r'^logout/$', auth_views.logout, name='logout'),
Expand Down
14 changes: 9 additions & 5 deletions app/assets/v2/js/pages/bounty_details.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,11 @@ var wait_for_tx_to_mine_and_then_ping_server = function() {

// clear local data
localStorage[document.issueURL] = '';
document.location.href = document.location.href;
if (response['url']) {
document.location.href = response['url'];
} else {
document.location.href = document.location.href;
}
} else {
console.log('error from sync/web', response);
error(response);
Expand Down Expand Up @@ -491,7 +495,7 @@ var do_actions = function(result) {
var enabled = submit_work_enabled;
var _entry = {
enabled: enabled,
href: '/funding/fulfill?source=' + result['github_url'],
href: result['action_urls']['fulfill'],
text: gettext('Submit Work'),
parent: 'right_actions',
title: gettext('Submit work for the funder to review'),
Expand Down Expand Up @@ -521,7 +525,7 @@ var do_actions = function(result) {
var enabled = kill_bounty_enabled;
var _entry = {
enabled: enabled,
href: '/funding/kill?source=' + result['github_url'],
href: result['action_urls']['cancel'],
text: gettext('Cancel Bounty'),
parent: 'right_actions',
title: gettext('Cancel bounty and reclaim funds for this issue')
Expand All @@ -536,7 +540,7 @@ var do_actions = function(result) {
var enabled = show_accept_submission;
var _entry = {
enabled: enabled,
href: '/funding/process?source=' + result['github_url'],
href: result['action_urls']['accept'],
text: gettext('Accept Submission'),
title: gettext('This will payout the bounty to the submitter.'),
parent: 'right_actions',
Expand All @@ -550,7 +554,7 @@ var do_actions = function(result) {
var enabled = increase_bounty_enabled;
var _entry = {
enabled: enabled,
href: '/funding/increase?source=' + result['github_url'],
href: result['action_urls']['increase'],
text: gettext('Add Contribution'),
parent: 'right_actions',
title: gettext('Increase the funding for this issue'),
Expand Down
3 changes: 2 additions & 1 deletion app/assets/v2/js/pages/fulfill_bounty.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
window.onload = function() {
// a little time for web3 injection
setTimeout(function() {
waitforWeb3(actions_page_warn_if_not_on_same_network);
var account = web3.eth.accounts[0];

if (typeof localStorage['githubUsername'] != 'undefined') {
Expand Down Expand Up @@ -137,7 +138,7 @@ window.onload = function() {
};

// Get bountyId from the database
var uri = '/api/v0.1/bounties/?github_url=' + issueURL + '&network=' + document.web3network;
var uri = '/api/v0.1/bounties/?github_url=' + issueURL + '&network=' + $('input[name=network]').val() + '&standard_bounties_id=' + $('input[name=standard_bounties_id]').val();

$.get(uri, function(results, status) {
results = sanitizeAPIResults(results);
Expand Down
2 changes: 2 additions & 0 deletions app/assets/v2/js/pages/increase_bounty.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ load_tokens();

// Wait until page is loaded, then run the function
$(document).ready(function() {
waitforWeb3(actions_page_warn_if_not_on_same_network);

$('input[name=amount]').keyup(setUsdAmount);
$('input[name=amount]').blur(setUsdAmount);
$('select[name=deonomination]').change(setUsdAmount);
Expand Down
3 changes: 2 additions & 1 deletion app/assets/v2/js/pages/kill_bounty.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
window.onload = function() {
// a little time for web3 injection
setTimeout(function() {
waitforWeb3(actions_page_warn_if_not_on_same_network);
var account = web3.eth.accounts[0];

if (
Expand Down Expand Up @@ -116,7 +117,7 @@ window.onload = function() {

};
// Get bountyId from the database
var uri = '/api/v0.1/bounties/?github_url=' + issueURL + '&network=' + document.web3network;
var uri = '/api/v0.1/bounties/?github_url=' + issueURL + '&network=' + $('input[name=network]').val() + '&standard_bounties_id=' + $('input[name=standard_bounties_id]').val();

$.get(uri, apiCallback);
}
Expand Down
53 changes: 20 additions & 33 deletions app/assets/v2/js/pages/new_bounty.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,41 +297,28 @@ $(document).ready(function() {
web3Callback // callback for web3
);
}
// Check if the bounty already exists
var uri = '/api/v0.1/bounties/?github_url=' + issueURL;

$.get(uri, function(results, status) {
results = sanitizeAPIResults(results);
var result = results[0];

if (result != null) {
_alert({ message: 'A bounty already exists for that Github Issue.' });
unloading_button($('.js-submit'));
return;
}
var approve_success_callback = function(callback) {
// Add data to IPFS and kick off all the callbacks.
ipfsBounty.payload.issuer.address = account;
ipfs.addJson(ipfsBounty, newIpfsCallback);
};

var approve_success_callback = function(callback) {
// Add data to IPFS and kick off all the callbacks.
ipfsBounty.payload.issuer.address = account;
ipfs.addJson(ipfsBounty, newIpfsCallback);
};

if (isETH) {
// no approvals needed for ETH
approve_success_callback();
} else {
token_contract.approve(
bounty_address(),
amount,
{
from: account,
value: 0,
gasPrice: web3.toHex($('#gasPrice').val() * Math.pow(10, 9))
},
approve_success_callback
);
}
});
if (isETH) {
// no approvals needed for ETH
approve_success_callback();
} else {
token_contract.approve(
bounty_address(),
amount,
{
from: account,
value: 0,
gasPrice: web3.toHex($('#gasPrice').val() * Math.pow(10, 9))
},
approve_success_callback
);
}
}
});
});
3 changes: 2 additions & 1 deletion app/assets/v2/js/pages/process_bounty.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
window.onload = function() {
// a little time for web3 injection
setTimeout(function() {
waitforWeb3(actions_page_warn_if_not_on_same_network);
var account = web3.eth.accounts[0];

if (getParam('source')) {
Expand Down Expand Up @@ -169,7 +170,7 @@ window.onload = function() {
// Get bountyId from the database

waitforWeb3(function() {
var uri = '/api/v0.1/bounties/?github_url=' + issueURL + '&network=' + document.web3network;
var uri = '/api/v0.1/bounties/?github_url=' + issueURL + '&network=' + $('input[name=network]').val() + '&standard_bounties_id=' + $('input[name=standard_bounties_id]').val();

$.get(uri, apiCallback);
});
Expand Down
15 changes: 15 additions & 0 deletions app/assets/v2/js/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,21 @@ var listen_for_web3_changes = function() {
}
};

var actions_page_warn_if_not_on_same_network = function() {
var user_network = document.web3network;

if (typeof user_network == 'undefined') {
user_network = 'no network';
}
var bounty_network = $('input[name=network]').val();

if (bounty_network != user_network) {
var msg = 'Warning: You are on ' + user_network + ' and this bounty is on the ' + bounty_network + ' network. Please change your network to the ' + bounty_network + ' network.';

_alert({message: gettext(msg)}, 'error');
}
};

$(document).ready(function() {
sidebar_redirect_triggers();
attach_change_element_type();
Expand Down
15 changes: 15 additions & 0 deletions app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,21 @@ def fetch_issue_comments(self, save=True):
self.save()
return comments

@property
def action_urls(self):
"""Provide URLs for bounty related actions.

Returns:
dict: A dictionary of action URLS for this bounty.

"""
return {
'fulfill': f"/issue/fulfill/{self.pk}",
'increase': f"/issue/increase/{self.pk}",
'accept': f"/issue/accept/{self.pk}",
'cancel': f"/issue/cancel/{self.pk}",
}


class BountyFulfillmentQuerySet(models.QuerySet):
"""Handle the manager queryset for BountyFulfillments."""
Expand Down
2 changes: 1 addition & 1 deletion app/dashboard/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Meta:
'standard_bounties_id', 'web3_type', 'can_submit_after_expiration_date',
'github_issue_number', 'github_org_name', 'github_repo_name',
'idx_status', 'token_value_time_peg', 'fulfillment_accepted_on', 'fulfillment_submitted_on',
'fulfillment_started_on', 'canceled_on',
'fulfillment_started_on', 'canceled_on', 'action_urls',
)

def create(self, validated_data):
Expand Down
3 changes: 2 additions & 1 deletion app/dashboard/templates/fulfill_bounty.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ <h3>{% trans "Submit Work" %}</h3>
<form id="submitBounty">
<div class="w-100">
<label class="form__label" for="issueURL">{% trans "Issue URL" %}</label>
<input required name='issueURL' id="issueURL" class="form__input" type="url" placeholder="https://github.com/user/repo/pull/n" value="{% if issueURL %}{{issueURL}}{%endif%}" />
<input required name='issueURL' id="issueURL" class="form__input" type="url" placeholder="https://github.com/user/repo/pull/n" value="{% if bounty %}{{bounty.github_url}}{%endif%}" />
</div>
{% include 'shared/github_username.html' %}
{% include 'shared/notification_email.html' %}
Expand All @@ -57,6 +57,7 @@ <h3>{% trans "Submit Work" %}</h3>
<label class="form__label" for="terms">{% url "terms" as termsurl %}{% blocktrans %}I have read, understand, and agree to, the <a href="{{ termsurl }}" target="_blank" rel="noopener noreferrer">Terms of Service</a>:{% endblocktrans %}</label>
</div>
</div>
{% include 'shared/bounty_actions_hidden_vars.html' %}
{% include 'shared/wallet_estimate.html' %}
<div class="form__footer form__footer--right">
<button class="button button--primary js-submit" role="button" href="#">{% trans "Submit Work" %}</button>
Expand Down
11 changes: 6 additions & 5 deletions app/dashboard/templates/increase_bounty.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,22 @@
{% include 'shared/zero_balance_error.html' %}
{% include 'shared/unlock_metamask.html' %}
<input type="hidden" name="standardBountiesId"
value="{{standard_bounties_id}}">
value="{{bounty.standard_bounties_id}}">
<input type="hidden" name="bountyOwnerAddress"
value="{{bounty_owner_address}}">
value="{{bounty.bounty_owner_address}}">
<input type="hidden" name="valueInToken"
value="{{value_in_token}}">
value="{{bounty.value_in_token}}">
<div class="col offset-md-1 col-md-10 d-flex align-items-center justify-content-center" id="primary_form">
<div class="d-flex justify-content-center flex-column mt-5" id="primary_subform">
<div class="w-100" style="text-align: center;">
<h3>Increase Funding</h3>
<img src="{% static "v2/images/prime.png" %}">
</div>
{% include 'shared/bounty_actions_hidden_vars.html' %}
{% include 'shared/network_status.html' %}
<div class="w-100">
<label class="form__label" for=issueURL>Issue URL</label>
<input name='issueURL' id="issueURL" class="w-100 form__input" type="url" placeholder="https://github.com/user/repo/pull/n" value="{% if issue_url %}{{issue_url}}{%endif%}" disabled/>
<input name='issueURL' id="issueURL" class="w-100 form__input" type="url" placeholder="https://github.com/user/repo/pull/n" value="{% if bounty %}{{bounty.github_url}}{%endif%}" disabled/>
</div>
<div class="w-100 mt-2">
<label class="form__label" for="amount">Amount</label>
Expand All @@ -61,7 +62,7 @@ <h3>Increase Funding</h3>
</div>
<div class="form__group-item">
<div class="form__select2">
<select name='deonomination' id='token' data-token-address='{{token_address}}' disabled></select>
<select name='deonomination' id='token' data-token-address='{{bounty.token_address}}' disabled></select>
</div>
<small class="form__input-help form__input-help--dynamic" id="usd_amount"></small>
</div>
Expand Down
3 changes: 2 additions & 1 deletion app/dashboard/templates/kill_bounty.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ <h5>{% trans "(Issue Submitters only)" %}</h5>
<form id="submitBounty">
<div class="w-100">
<label class="form__label" for="issueURL">{% trans "Issue URL" %}</label>
<input name='issueURL' id="issueURL" class="form__input" type="url" required placeholder="https://github.com/user/repo/pull/n" value="{% if issueURL %}{{issueURL}}{%endif%}" />
<input name='issueURL' id="issueURL" class="form__input" type="url" required placeholder="https://github.com/user/repo/pull/n" value="{% if bounty %}{{bounty.github_url}}{%endif%}" />
</div>
<div class="w-100 mt-2 terms_container">
<div class="form__checkbox">
<input name='terms' id='terms' type="checkbox" value=1 />
<label required class="form__label" for="terms">{% url "terms" as termsurl %}{% blocktrans %}I have read, understand, and agree to, the <a href="{{ termsurl }}" target="_blank" rel="noopener noreferrer">Terms of Service</a>:{% endblocktrans %}</label>
</div>
</div>
{% include 'shared/bounty_actions_hidden_vars.html' %}
{% include 'shared/wallet_estimate.html' %}
<div class="form__footer form__footer--right">
<button class="button button--primary js-submit">{% trans "Cancel Bounty" %}</button>
Expand Down
Loading