Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Drop is_locked entirely #3020

Merged
merged 4 commits into from
Dec 27, 2014
Merged
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
17 changes: 17 additions & 0 deletions branch.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
BEGIN;

UPDATE participants
SET goal = -1
WHERE is_locked;

INSERT INTO tips (tipper, tippee, amount, ctime)
SELECT tipper, tippee, 0, t.ctime
FROM current_tips t
JOIN participants p ON p.username = tippee
WHERE amount > 0
AND p.is_locked;

-- Uncomment when deploying
-- ALTER TABLE participants DROP COLUMN is_locked;

END;
10 changes: 1 addition & 9 deletions fake_payday.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
CREATE TEMPORARY TABLE temp_participants ON COMMIT DROP AS
SELECT username
, claimed_time
, is_locked
, balance AS fake_balance
, 0::numeric(35,2) AS giving
, 0::numeric(35,2) AS pledging
Expand Down Expand Up @@ -42,19 +41,12 @@ CREATE TEMPORARY TABLE temp_takes
CREATE OR REPLACE FUNCTION fake_tip() RETURNS trigger AS $$
DECLARE
tipper temp_participants;
tippee temp_participants;
BEGIN
tipper := (
SELECT p.*::temp_participants
FROM temp_participants p
WHERE username = NEW.tipper
);
tippee := (
SELECT p.*::temp_participants
FROM temp_participants p
WHERE username = NEW.tippee
LIMIT 1
);
IF (NEW.amount > tipper.fake_balance AND NOT tipper.credit_card_ok) THEN
RETURN NULL;
END IF;
Expand All @@ -63,7 +55,7 @@ CREATE OR REPLACE FUNCTION fake_tip() RETURNS trigger AS $$
SET fake_balance = (fake_balance - NEW.amount)
, giving = (giving + NEW.amount)
WHERE username = NEW.tipper;
ELSIF (NOT tippee.is_locked) THEN
ELSE
UPDATE temp_participants
SET fake_balance = (fake_balance - NEW.amount)
, pledging = (pledging + NEW.amount)
Expand Down
2 changes: 1 addition & 1 deletion gratipay/models/account_elsewhere.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def opt_in(self, desired_username):
"""Given a desired username, return a User object.
"""
from gratipay.security.user import User
self.participant.set_is_locked(False)
self.participant.update_goal(None)
user = User.from_username(self.participant.username)
assert not user.ANON, self.participant # sanity check
if self.participant.is_claimed:
Expand Down
9 changes: 1 addition & 8 deletions gratipay/models/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,12 +621,6 @@ def set_email_lang(self, accept_lang):
# Random Junk
# ===========

def set_is_locked(self, is_locked):
self.db.run( 'UPDATE participants SET is_locked=%s WHERE id=%s'
, (is_locked, self.id)
)
self.set_attributes(is_locked=is_locked)

