Skip to content

Commit

Permalink
Merge pull request #42 from jacobwegner/add-initiator-to-signals
Browse files Browse the repository at this point in the history
Add initiator to signals
  • Loading branch information
jacobwegner committed Mar 14, 2016
2 parents 67a076b + 3613051 commit 0f4645d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
21 changes: 11 additions & 10 deletions pinax/teams/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def is_owner(self, user):
def is_on_team(self, user):
return self.acceptances.filter(user=user).exists()

def add_member(self, user, role=None, state=None):
def add_member(self, user, role=None, state=None, by=None):
# we do this, rather than put the Membership constants in declaration
# because Membership is not yet defined
if role is None:
Expand All @@ -150,17 +150,18 @@ def add_member(self, user, role=None, state=None):
user=user,
defaults={"role": role, "state": state},
)
signals.added_member.send(sender=self, membership=membership, by=by)
return membership

def add_user(self, user, role):
def add_user(self, user, role, by=None):
state = Membership.STATE_AUTO_JOINED
if self.manager_access == Team.MANAGER_ACCESS_INVITE:
state = Membership.STATE_INVITED
membership, _ = self.memberships.get_or_create(
user=user,
defaults={"role": role, "state": state}
)
signals.added_member.send(sender=self, membership=membership)
signals.added_member.send(sender=self, membership=membership, by=by)
return membership

def invite_user(self, from_user, to_email, role, message=None):
Expand All @@ -171,7 +172,7 @@ def invite_user(self, from_user, to_email, role, message=None):
defaults={"role": role, "state": Membership.STATE_INVITED}
)
invite.send_invite()
signals.invited_user.send(sender=self, membership=membership)
signals.invited_user.send(sender=self, membership=membership, by=from_user)
return membership

def for_user(self, user):
Expand Down Expand Up @@ -255,7 +256,7 @@ def promote(self, by):
if self.role == Membership.ROLE_MEMBER:
self.role = Membership.ROLE_MANAGER
self.save()
signals.promoted_member.send(sender=self, membership=self)
signals.promoted_member.send(sender=self, membership=self, by=by)
return True
return False

Expand All @@ -265,7 +266,7 @@ def demote(self, by):
if self.role == Membership.ROLE_MANAGER:
self.role = Membership.ROLE_MEMBER
self.save()
signals.demoted_member.send(sender=self, membership=self)
signals.demoted_member.send(sender=self, membership=self, by=by)
return True
return False

Expand Down Expand Up @@ -304,20 +305,20 @@ def status(self):
return self.invite.get_status_display()
return "Unknown"

def resend_invite(self):
def resend_invite(self, by=None):
if self.invite is not None:
code = self.invite.signup_code
code.expiry = timezone.now() + datetime.timedelta(days=5)
code.save()
code.send()
signals.resent_invite.send(sender=self, membership=self)
signals.resent_invite.send(sender=self, membership=self, by=by)

def remove(self):
def remove(self, by=None):
if self.invite is not None:
self.invite.signup_code.delete()
self.invite.delete()
self.delete()
signals.removed_membership.send(sender=Membership, team=self.team, user=self.user)
signals.removed_membership.send(sender=Membership, team=self.team, user=self.user, invitee=self.invitee, by=by)

@property
def invitee(self):
Expand Down
12 changes: 6 additions & 6 deletions pinax/teams/signals.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import django.dispatch


added_member = django.dispatch.Signal(providing_args=["membership"])
invited_user = django.dispatch.Signal(providing_args=["membership"])
promoted_member = django.dispatch.Signal(providing_args=["membership"])
demoted_member = django.dispatch.Signal(providing_args=["membership"])
added_member = django.dispatch.Signal(providing_args=["membership", "by"])
invited_user = django.dispatch.Signal(providing_args=["membership", "by"])
promoted_member = django.dispatch.Signal(providing_args=["membership", "by"])
demoted_member = django.dispatch.Signal(providing_args=["membership", "by"])
accepted_membership = django.dispatch.Signal(providing_args=["membership"])
rejected_membership = django.dispatch.Signal(providing_args=["membership"])
resent_invite = django.dispatch.Signal(providing_args=["membership"])
removed_membership = django.dispatch.Signal(providing_args=["team", "user"])
resent_invite = django.dispatch.Signal(providing_args=["membership", "by"])
removed_membership = django.dispatch.Signal(providing_args=["team", "user", "invitee", "by"])
6 changes: 3 additions & 3 deletions pinax/teams/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def render_to_response(self, context, **response_kwargs):
@require_POST
def team_member_revoke_invite(request, pk):
membership = get_object_or_404(request.team.memberships.all(), pk=pk)
membership.remove()
membership.remove(by=request.user)
data = {
"html": ""
}
Expand All @@ -310,7 +310,7 @@ def team_member_revoke_invite(request, pk):
@require_POST
def team_member_resend_invite(request, pk):
membership = get_object_or_404(request.team.memberships.all(), pk=pk)
membership.resend_invite()
membership.resend_invite(by=request.user)
data = {
"html": render_to_string(
"teams/_membership.html",
Expand Down Expand Up @@ -361,7 +361,7 @@ def team_member_demote(request, pk):
@require_POST
def team_member_remove(request, pk):
membership = get_object_or_404(request.team.memberships.all(), pk=pk)
membership.remove()
membership.remove(by=request.user)
data = {
"html": ""
}
Expand Down

0 comments on commit 0f4645d

Please sign in to comment.