diff --git a/branch.sql b/branch.sql new file mode 100644 index 0000000000..20c086f178 --- /dev/null +++ b/branch.sql @@ -0,0 +1,5 @@ +BEGIN; + + ALTER TABLE participants ADD COLUMN is_closed bool NOT NULL DEFAULT FALSE; + +END; diff --git a/gittip/models/participant.py b/gittip/models/participant.py index b7cc85bcc2..d00158be77 100644 --- a/gittip/models/participant.py +++ b/gittip/models/participant.py @@ -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 @@ -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) @@ -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. diff --git a/tests/py/test_cancel.py b/tests/py/test_cancel.py index 514e1f4219..9f6cca97d5 100644 --- a/tests/py/test_cancel.py +++ b/tests/py/test_cancel.py @@ -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 diff --git a/tests/py/test_participant.py b/tests/py/test_participant.py index 75764d2c9b..16f803182f 100644 --- a/tests/py/test_participant.py +++ b/tests/py/test_participant.py @@ -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')