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/account_elsewhere.py b/gittip/models/account_elsewhere.py index 9b2da78bc1..0e3b23739a 100644 --- a/gittip/models/account_elsewhere.py +++ b/gittip/models/account_elsewhere.py @@ -154,6 +154,8 @@ def opt_in(self, desired_username): user.participant.change_username(desired_username) except ProblemChangingUsername: pass + if user.participant.is_closed: + user.participant.update_is_closed(False) return user, newly_claimed def save_token(self, token, refresh_token=None, expires=None): diff --git a/gittip/models/participant.py b/gittip/models/participant.py index b7cc85bcc2..2005d2f774 100644 --- a/gittip/models/participant.py +++ b/gittip/models/participant.py @@ -274,6 +274,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 +552,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_elsewhere.py b/tests/py/test_elsewhere.py index d5351b48c3..cdd11969dc 100644 --- a/tests/py/test_elsewhere.py +++ b/tests/py/test_elsewhere.py @@ -2,6 +2,7 @@ from gittip.elsewhere import UserInfo from gittip.models.account_elsewhere import AccountElsewhere +from gittip.models.participant import Participant from gittip.testing import Harness import gittip.testing.elsewhere as user_info_examples @@ -33,6 +34,13 @@ def test_opt_in_doesnt_have_to_change_username(self): actual = account.opt_in('bob')[0].participant.username assert actual == expected + def test_opt_in_resets_is_closed_to_false(self): + alice = self.make_elsewhere('twitter', 1, 'alice') + alice.participant.update_is_closed(True) + user = alice.opt_in('alice')[0] + assert not user.participant.is_closed + assert not Participant.from_username('alice').is_closed + def test_redirect_csrf(self): response = self.client.GxT('/on/github/redirect') assert response.code == 405