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

kill pledging #3403

Merged
merged 8 commits into from
May 12, 2015
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
2 changes: 1 addition & 1 deletion bin/masspay.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def compute_input_csv():
print_rule(88)
total_gross = 0
for participant in participants:
total = participant.giving + participant.pledging
total = participant.giving
amount = participant.balance - total
if amount < 0.50:
# Minimum payout of 50 cents. I think that otherwise PayPal upcharges to a penny.
Expand Down
14 changes: 0 additions & 14 deletions emails/notify_patron.spt

This file was deleted.

2 changes: 1 addition & 1 deletion gratipay/billing/payday.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ def credit(participant):
if participant.is_suspicious is None:
log("UNREVIEWED: %s" % participant.username)
return
withhold = participant.giving + participant.pledging
withhold = participant.giving
error = ach_credit(self.db, participant, withhold)
if error:
self.mark_ach_failed()
Expand Down
2 changes: 1 addition & 1 deletion gratipay/elsewhere/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from gratipay.utils import LazyResponse


ACTIONS = {'opt-in', 'connect', 'lock', 'unlock'}
ACTIONS = {'opt-in', 'connect'}
PLATFORMS = 'facebook google bitbucket bountysource github openstreetmap twitter venmo'.split()


Expand Down
1 change: 0 additions & 1 deletion gratipay/models/account_elsewhere.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ def opt_in(self, desired_username):
else:
newly_claimed = True
user.participant.set_as_claimed()
user.participant.notify_patrons(self)
try:
user.participant.change_username(desired_username)
except ProblemChangingUsername:
Expand Down
83 changes: 11 additions & 72 deletions gratipay/models/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def upsert_statement(self, lang, statement):

@property
def usage(self):
return max(self.giving + self.pledging, self.receiving)
return max(self.giving, self.receiving)

@property
def suggested_payment(self):
Expand Down Expand Up @@ -296,8 +296,8 @@ def _generate_api_key(self):

# Claiming
# ========
# An unclaimed Participant is a stub that's created when someone pledges to
# give to an AccountElsewhere that's not been connected on Gratipay yet.
# An unclaimed Participant is a stub that's created when someone visits our
# page for an AccountElsewhere that's not been connected on Gratipay yet.

def resolve_unclaimed(self):
"""Given a username, return an URL path.
Expand Down Expand Up @@ -372,7 +372,7 @@ def distribute_balance_as_final_gift(self, cursor):
if self.balance == 0:
return

claimed_tips, claimed_total, _, _= self.get_giving_for_profile()
claimed_tips, claimed_total = self.get_giving_for_profile()
transfers = []
distributed = Decimal('0.00')

Expand Down Expand Up @@ -482,7 +482,6 @@ def clear_personal_information(self, cursor):
, session_token=NULL
, session_expires=now()
, giving=0
, pledging=0
, receiving=0
, npatrons=0
WHERE username=%(username)s
Expand Down Expand Up @@ -659,19 +658,6 @@ def render(t, context):
self._mailer.messages.send(message=message)
return 1 # Sent

def notify_patrons(self, elsewhere, tips=None):
tips = self.get_tips_receiving() if tips is None else tips
for t in tips:
p = Participant.from_username(t.tipper)
if p.email_address and p.notify_on_opt_in:
p.queue_email(
'notify_patron',
user_name=elsewhere.user_name,
platform=elsewhere.platform_data.display_name,
amount=t.amount,
profile_url=elsewhere.gratipay_url,
)

def queue_email(self, spt_name, **context):
self.db.run("""
INSERT INTO email_queue
Expand Down Expand Up @@ -966,8 +952,8 @@ def update_giving(self, cursor=None):
RETURNING *
""", (is_funded, tip.id)))

# Update giving and pledging on participant
giving, pledging = (cursor or self.db).one("""
# Update giving on participant
giving = (cursor or self.db).one("""
WITH our_tips AS (
SELECT amount, p2.claimed_time
FROM current_tips
Expand All @@ -983,15 +969,10 @@ def update_giving(self, cursor=None):
FROM our_tips
WHERE claimed_time IS NOT NULL
), 0)
, pledging = COALESCE((
SELECT sum(amount)
FROM our_tips
WHERE claimed_time IS NULL
), 0)
WHERE p.username = %(username)s
RETURNING giving, pledging
RETURNING giving
""", dict(username=self.username))
self.set_attributes(giving=giving, pledging=pledging)
self.set_attributes(giving=giving)

