Skip to content

Commit

Permalink
allow funder to turn off auto approvals at bounty creation
Browse files Browse the repository at this point in the history
  • Loading branch information
darkdarkdragon committed Aug 6, 2018
1 parent 77fcb0a commit 3b75809
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 5 deletions.
13 changes: 11 additions & 2 deletions app/assets/v2/js/pages/bounty_details.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ var rows = [
'submitted_owners_username',
'fulfilled_owners_username',
'fulfillment_accepted_on',
'additional_funding_summary'
'additional_funding_summary',
'auto_approve_workers'
];

var heads = {
Expand Down Expand Up @@ -168,6 +169,14 @@ var callbacks = {
'project_type': function(key, val, result) {
return [ 'project_type', ucwords(result.project_type) ];
},
'auto_approve_workers': function(key, val, result) {
if (result['permission_type'] == 'approval') {
$('#auto_approve_workers_wrapper').show();
} else {
$('#auto_approve_workers_wrapper').hide();
}
return [ 'auto_approve_workers', val ? 'on' : 'off' ];
},
'issue_keywords': function(key, val, result) {
if (!result.keywords || result.keywords.length == 0)
return [ 'issue_keywords', null ];
Expand Down Expand Up @@ -674,7 +683,7 @@ var do_actions = function(result) {
const increase_bounty_enabled = isBountyOwner(result);
let show_accept_submission = isBountyOwner(result) && !is_status_expired && !is_status_done;
let show_advanced_payout = isBountyOwner(result) && !is_status_expired && !is_status_done;
const show_suspend_auto_approval = document.isStaff && result['permission_type'] == 'approval';
const show_suspend_auto_approval = document.isStaff && result['permission_type'] == 'approval' && result['auto_approve_workers'];
const show_admin_methods = document.isStaff;
const show_moderator_methods = document.isModerator;

Expand Down
12 changes: 11 additions & 1 deletion app/assets/v2/js/pages/new_bounty.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ $(document).ready(function() {
waitforWeb3(function() {
promptForAuth();
});
$('select[name=permission_type]').change(function() {
var val = $('select[name=permission_type] option:selected').val();

if (val == 'approval') {
$('#auto_approve_workers_container').show();
} else {
$('#auto_approve_workers_container').hide();
}
});

// revision action buttons
$('#subtractAction').on('click', function() {
Expand Down Expand Up @@ -253,7 +262,8 @@ $(document).ready(function() {
},
schemes: {
project_type: data.project_type,
permission_type: data.permission_type
permission_type: data.permission_type,
auto_approve_workers: data.auto_approve_workers || '0'
},
hiring: {
hiringRightNow: data.hiringRightNow,
Expand Down
2 changes: 2 additions & 0 deletions app/dashboard/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ def create_new_bounty(old_bounties, bounty_payload, bounty_details, bounty_id):
old_bounty.save()
latest_old_bounty = old_bounty
try:
aaw = bounty_payload.get('schemes', {}).get('auto_approve_workers', 1)
new_bounty = Bounty.objects.create(
is_open=True if (bounty_details.get('bountyStage') == 1 and not accepted) else False,
raw_data=bounty_details,
Expand Down Expand Up @@ -407,6 +408,7 @@ def create_new_bounty(old_bounties, bounty_payload, bounty_details, bounty_id):
experience_level=metadata.get('experienceLevel', '') if not latest_old_bounty else latest_old_bounty.experience_level,
project_type=bounty_payload.get('schemes', {}).get('project_type', 'traditional') if not latest_old_bounty else latest_old_bounty.project_type,
permission_type=bounty_payload.get('schemes', {}).get('permission_type', 'permissionless') if not latest_old_bounty else latest_old_bounty.permission_type,
auto_approve_workers=aaw if not latest_old_bounty else latest_old_bounty.auto_approve_workers,
attached_job_description=bounty_payload.get('hiring', {}).get('jobDescription', None) if not latest_old_bounty else latest_old_bounty.attached_job_description,
bounty_owner_github_username=bounty_issuer.get('githubUsername', '') if not latest_old_bounty else latest_old_bounty.bounty_owner_github_username,
bounty_owner_address=bounty_issuer.get('address', '') if not latest_old_bounty else latest_old_bounty.bounty_owner_address,
Expand Down
18 changes: 18 additions & 0 deletions app/dashboard/migrations/0105_bounty_auto_approve_workers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.0.7 on 2018-08-05 17:05

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('dashboard', '0104_auto_20180802_1804'),
]

operations = [
migrations.AddField(
model_name='bounty',
name='auto_approve_workers',
field=models.BooleanField(default=True),
),
]
1 change: 1 addition & 0 deletions app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ class Bounty(SuperModel):
project_type = models.CharField(max_length=50, choices=PROJECT_TYPES, default='traditional')
permission_type = models.CharField(max_length=50, choices=PERMISSION_TYPES, default='permissionless')
snooze_warnings_for_days = models.IntegerField(default=0)
auto_approve_workers = models.BooleanField(default=True)

token_value_time_peg = models.DateTimeField(blank=True, null=True)
token_value_in_usdt = models.DecimalField(default=0, decimal_places=2, max_digits=50, blank=True, null=True)
Expand Down
2 changes: 1 addition & 1 deletion app/dashboard/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class Meta:
'github_org_name', 'github_repo_name', 'idx_status', 'token_value_time_peg', 'fulfillment_accepted_on',
'fulfillment_submitted_on', 'fulfillment_started_on', 'canceled_on', 'action_urls', 'project_type',
'permission_type', 'attached_job_description', 'needs_review', 'github_issue_state', 'is_issue_closed',
'additional_funding_summary',
'additional_funding_summary', 'auto_approve_workers',
)

def create(self, validated_data):
Expand Down
7 changes: 6 additions & 1 deletion app/dashboard/templates/bounty_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,14 @@ <h4 id="title" class="font-title"></h4>

<div>
<span class="bounty-info-heading" title='{% include "shared/permissions_type_tooltip.html" %}'>{% trans "Permissions" %}</span>
<span class="bounty-info-text" id="permission_type" title='{% include "shared/permissions_type_tooltip.html" %}'>></span>
<span class="bounty-info-text" id="permission_type" title='{% include "shared/permissions_type_tooltip.html" %}'></span>
<i class="fas fa-info-circle" title='{% include "shared/permissions_type_tooltip.html" %}'></i>
</div>

<div id="auto_approve_workers_wrapper">
<span class="bounty-info-heading">{% trans "Workers Auto Approve" %} </span>
<span class="bounty-info-text" id="auto_approve_workers"></span>
</div>
</div>
</div>
</div>
Expand Down
7 changes: 7 additions & 0 deletions app/dashboard/templates/submit_bounty.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ <h5 class="font-subheader">{% trans "Details" %}</h5>
<option value="approval" selected>{% trans "Approval Required - I will approve bounty hunters." %}</option>
</select>
</div>
<div class="w-100 mt-2" id="auto_approve_workers_container">
<div class="form__checkbox">
<input name='auto_approve_workers' id='auto_approve_workers' type="checkbox" value=1 checked />
<label class="form__label" for=auto_approve_workers style="display: flex;">{% blocktrans %}Worker will be
auto-approved after 72 hours.{% endblocktrans %}</label>
</div>
</div>
<div>
<label class="form__label">{% trans "Issue Details" %}</label>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def helper_execute(threshold, func_to_execute, action_str):
for interest in interests:
bounty = interest.bounties.first()
has_approved_worker_already = bounty.interested.filter(pending=False).exists()
if not bounty.auto_approve_workers:
print("skipped bc of auto_approve_workers")
continue
if bounty.admin_override_suspend_auto_approval: # skip bounties where this flag is set
print("skipped bc of admin_override_suspend_auto_approval")
continue
Expand Down

0 comments on commit 3b75809

Please sign in to comment.