def remove_member(self, userprofile, send_email=True): try: membership = GroupMembership.objects.get(group=self, userprofile=userprofile) except GroupMembership.DoesNotExist: return old_status = membership.status membership.delete() if old_status == GroupMembership.PENDING and send_email: # Request denied email_membership_change.delay(self.pk, userprofile.user.pk, old_status, None) elif old_status == GroupMembership.MEMBER: # If group is the NDA group, unsubscribe user from the newsletter. if self.name == settings.NDA_GROUP: unsubscribe_from_basket_task.delay( userprofile.email, userprofile.basket_token, [settings.BASKET_NDA_NEWSLETTER]) if send_email: # Member removed member_removed_email.delay(self.pk, userprofile.user.pk) # delete the invitation to the group if exists Invite.objects.filter(group=self, redeemer=userprofile).delete()
def update_basket(sender, instance, **kwargs): newsletters = [settings.BASKET_VOUCHED_NEWSLETTER] if instance.is_vouched: update_basket_task.delay(instance.id, newsletters) elif instance.basket_token: unsubscribe_from_basket_task.delay(instance.email, instance.basket_token, newsletters)
def remove_member(self, userprofile, status=None, send_email=False): """Change membership status for a group. If user is a member of an open group, then the user is removed. If a user is a member of a reviewed or closed group, then the membership is in a pending state. """ try: membership = GroupMembership.objects.get(group=self, userprofile=userprofile) except GroupMembership.DoesNotExist: return old_status = membership.status # If the group is of type Group.OPEN, delete membership # If no status is given, delete membership, # If the current membership is PENDING*, delete membership if (not status or self.accepting_new_members == Group.OPEN or old_status != GroupMembership.MEMBER): # We have either an open group or the request to join a reviewed group is denied # or the curator manually declined a user in a pending state. membership.delete() send_userprofile_to_cis.delay(membership.userprofile.pk) # delete the invitation to the group if exists Invite.objects.filter(group=self, redeemer=userprofile).delete() send_email = True # Group is either of Group.REVIEWED or Group.CLOSED, change membership to `status` else: # if we are here, there is a new status for our user membership.status = status membership.needs_renewal = False membership.save() send_email = True # If group is the NDA group, unsubscribe user from the newsletter. if self.name == settings.NDA_GROUP: unsubscribe_from_basket_task.delay( userprofile.email, [settings.BASKET_NDA_NEWSLETTER]) if send_email: email_membership_change.delay(self.pk, userprofile.user.pk, old_status, status)
def remove_member(self, userprofile, status=None, send_email=False): """Change membership status for a group. If user is a member of an open group, then the user is removed. If a user is a member of a reviewed or closed group, then the membership is in a pending state. """ try: membership = GroupMembership.objects.get(group=self, userprofile=userprofile) except GroupMembership.DoesNotExist: return old_status = membership.status # If the group is of type Group.OPEN, delete membership # If no status is given, delete membership, # If the current membership is PENDING*, delete membership if (not status or self.accepting_new_members == Group.OPEN or old_status != GroupMembership.MEMBER): # We have either an open group or the request to join a reviewed group is denied # or the curator manually declined a user in a pending state. membership.delete() # delete the invitation to the group if exists Invite.objects.filter(group=self, redeemer=userprofile).delete() send_email = True # Group is either of Group.REVIEWED or Group.CLOSED, change membership to `status` else: # if we are here, there is a new status for our user membership.status = status membership.needs_renewal = False membership.save() send_email = True # If group is the NDA group, unsubscribe user from the newsletter. if self.name == settings.NDA_GROUP: unsubscribe_from_basket_task.delay(userprofile.email, [settings.BASKET_NDA_NEWSLETTER]) if send_email: email_membership_change.delay(self.pk, userprofile.user.pk, old_status, status)
def remove_member(self, userprofile, send_email=True): try: membership = GroupMembership.objects.get(group=self, userprofile=userprofile) except GroupMembership.DoesNotExist: return old_status = membership.status membership.delete() if old_status == GroupMembership.PENDING and send_email: # Request denied email_membership_change.delay(self.pk, userprofile.user.pk, old_status, None) elif old_status == GroupMembership.MEMBER: # If group is the NDA group, unsubscribe user from the newsletter. if self.name == settings.NDA_GROUP: unsubscribe_from_basket_task.delay(userprofile.email, userprofile.basket_token, [settings.BASKET_NDA_NEWSLETTER]) if send_email: # Member removed member_removed_email.delay(self.pk, userprofile.user.pk) # delete the invitation to the group if exists Invite.objects.filter(group=self, redeemer=userprofile).delete()
def remove_member(self, userprofile, status=None, send_email=False): """Change membership status for a group. If user is a member of an open group, then the user is removed. If a user is a member of a reviewed or closed group, then the membership is in a pending state. """ # Avoid circular dependencies from mozillians.users.models import UserProfile try: membership = GroupMembership.objects.get(group=self, userprofile=userprofile) except GroupMembership.DoesNotExist: return old_status = membership.status # If the group is of type Group.OPEN, delete membership # If no status is given, delete membership, # If the current membership is PENDING*, delete membership if (not status or self.accepting_new_members == Group.OPEN or old_status != GroupMembership.MEMBER): # We have either an open group or the request to join a reviewed group is denied # or the curator manually declined a user in a pending state. membership.delete() # delete the invitation to the group if exists Invite.objects.filter(group=self, redeemer=userprofile).delete() send_email = True # Remove all the access groups the user is a member of # if the group to remove is the NDA if self.name == settings.NDA_GROUP: group_memberships = GroupMembership.objects.none() # If the user is not staff, we need to delete the memberships to any access group if not userprofile.can_create_access_groups: group_memberships = GroupMembership.objects.filter(userprofile=userprofile, group__is_access_group=True) for access_membership in group_memberships: group = access_membership.group if not group.curator_can_leave(userprofile): # If the user is the only curator, let's add the superusers as curators # as a fallback option for super_user in UserProfile.objects.filter(user__is_superuser=True): group.curators.add(super_user) if not group.has_member(super_user): group.add_member(super_user) group.curators.remove(userprofile) access_membership.delete() # Notify CIS about this change send_userprofile_to_cis.delay(access_membership.userprofile.pk) # Notify CIS about this change send_userprofile_to_cis.delay(membership.userprofile.pk) # Group is either of Group.REVIEWED or Group.CLOSED, change membership to `status` else: # if we are here, there is a new status for our user membership.status = status membership.needs_renewal = False membership.save() send_email = True # If group is the NDA group, unsubscribe user from the newsletter. if self.name == settings.NDA_GROUP: unsubscribe_from_basket_task.delay(userprofile.email, [settings.BASKET_NDA_NEWSLETTER]) if send_email: email_membership_change.delay(self.pk, userprofile.user.pk, old_status, status)
def unsubscribe_from_basket(sender, instance, **kwargs): unsubscribe_from_basket_task.delay(instance.email, instance.basket_token)
def update_basket(sender, instance, **kwargs): if instance.is_vouched: update_basket_task.delay(instance.id) elif instance.basket_token: unsubscribe_from_basket_task.delay(instance.email, instance.basket_token)
def unsubscribe_from_basket(sender, instance, **kwargs): newsletters = [ settings.BASKET_VOUCHED_NEWSLETTER, settings.BASKET_NDA_NEWSLETTER ] unsubscribe_from_basket_task.delay(instance.email, newsletters)
def unsubscribe_from_basket(sender, instance, **kwargs): newsletters = [settings.BASKET_VOUCHED_NEWSLETTER, settings.BASKET_NDA_NEWSLETTER] unsubscribe_from_basket_task.delay(instance.email, newsletters)
def update_basket(sender, instance, **kwargs): newsletters = [settings.BASKET_VOUCHED_NEWSLETTER] if instance.is_vouched: subscribe_user_to_basket.delay(instance.id, newsletters) else: unsubscribe_from_basket_task.delay(instance.email, newsletters)
def remove_member(self, userprofile, status=None, send_email=False): """Change membership status for a group. If user is a member of an open group, then the user is removed. If a user is a member of a reviewed or closed group, then the membership is in a pending state. """ # Avoid circular dependencies from mozillians.users.models import UserProfile try: membership = GroupMembership.objects.get(group=self, userprofile=userprofile) except GroupMembership.DoesNotExist: return old_status = membership.status # If the group is of type Group.OPEN, delete membership # If no status is given, delete membership, # If the current membership is PENDING*, delete membership if (not status or self.accepting_new_members == Group.OPEN or old_status != GroupMembership.MEMBER): # We have either an open group or the request to join a reviewed group is denied # or the curator manually declined a user in a pending state. membership.delete() # delete the invitation to the group if exists Invite.objects.filter(group=self, redeemer=userprofile).delete() send_email = True # Remove all the access groups the user is a member of # if the group to remove is the NDA if self.name == settings.NDA_GROUP: group_memberships = GroupMembership.objects.none() # If the user is not staff, we need to delete the memberships to any access group if not userprofile.can_create_access_groups: group_memberships = GroupMembership.objects.filter( userprofile=userprofile, group__is_access_group=True) for access_membership in group_memberships: group = access_membership.group if not group.curator_can_leave(userprofile): # If the user is the only curator, let's add the superusers as curators # as a fallback option for super_user in UserProfile.objects.filter( user__is_superuser=True): group.curators.add(super_user) if not group.has_member(super_user): group.add_member(super_user) group.curators.remove(userprofile) access_membership.delete() # Notify CIS about this change send_userprofile_to_cis.delay( access_membership.userprofile.pk) # Notify CIS about this change send_userprofile_to_cis.delay(membership.userprofile.pk) # Group is either of Group.REVIEWED or Group.CLOSED, change membership to `status` else: # if we are here, there is a new status for our user membership.status = status membership.needs_renewal = False membership.save() send_email = True # If group is the NDA group, unsubscribe user from the newsletter. if self.name == settings.NDA_GROUP: unsubscribe_from_basket_task.delay( userprofile.email, [settings.BASKET_NDA_NEWSLETTER]) if send_email: email_membership_change.delay(self.pk, userprofile.user.pk, old_status, status)