Skip to content

Commit

Permalink
remove suspicious fix #60
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinDelille committed Feb 7, 2016
1 parent b5e205e commit 64f7181
Show file tree
Hide file tree
Showing 16 changed files with 11 additions and 286 deletions.
8 changes: 1 addition & 7 deletions liberapay/billing/exchanges.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from liberapay.constants import QUARANTINE
from liberapay.exceptions import (
LazyResponse, NegativeBalance, NotEnoughWithdrawableMoney,
TransactionFeeTooHigh, UserIsSuspicious
TransactionFeeTooHigh
)
from liberapay.models import check_db
from liberapay.models.participant import Participant
Expand Down Expand Up @@ -115,9 +115,6 @@ def test_hook():


def payout(db, participant, amount):
if participant.is_suspicious:
raise UserIsSuspicious

route = ExchangeRoute.from_network(participant, 'mango-ba')
assert route
ba = mangoapi.users.GetBankAccount(participant.mangopay_user_id, route.address)
Expand Down Expand Up @@ -157,9 +154,6 @@ def charge(db, participant, amount, return_url):
"""
typecheck(amount, Decimal)

if participant.is_suspicious:
raise UserIsSuspicious

route = ExchangeRoute.from_network(participant, 'mango-cc')
assert route

Expand Down
4 changes: 1 addition & 3 deletions liberapay/billing/payday.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,10 @@ def prepare(cursor, ts_start):
, join_time
, balance AS old_balance
, balance AS new_balance
, is_suspicious
, goal
, kind
FROM participants p
WHERE is_suspicious IS NOT true
AND join_time < %(ts_start)s
WHERE join_time < %(ts_start)s
AND (mangopay_user_id IS NOT NULL OR kind = 'group')
ORDER BY join_time;
Expand Down
3 changes: 0 additions & 3 deletions liberapay/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ def msg(self, _):
return _("You can't withdraw more than {0} at this time.", *self.args)


class UserIsSuspicious(Exception): pass


class TransactionFeeTooHigh(LazyResponse400):
def msg(self, _):
return _("The transaction fee would be more than 10%.")
Expand Down
17 changes: 1 addition & 16 deletions liberapay/models/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,14 @@ def update_session(self, new_token, expires):
SET session_token=%s
, session_expires=%s
WHERE id=%s
AND is_suspicious IS NOT true
""", (new_token, expires, self.id))
self.set_attributes(session_token=new_token, session_expires=expires)

def set_session_expires(self, expires):
"""Set ``session_expires`` to the given datetime.
"""
self.db.run( "UPDATE participants SET session_expires=%s "
"WHERE id=%s AND is_suspicious IS NOT true"
"WHERE id=%s"
, (expires, self.id,)
)
self.set_attributes(session_expires=expires)
Expand Down Expand Up @@ -262,14 +261,6 @@ def sign_out(self, cookies):
erase_cookie(cookies, SESSION)


# Suspiciousness
# ==============

@property
def is_whitelisted(self):
return self.is_suspicious is False


# Statement
# =========

