From 0b88b4dee6f8deb374fa66bc308f5c91b96670cd Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Wed, 31 Aug 2016 20:47:21 -0400 Subject: [PATCH] Allow owners to add themselves --- gratipay/models/team/mixins/takes.py | 11 ++++++++--- tests/py/test_billing_payday.py | 6 ++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/gratipay/models/team/mixins/takes.py b/gratipay/models/team/mixins/takes.py index a7d2f558d3..7357ea8e2e 100644 --- a/gratipay/models/team/mixins/takes.py +++ b/gratipay/models/team/mixins/takes.py @@ -82,10 +82,15 @@ def vet(p): vet(participant) vet(recorder) - if recorder.username == self.owner: - if take not in (ZERO, PENNY): + owner_recording = recorder.username == self.owner + owner_taking = participant.username == self.owner + taker_recording = recorder == participant + adding_or_removing = take in (ZERO, PENNY) + + if owner_recording: + if not adding_or_removing and not owner_taking: raise NotAllowed("owner can only add and remove members, not otherwise set takes") - elif recorder != participant: + elif not taker_recording: raise NotAllowed("can only set own take") with self.db.get_cursor(cursor) as cursor: diff --git a/tests/py/test_billing_payday.py b/tests/py/test_billing_payday.py index ce990d07aa..7ccc2f09fd 100644 --- a/tests/py/test_billing_payday.py +++ b/tests/py/test_billing_payday.py @@ -609,13 +609,11 @@ def test_pt_clips_to_balance_when_less_than_available(self): assert P('zorro').balance == D(' 0.00') assert P('picard').balance == D(' 0.00') - def test_pt_is_NOT_happy_to_deal_the_owner_in(self): + def test_pt_is_happy_to_deal_the_owner_in(self): self.make_member('crusher', 150) self.make_member('bruiser', 250) self.enterprise.set_take_for(self.picard, D('0.01'), self.picard) - with pytest.raises(NotAllowed): - self.enterprise.set_take_for(self.picard, 50, self.picard) - return # XXX allow owners to join teams! + self.enterprise.set_take_for(self.picard, 50, self.picard) self.run_through_takes() assert P('crusher').balance == D('150.00') assert P('bruiser').balance == D('250.00')