return updated

Expand Down Expand Up @@ -1088,7 +1069,7 @@ def set_tip_to(self, tippee, amount, update_self=True, update_tippee=True, curso
t = (cursor or self.db).one(NEW_TIP, args)

if update_self:
# Update giving/pledging amount of tipper
# Update giving amount of tipper
self.update_giving(cursor)
if update_tippee:
# Update receiving amount of tippee
Expand Down Expand Up @@ -1210,51 +1191,16 @@ def get_giving_for_profile(self):
"""
tips = self.db.all(TIPS, (self.username,))

UNCLAIMED_TIPS = """\

SELECT * FROM (
SELECT DISTINCT ON (tippee)
amount
, tippee
, t.ctime
, t.mtime
, p.claimed_time
, e.platform
, e.user_name
FROM tips t
JOIN participants p ON p.username = t.tippee
JOIN elsewhere e ON e.participant = t.tippee
WHERE tipper = %s
AND p.is_suspicious IS NOT true
AND p.claimed_time IS NULL
ORDER BY tippee
, t.mtime DESC
) AS foo
ORDER BY amount DESC
, lower(user_name)

"""
unclaimed_tips = self.db.all(UNCLAIMED_TIPS, (self.username,))


# Compute the total.
# ==================
# For payday we only want to process payments to tippees who have
# themselves opted into Gratipay. For the tipper's profile page we want
# to show the total amount they've pledged (so they're not surprised
# when someone *does* start accepting tips and all of a sudden they're
# hit with bigger charges.

total = sum([t.amount for t in tips])
if not total:
# If tips is an empty list, total is int 0. We want a Decimal.
total = Decimal('0.00')

unclaimed_total = sum([t.amount for t in unclaimed_tips])
if not unclaimed_total:
unclaimed_total = Decimal('0.00')

return tips, total, unclaimed_tips, unclaimed_total
return tips, total

def get_tips_receiving(self):
return self.db.all("""
Expand Down Expand Up @@ -1429,7 +1375,6 @@ def reserve(cursor, username):
, session_token=NULL
, session_expires=now()
, giving = 0
, pledging = 0
, receiving = 0
, taking = 0
WHERE username=%s
Expand Down Expand Up @@ -1460,8 +1405,7 @@ def take_over(self, account, have_confirmation=False):
This method associates an account on another platform (GitHub, Twitter,
etc.) with the given Gratipay participant. Every account elsewhere has an
associated Gratipay participant account, even if its only a stub
participant (it allows us to track pledges to that account should they
ever decide to join Gratipay).
participant.

In certain circumstances, we want to present the user with a
confirmation before proceeding to transfer the account elsewhere to
Expand Down Expand Up @@ -1645,8 +1589,6 @@ def take_over(self, account, have_confirmation=False):
# this is a no op - trying to take over itself
return

# Save old tips so we can notify patrons that they've been claimed
old_tips = None if other.is_claimed else other.get_tips_receiving()

# Make sure we have user confirmation if needed.
# ==============================================
Expand Down Expand Up @@ -1783,9 +1725,6 @@ def take_over(self, account, have_confirmation=False):
if new_balance is not None:
self.set_attributes(balance=new_balance)

if old_tips:
self.notify_patrons(elsewhere, tips=old_tips)

self.update_avatar()

# Note: the order matters here, receiving needs to be updated before giving
Expand Down
6 changes: 6 additions & 0 deletions sql/branch.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BEGIN;

ALTER TABLE participants DROP COLUMN pledging;
ALTER TABLE participants DROP COLUMN notify_on_opt_in;

END;
4 changes: 0 additions & 4 deletions sql/fake_payday.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ CREATE TEMPORARY TABLE temp_participants ON COMMIT DROP AS
, claimed_time
, balance AS fake_balance
, 0::numeric(35,2) AS giving
, 0::numeric(35,2) AS pledging
, 0::numeric(35,2) AS taking
, 0::numeric(35,2) AS receiving
, 0 as npatrons
Expand Down Expand Up @@ -63,7 +62,6 @@ CREATE OR REPLACE FUNCTION fake_tip() RETURNS trigger AS $$
ELSE
UPDATE temp_participants
SET fake_balance = (fake_balance - NEW.amount)
, pledging = (pledging + NEW.amount)
WHERE username = NEW.tipper;
END IF;
UPDATE temp_participants
Expand Down Expand Up @@ -173,14 +171,12 @@ UPDATE tips t

UPDATE participants p
SET giving = p2.giving
, pledging = p2.pledging
, taking = p2.taking
, receiving = p2.receiving
, npatrons = p2.npatrons
FROM temp_participants p2
WHERE p.username = p2.username
AND ( p.giving <> p2.giving OR
p.pledging <> p2.pledging OR
p.taking <> p2.taking OR
p.receiving <> p2.receiving OR
p.npatrons <> p2.npatrons
Expand Down
4 changes: 1 addition & 3 deletions templates/sign-in-using-to-give.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<div class="sign-in-to">
{% include "templates/sign-in-using.html" %}
{% set message = _("{0} to pledge to {1}") if request.path.decoded.startswith('/on/') else _("{0} to give to {1}") %}
{% set formatted_message = message.format("", account.user_name if account else participant.username) %}
{{ formatted_message }}
{{ _("{0} to give to {1}").format("", participant.username) }}
</div>
5 changes: 1 addition & 4 deletions templates/your-tip.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ <h2>{{ _('Your Tip') }}</h2>
<span class="amount">{{ format_currency(tip.amount, 'USD') }}</span>
<div class="per-week">{{ _("per week") }}</div>
<button class="edit {{ 'not-zero' if tip.amount > 0 }}">
<span class="zero">{{
_("Pledge to {0}", account.user_name) if account else
_("Give to {0}", tippee)
}}</span>
<span class="zero">{{ _("Give to {0}", tippee) }}</span>
<span class="not-zero">{{ _("Edit") }}</span>
</button>
</div>
Expand Down
3 changes: 0 additions & 3 deletions tests/py/test_billing_payday.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ def check():
dana = Participant.from_username('dana')
emma = Participant.from_username('emma')
assert alice.giving == D('13.00')
assert alice.pledging == D('1.00')
assert alice.receiving == D('5.00')
assert bob.giving == D('7.00')
assert bob.receiving == D('7.00')
Expand All @@ -153,7 +152,6 @@ def check():
UPDATE participants
SET giving = 0
, npatrons = 0
, pledging = 0
, receiving = 0
, taking = 0;
""")
Expand All @@ -174,7 +172,6 @@ def check():
for username in reversed(usernames[1:]):
user = Participant.from_username(username)
assert user.giving == D('1.00')
assert user.pledging == D('0.00')
assert user.receiving == D('1.00')
assert user.npatrons == 1
funded_tips = self.db.all("SELECT id FROM tips WHERE is_funded ORDER BY id")
Expand Down
2 changes: 0 additions & 2 deletions tests/py/test_close.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ def test_cpi_clears_personal_information(self, mailer):
, session_token='deadbeef'
, session_expires='2000-01-01'
, giving=20
, pledging=30
, receiving=40
, npatrons=21
)
Expand All @@ -306,7 +305,6 @@ def test_cpi_clears_personal_information(self, mailer):
assert alice.email_address == new_alice.email_address == None
assert alice.claimed_time == new_alice.claimed_time == None
assert alice.giving == new_alice.giving == 0
assert alice.pledging == new_alice.pledging == 0
assert alice.receiving == new_alice.receiving == 0
assert alice.npatrons == new_alice.npatrons == 0
assert alice.session_token == new_alice.session_token == None
Expand Down
11 changes: 0 additions & 11 deletions tests/py/test_elsewhere.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,6 @@ def test_user_pages_not_found(self):
expected = error % (user_name, platform.display_name)
assert expected in r.body

def test_user_name_is_in_button(self):
self.make_participant('bob', claimed_time='now')
self.make_participant('alice', elsewhere='twitter')
body = self.client.GET('/on/twitter/alice/', auth_as='bob').body
assert '<span class="zero">Pledge to alice</span>' in body

def test_user_name_is_in_pledge_cta(self):
self.make_participant('alice', elsewhere='twitter')
body = self.client.GET('/on/twitter/alice/').body
assert 'pledge to alice' in body

def test_failure_page_accepts_valid_username(self):
self.client.GET('/on/twitter/Gratipay/') # normal case will have the db primed
response = self.client.GET('/on/twitter/Gratipay/failure.html')
Expand Down
Loading