Expand Down Expand Up @@ -1004,7 +995,6 @@ def update_giving(self, cursor=None):
JOIN participants p2 ON p2.id = t.tippee
WHERE t.tipper = %s
AND t.amount > 0
AND p2.is_suspicious IS NOT true
ORDER BY p2.join_time IS NULL, t.ctime ASC
""", (self.id,))
fake_balance = self.balance + self.receiving
Expand Down Expand Up @@ -1032,7 +1022,6 @@ def update_giving(self, cursor=None):
FROM current_tips
JOIN participants p2 ON p2.id = tippee
WHERE tipper = %(id)s
AND p2.is_suspicious IS NOT true
AND p2.status = 'active'
AND (p2.mangopay_user_id IS NOT NULL OR kind = 'group')
AND amount > 0
Expand All @@ -1054,7 +1043,6 @@ def update_receiving(self, cursor=None):
FROM current_tips
JOIN participants p2 ON p2.id = tipper
WHERE tippee = %(id)s
AND p2.is_suspicious IS NOT true
AND amount > 0
AND is_funded
)
Expand Down Expand Up @@ -1198,7 +1186,6 @@ def get_tip_distribution(self):
JOIN participants p ON p.id = tipper
WHERE tippee=%s
AND is_funded
AND is_suspicious IS NOT true
ORDER BY tipper
, mtime DESC
) AS foo
Expand Down Expand Up @@ -1242,7 +1229,6 @@ def get_giving_for_profile(self):
, p.kind
, t.is_funded
, (p.mangopay_user_id IS NOT NULL OR kind = 'group') AS is_identified
, p.is_suspicious
FROM tips t
JOIN participants p ON p.id = t.tippee
WHERE tipper = %s
Expand Down Expand Up @@ -1316,7 +1302,6 @@ def get_current_tips(self):
FROM tips t
JOIN participants p ON p.id = t.tippee
WHERE tipper = %s
AND p.is_suspicious IS NOT true
ORDER BY tippee
, t.mtime DESC
) AS foo
Expand Down
6 changes: 3 additions & 3 deletions liberapay/testing/mangopay.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ class MangopayHarness(Harness):
def setUp(self):
Harness.setUp(self)
self.david = self.make_participant(
'david', is_suspicious=False, mangopay_user_id=self.david_id,
'david', mangopay_user_id=self.david_id,
mangopay_wallet_id=self.david_wallet_id, email='[email protected]'
)
self.janet = self.make_participant(
'janet', is_suspicious=False, mangopay_user_id=self.janet_id,
'janet', mangopay_user_id=self.janet_id,
mangopay_wallet_id=self.janet_wallet_id, email='[email protected]'
)
self.janet_route = ExchangeRoute.insert(self.janet, 'mango-cc', self.card_id)
self.homer = self.make_participant(
'homer', is_suspicious=False, mangopay_user_id=self.homer_id,
'homer', mangopay_user_id=self.homer_id,
mangopay_wallet_id=self.homer_wallet_id, email='[email protected]'
)
self.homer_route = ExchangeRoute.insert(self.homer, 'mango-ba', self.bank_account.Id)
Expand Down
1 change: 0 additions & 1 deletion liberapay/utils/fake_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def fake_participant(db, kind=None, is_admin=False):
, balance=0
, hide_giving=is_a_person and (random.randrange(5) == 0)
, hide_receiving=is_a_person and (random.randrange(5) == 0)
, is_suspicious=False
, status='active'
, join_time=faker.date_time_this_year()
, kind=kind
Expand Down
3 changes: 0 additions & 3 deletions sql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ CREATE TABLE participants

, balance numeric(35,2) NOT NULL DEFAULT 0.0
, goal numeric(35,2) DEFAULT NULL
, is_suspicious boolean DEFAULT NULL
, mangopay_user_id text DEFAULT NULL UNIQUE
, mangopay_wallet_id text DEFAULT NULL

Expand Down Expand Up @@ -322,8 +321,6 @@ CREATE VIEW current_takes AS
FROM takes t
JOIN participants p1 ON p1.id = member
JOIN participants p2 ON p2.id = team
WHERE p1.is_suspicious IS NOT TRUE
AND p2.is_suspicious IS NOT TRUE
ORDER BY member
, team
, mtime DESC
Expand Down
12 changes: 3 additions & 9 deletions tests/py/test_billing_exchanges.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
transfer,
)
from liberapay.exceptions import (
NegativeBalance, NotEnoughWithdrawableMoney, UserIsSuspicious,
NegativeBalance, NotEnoughWithdrawableMoney,
TransactionFeeTooHigh
)
from liberapay.models.participant import Participant
Expand Down Expand Up @@ -77,12 +77,6 @@ def test_payout_quarantine(self, gba):

class TestCharge(MangopayHarness):

def test_charge_for_suspicious_raises_UserIsSuspicious(self):
bob = self.make_participant('bob', is_suspicious=True,
mangopay_user_id='fake_id')
with self.assertRaises(UserIsSuspicious):
charge(self.db, bob, D('1.00'), 'http://localhost/')

@mock.patch('liberapay.billing.exchanges.test_hook')
def test_charge_failure(self, test_hook):
test_hook.side_effect = Foobar
Expand Down Expand Up @@ -122,12 +116,12 @@ def test_charge_bad_card(self):
assert 'CardId: The value -1 is not valid' in exchange.note

def test_charge_no_card(self):
bob = self.make_participant('bob', is_suspicious=False)
bob = self.make_participant('bob')
with self.assertRaises(AssertionError):
charge(self.db, bob, D('10.00'), 'http://localhost/')

def test_charge_invalidated_card(self):
bob = self.make_participant('bob', is_suspicious=False, last_bill_result='invalidated')
bob = self.make_participant('bob', last_bill_result='invalidated')
with self.assertRaises(AssertionError):
charge(self.db, bob, D('10.00'), 'http://localhost/')

Expand Down
30 changes: 0 additions & 30 deletions tests/py/test_billing_payday.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,6 @@ def test_payday_moves_money(self):

assert self.transfer_mock.call_count

def test_payday_doesnt_move_money_from_a_suspicious_account(self):
self.db.run("""
UPDATE participants
SET is_suspicious = true
WHERE username = 'janet'
""")
self.janet.set_tip_to(self.homer, '6.00') # under $10!
Payday.start().run()

janet = Participant.from_username('janet')
homer = Participant.from_username('homer')

assert janet.balance == D('0.00')
assert homer.balance == D('0.00')

def test_payday_doesnt_move_money_to_a_suspicious_account(self):
self.db.run("""
UPDATE participants
SET is_suspicious = true
WHERE username = 'homer'
""")
self.janet.set_tip_to(self.homer, '6.00') # under $10!
Payday.start().run()

janet = Participant.from_username('janet')
homer = Participant.from_username('homer')

assert janet.balance == D('0.00')
assert homer.balance == D('0.00')

def test_update_cached_amounts(self):
team = self.make_participant('team', kind='group')
alice = self.make_participant('alice', balance=100)
Expand Down
50 changes: 0 additions & 50 deletions tests/py/test_is_suspicious.py

This file was deleted.

13 changes: 0 additions & 13 deletions tests/py/test_participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ def test_only_latest_tip_counts(self):
def test_receiving_includes_tips_from_whitelisted_accounts(self):
alice = self.make_participant( 'alice'
, balance=100
, is_suspicious=False
)
bob = self.make_stub()
alice.set_tip_to(bob, '3.00')
Expand All @@ -364,25 +363,13 @@ def test_receiving_includes_tips_from_whitelisted_accounts(self):
def test_receiving_includes_tips_from_unreviewed_accounts(self):
alice = self.make_participant( 'alice'
, balance=100
, is_suspicious=None
)
bob = self.make_stub()
alice.set_tip_to(bob, '3.00')

assert bob.receiving == Decimal('3.00')
assert bob.npatrons == 1

def test_receiving_ignores_tips_from_blacklisted_accounts(self):
alice = self.make_participant( 'alice'
, balance=100
, is_suspicious=True
)
bob = self.make_stub()
alice.set_tip_to(bob, '3.00')

assert bob.receiving == Decimal('0.00')
assert bob.npatrons == 0

def test_receiving_includes_taking_when_updated_from_set_tip_to(self):
alice = self.make_participant('alice', balance=100)
bob = self.make_participant('bob', taking=Decimal('42.00'))
Expand Down
6 changes: 2 additions & 4 deletions www/%username/giving/index.html.spt
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,14 @@ weekly = total - participant.receiving
</tfoot>
<tbody>
% for tip in tips
% set inactive = tip.is_suspicious or not tip.is_identified or not tip.is_funded
% set inactive = not tip.is_identified or not tip.is_funded
<tr>
<td class="recipient"><a href="/{{ tip.username }}/">{{ tip.username }}</a></td>
<td class="amount">{{ tip_form(tip=tip, inline=True) }}</td>
<td class="ctime">{{ to_age_str(tip.ctime, add_direction=True) }}</td>
<td class="mtime">{{ to_age_str(tip.mtime, add_direction=True) }}</td>
<td class="funded {{ 'danger' if inactive }}">
% if tip.is_suspicious
{{ _("No: the donee is blacklisted") }}
% elif not tip.is_identified
% if not tip.is_identified
{{ _("No: the donee hasn't filled the identity form") }}</td>
% elif not tip.is_funded
{{ _("No: insufficient funds") }}
Expand Down
36 changes: 0 additions & 36 deletions www/%username/toggle-is-suspicious.json.spt

This file was deleted.

Loading

0 comments on commit 64f7181

Please sign in to comment.