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

Commit

Permalink
Add an is_closed attribute to Participant
Browse files Browse the repository at this point in the history
This is useful for showing an "Account closed by user" page for that
case.
  • Loading branch information
chadwhitacre authored and Changaco committed Jun 10, 2014
1 parent 11b30cf commit 2989eb3
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
5 changes: 5 additions & 0 deletions branch.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BEGIN;

ALTER TABLE participants ADD COLUMN is_closed bool NOT NULL DEFAULT FALSE;

END;
23 changes: 22 additions & 1 deletion gittip/models/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,13 @@ def set_as_claimed(self):
UPDATE participants
SET claimed_time=CURRENT_TIMESTAMP
, is_closed=false
WHERE username=%s
AND claimed_time IS NULL
RETURNING claimed_time
""", (self.username,))
self.set_attributes(claimed_time=claimed_time)
self.set_attributes(claimed_time=claimed_time, is_closed=False)


# Canceling
Expand Down Expand Up @@ -274,6 +275,7 @@ def cancel(self, disbursement_strategy):
self.clear_tips_giving(cursor)
self.clear_tips_receiving(cursor)
self.clear_personal_information(cursor)
self.update_is_closed(True, cursor)

return self.archive(cursor)

Expand Down Expand Up @@ -551,6 +553,25 @@ def update_goal(self, goal):
)
self.set_attributes(goal=goal)

def update_is_closed(self, is_closed, cursor=None):
ctx = None
if cursor is None:
ctx = self.db.get_cursor()
cursor = ctx.__enter__()
try:
cursor.run( "UPDATE participants SET is_closed=%(is_closed)s "
"WHERE username=%(username)s"
, dict(username=self.username, is_closed=is_closed)
)
add_event( cursor
, 'participant'
, dict(id=self.id, action='set', values=dict(is_closed=is_closed))
)
self.set_attributes(is_closed=is_closed)
finally:
if ctx is not None:
ctx.__exit__(None, None, None)


def set_tip_to(self, tippee, amount, cursor=None):
"""Given a Participant or username, and amount as str, return a tuple.
Expand Down
27 changes: 27 additions & 0 deletions tests/py/test_cancel.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,30 @@ def test_cpi_clears_teams(self):
alice.clear_personal_information(cursor)

assert len(team.get_takes()) == 1


# uic = update_is_closed

def test_uic_updates_is_closed(self):
alice = self.make_participant('alice')
alice.update_is_closed(True)

assert alice.is_closed
assert Participant.from_username('alice').is_closed

def test_uic_updates_is_closed_False(self):
alice = self.make_participant('alice')
alice.update_is_closed(True)
alice.update_is_closed(False)

assert not alice.is_closed
assert not Participant.from_username('alice').is_closed

def test_uic_uses_supplied_cursor(self):
alice = self.make_participant('alice')

with self.db.get_cursor() as cursor:
alice.update_is_closed(True, cursor)
assert alice.is_closed
assert not Participant.from_username('alice').is_closed
assert Participant.from_username('alice').is_closed
6 changes: 6 additions & 0 deletions tests/py/test_participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,12 @@ def test_claiming_participant(self):
expected = datetime.timedelta(seconds=0.1)
assert actual < expected

def test_claiming_participant_resets_is_closed_to_false(self):
self.participant.update_is_closed(True)
self.participant.set_as_claimed()
assert not self.participant.is_closed
assert not Participant.from_username('user1').is_closed

def test_changing_username_successfully(self):
self.participant.change_username('user2')
actual = Participant.from_username('user2')
Expand Down

0 comments on commit 2989eb3

Please sign in to comment.