def get_teams(self):
"""Return a list of teams this user is a member of.
"""
Expand Down Expand Up @@ -791,7 +785,7 @@ def update_giving(self, cursor=None):
# Update giving and pledging on participant
giving, pledging = (cursor or self.db).one("""
WITH our_tips AS (
SELECT amount, tippee, p2.claimed_time, p2.is_locked
SELECT amount, p2.claimed_time
FROM current_tips
JOIN participants p2 ON p2.username = tippee
WHERE tipper = %(username)s
Expand All @@ -809,7 +803,6 @@ def update_giving(self, cursor=None):
SELECT sum(amount)
FROM our_tips
WHERE claimed_time IS NULL
AND is_locked = false
), 0)
WHERE p.username = %(username)s
RETURNING giving, pledging
Expand Down
1 change: 0 additions & 1 deletion gratipay/utils/fake_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def fake_participant(db, number="singular", is_admin=False):
, last_bill_result='' # Needed to not be suspicious
, claimed_time=faker.date_time_this_year()
, number=number
, is_locked=False
)
#Call participant constructor to perform other DB initialization
return Participant.from_username(username)
Expand Down
4 changes: 1 addition & 3 deletions tests/py/test_billing_payday.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,10 @@ def test_update_cached_amounts(self):
carl = self.make_participant('carl', claimed_time='now', last_bill_result="Fail!")
dana = self.make_participant('dana', claimed_time='now')
emma = self.make_participant('emma')
roy = self.make_participant('roy', is_locked=True)
alice.set_tip_to(dana, '3.00')
alice.set_tip_to(bob, '6.00')
alice.set_tip_to(emma, '1.00')
alice.set_tip_to(team, '4.00')
alice.set_tip_to(roy, '10.00')
bob.set_tip_to(alice, '5.00')
team.add_member(bob)
team.set_take_for(bob, D('1.00'), bob)
Expand All @@ -139,7 +137,7 @@ def check():
assert emma.receiving == D('1.00')
assert emma.npatrons == 1
funded_tips = self.db.all("SELECT amount FROM tips WHERE is_funded ORDER BY id")
assert funded_tips == [3, 6, 1, 4, 10, 5, 2]
assert funded_tips == [3, 6, 1, 4, 5, 2]

# Pre-test check
check()
Expand Down
9 changes: 5 additions & 4 deletions tests/py/test_participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from gratipay import NotSane
from gratipay.exceptions import (
HasBigTips,
UserDoesntAcceptTips,
UsernameIsEmpty,
UsernameTooLong,
UsernameAlreadyTaken,
Expand Down Expand Up @@ -615,11 +616,11 @@ def test_pledging_only_counts_latest_tip(self):
alice.set_tip_to(bob, '3.00')
assert alice.pledging == Decimal('3.00')

def test_pledging_doesnt_count_locked_accounts(self):
def test_cant_pledge_to_locked_accounts(self):
alice = self.make_participant('alice', claimed_time='now', last_bill_result='')
bob = self.make_participant('bob', is_locked=True)
alice.set_tip_to(bob, '3.00')
assert alice.pledging == Decimal('0.00')
bob = self.make_participant('bob', goal=-1)
with self.assertRaises(UserDoesntAcceptTips):
alice.set_tip_to(bob, '3.00')

def test_pledging_isnt_giving(self):
alice = self.make_participant('alice', claimed_time='now', last_bill_result='')
Expand Down
1 change: 0 additions & 1 deletion www/%username/account/index.html.spt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ hero = _("Account")
title = participant.username # used in the title tag
username = participant.username # used in footer shared with on/$platform/
# pages
locked = False

emails = participant.get_emails()

Expand Down
1 change: 0 additions & 1 deletion www/%username/events/index.html.spt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ db = website.db
participant = get_participant(request, restrict=True)
hero = "Events"
title = "%s - %s" % (participant.username, hero)
locked = False

SQL = """
SELECT * FROM events WHERE type = 'participant' AND payload->>'id' = %s ORDER BY ts DESC
Expand Down
1 change: 0 additions & 1 deletion www/%username/giving/index.html.spt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ tips, total, unclaimed_tips, unclaimed_total = \
participant.get_giving_for_profile()
hero = _("Giving")
title = "%s - %s" % (participant.username, hero)
locked = False
cancelled_tips = [x for x in tips if x.amount == 0][:10]
ncancelled_tips = len(cancelled_tips)

Expand Down
1 change: 0 additions & 1 deletion www/%username/history/index.html.spt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ participant = get_participant(request, restrict=True)
events = iter_payday_events(website.db, participant)
hero = _("History")
title = "%s - %s" % (participant.username, hero)
locked = False
subpath = 'history/' if user.ADMIN else ''
admin_override = user.ADMIN and (participant != user.participant or 'override' in qs)
translated_status = { None: ''
Expand Down
1 change: 0 additions & 1 deletion www/%username/index.html.spt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def _clip(text, n):
[-----------------------------------------------------------------------------]

participant = get_participant(request, restrict=False)
locked = False
tip_or_pledge = "tip"
hero = _("Profile")
title = participant.username # used in the title tag
Expand Down
1 change: 0 additions & 1 deletion www/%username/members/index.html.spt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ from gratipay.utils import get_participant
participant = team = get_participant(request, restrict=False)
if not team.show_as_team(user):
request.redirect('../')
locked = False
tip_or_pledge = "tip"
hero = _("Team Members")
title = team.username # used in the title tag
Expand Down
2 changes: 0 additions & 2 deletions www/%username/tip.json.spt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ if not user.ANON:

# Get tipper and tippee.
# ======================
# XXX We could/should enforce that tips cannot be pledged at all to locked
# accounts.

tipper = user.participant
tippee = get_participant(request, restrict=False, resolve_unclaimed=False)
Expand Down
1 change: 0 additions & 1 deletion www/%username/widgets/index.html.spt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ from gratipay.utils import get_participant
participant = get_participant(request, restrict=True)
hero = _("Widgets")
title = "%s - %s" % (participant.username, hero)
locked = False

[-----------------------------------------------------------------------------]
{% extends "templates/profile.html" %}
Expand Down
6 changes: 3 additions & 3 deletions www/on/%platform/%user_name/index.html.spt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if account.participant.is_claimed:

title = username = user_name = account.user_name
participant = account.participant
locked = participant.is_locked
locked = participant.goal == -1
is_team = account.is_team
allow_pledges = not locked and (not is_team or platform.allows_team_connect)

Expand Down Expand Up @@ -194,7 +194,7 @@ else:

{% for member in members %}
{% set on_gratipay = member.participant.is_claimed %}
{% set declines_gifts = not member.participant.accepts_tips or member.participant.is_locked %}
{% set declines_gifts = not member.participant.accepts_tips %}
<tr class="{{ 'declines' if declines_gifts }} {{ 'not-on-gratipay' if not on_gratipay }}">
{% if on_gratipay %}
<td>
Expand All @@ -218,7 +218,7 @@ else:
</a>
</td>
<td>
{% if member.participant.is_locked %}
{% if member.participant.accepts_tips %}
declines gifts (opted out)
{% else %}
hasn't joined Gratipay yet
Expand Down
2 changes: 1 addition & 1 deletion www/on/%platform/associate.spt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ elif action == 'connect':
raise request.resource.respond(request, dispatch_result)

elif action in {'lock', 'unlock'}:
account.participant.set_is_locked(action == 'lock')
account.participant.update_goal(-1 if action == 'lock' else None)

else:
raise Response(400)
Expand Down