Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions app/assets/javascripts/admin/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,8 @@ angular.module('api.bountysource',[]).
});
};

this.refund_bounty = function(id) {
return this.call("/admin/bounties/"+id+"/refund", 'POST', function(response) {
this.refund_bounty = function(id, is_fraud) {
return this.call("/admin/bounties/"+id+"/refund" + (is_fraud ? '?fraud=true' : ''), 'POST', function(response) {
return response;
});
};
Expand Down
4 changes: 3 additions & 1 deletion app/assets/javascripts/admin/bounties/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ <h4>Options</h4>


<h4>Actions</h4>
<button class="btn btn-success" ng-click="refund(bounty.id)" ng-show="bounty.status=='active'">Refund</button>
<button class="btn btn-success" ng-click="refund(bounty.id, false)" ng-show="bounty.status=='active'">Cancel (refund owner)</button>
&nbsp; &nbsp;
<button class="btn btn-success" ng-click="refund(bounty.id, true)" ng-show="bounty.status=='active'">Cancel (no refund)</button>
&nbsp; &nbsp;
<button class="btn btn-success" ng-click="set_featured(bounty.id, true)" ng-show="!bounty.featured">Feature</button>
<button class="btn btn-success" ng-click="set_featured(bounty.id, false)" ng-show="bounty.featured">Unfeature</button>
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/admin/bounties/show.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ angular.module('app')
return split.transaction.audited;
};

$scope.refund = function(bounty_id) {
$scope.refund = function(bounty_id, is_fraud) {
if (confirm("Are you sure?")) {
$api.refund_bounty(bounty_id).then(function(response) {
$api.refund_bounty(bounty_id, is_fraud).then(function(response) {
if (response.meta.success) {
$window.location.reload();
} else {
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/admin/issues/controllers/show.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ angular.module('app')
if (confirm("Are you sure?")) {
angular.forEach($scope.issue.bounties, function(bounty) {
if (bounty.checked && (bounty.status==='active')) {
$api.refund_bounty(bounty.id).then(function(response) {
$api.refund_bounty(bounty.id, false).then(function(response) {
if (response.meta.success) {
angular.forEach($scope.issue.bounties, function(sub_bounty, $index) {
if (sub_bounty.id === bounty.id) {
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v0/bounties_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def update
end

def refund
@bounty.refund!
@bounty.refund!(!!params[:fraud])

if @bounty.errors.empty?
render "api/v0/bounties/show"
Expand Down
10 changes: 6 additions & 4 deletions app/models/bounty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,15 @@ def frontend_url

# Refund bounty to the person who created it. The amount refundable is simply
# the amount - (amount * bs fee)
def refund!
def refund!(is_fraud=false)
if refundable?
self.class.transaction do
transaction = Transaction.build do |tr|
tr.description = "Refund Bounty(#{id}) - Bounty Amount: $#{amount} Refunded: $#{amount}"
tr.description = "Refund Bounty(#{id}) #{'FOR FRAUD ' if is_fraud}- Bounty Amount: $#{amount} Refunded: $#{amount}"
tr.splits.create(amount: -amount, item: issue)
if owner_type == "Team"
if is_fraud
tr.splits.create(amount: +amount, account: Account::Liability.instance)
elsif owner_type == "Team"
tr.splits.create(amount: +amount, item: owner)
else
tr.splits.create(amount: +amount, item: person)
Expand All @@ -246,7 +248,7 @@ def refund!
update_attributes status: Status::REFUNDED or raise ActiveRecord::Rollback

# email the backer
person.send_email :bounty_refunded, bounty: self, transaction: transaction
person.send_email :bounty_refunded, bounty: self, transaction: transaction unless is_fraud
end

# update displayed bounty total on issue
Expand Down