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

Commit

Permalink
Allow owners to add themselves
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed Sep 1, 2016
1 parent 241bc51 commit 3ac7fee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
11 changes: 8 additions & 3 deletions gratipay/models/team/mixins/takes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 4 additions & 7 deletions tests/py/test_billing_payday.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from gratipay.billing.payday import NoPayday, Payday
from gratipay.exceptions import NegativeBalance
from gratipay.models.participant import Participant
from gratipay.models.team.mixins.takes import NotAllowed
from gratipay.testing import Foobar, D,P
from gratipay.testing.billing import BillingHarness
from gratipay.testing.emails import EmailHarness
Expand Down Expand Up @@ -609,17 +608,15 @@ 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, 200, self.picard)
self.run_through_takes()
assert P('crusher').balance == D('150.00')
assert P('bruiser').balance == D('250.00')
assert P('picard').balance == D(' 50.00')
assert P('bruiser').balance == D('150.00') # Sorry, bruiser.
assert P('picard').balance == D('200.00')


class TestNotifyParticipants(EmailHarness):
Expand Down

0 comments on commit 3ac7fee

Please sign in to comment.