def add_member(self, userprofile, status=GroupMembership.MEMBER): """ Add a user to this group. Optionally specify status other than member. If user is already in the group with the given status, this is a no-op. If user is already in the group with a different status, their status will be updated. """ defaults = dict(status=status, date_joined=now()) membership, created = GroupMembership.objects.get_or_create( userprofile=userprofile, group=self, defaults=defaults ) if created: if status == GroupMembership.MEMBER: # Joined update_basket_task.delay(userprofile.id) elif not created and membership.status != status: # Status changed old_status = membership.status membership.status = status membership.save() update_basket_task.delay(userprofile.id) if (old_status, status) == (GroupMembership.PENDING, GroupMembership.MEMBER): # Request accepted email_membership_change.delay(self.pk, userprofile.user.pk, old_status, status)
def add_member(self, userprofile, status=GroupMembership.MEMBER): """ Add a user to this group. Optionally specify status other than member. If user is already in the group with the given status, this is a no-op. If user is already in the group with a different status, their status will be updated if the change is a promotion. Otherwise, their status will not change. """ defaults = dict(status=status, date_joined=now()) membership, created = GroupMembership.objects.get_or_create(userprofile=userprofile, group=self, defaults=defaults) if membership.status != status: # Status changed # The only valid status change states are: # PENDING to MEMBER # PENDING to PENDING_TERMS # PENDING_TERMS to MEMBER old_status = membership.status membership.status = status statuses = [(GroupMembership.PENDING, GroupMembership.MEMBER), (GroupMembership.PENDING, GroupMembership.PENDING_TERMS), (GroupMembership.PENDING_TERMS, GroupMembership.MEMBER)] if (old_status, status) in statuses: # Status changed membership.save() if membership.status in [GroupMembership.PENDING, GroupMembership.MEMBER]: email_membership_change.delay(self.pk, userprofile.user.pk, old_status, status)
def add_member(self, userprofile, status=GroupMembership.MEMBER): """ Add a user to this group. Optionally specify status other than member. If user is already in the group with the given status, this is a no-op. If user is already in the group with a different status, their status will be updated if the change is a promotion. Otherwise, their status will not change. """ defaults = dict(status=status, date_joined=now()) membership, created = GroupMembership.objects.get_or_create(userprofile=userprofile, group=self, defaults=defaults) if created: if status == GroupMembership.MEMBER: # Joined # Group is functional area, we want to sent this update to Basket if self.functional_area: update_basket_task.delay(userprofile.id) else: if membership.status != status: # Status changed old_status = membership.status membership.status = status if (old_status, status) == (GroupMembership.PENDING, GroupMembership.MEMBER): # Request accepted membership.save() if self.functional_area: # Group is functional area, we want to sent this update to Basket. update_basket_task.delay(userprofile.id) 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, send_email=True): membership = GroupMembership.objects.get(group=self, userprofile=userprofile) old_status = membership.status membership.delete() update_basket_task.delay(userprofile.id) if old_status == GroupMembership.PENDING and send_email: # Request denied email_membership_change.delay(self.pk, userprofile.user.pk, old_status, None)
def add_member(self, userprofile, status=GroupMembership.MEMBER, inviter=None): """ Add a user to this group. Optionally specify status other than member. If user is already in the group with the given status, this is a no-op. If user is already in the group with a different status, their status will be updated if the change is a promotion. Otherwise, their status will not change. If the group in question is the NDA group, also add the user to the NDA newsletter. """ defaults = dict(status=status, date_joined=now()) membership, _ = GroupMembership.objects.get_or_create(userprofile=userprofile, group=self, defaults=defaults) send_userprofile_to_cis.delay(membership.userprofile.pk) # Remove the need_removal flag in any case # We have a renewal, let's save the object. if membership.needs_renewal: membership.needs_renewal = False membership.save() if membership.status != status: # Status changed # The only valid status change states are: # PENDING to MEMBER # PENDING to PENDING_TERMS # PENDING_TERMS to MEMBER old_status = membership.status membership.status = status statuses = [(GroupMembership.PENDING, GroupMembership.MEMBER), (GroupMembership.PENDING, GroupMembership.PENDING_TERMS), (GroupMembership.PENDING_TERMS, GroupMembership.MEMBER)] if (old_status, status) in statuses: # Status changed membership.save() if membership.status in [GroupMembership.PENDING, GroupMembership.MEMBER]: email_membership_change.delay(self.pk, userprofile.user.pk, old_status, status) # Since there is no demotion, we can check if the new status is MEMBER and # subscribe the user to the NDA newsletter if the group is NDA if self.name == settings.NDA_GROUP and status == GroupMembership.MEMBER: subscribe_user_to_basket.delay(userprofile.id, [settings.BASKET_NDA_NEWSLETTER]) if inviter: # Set the invite to the last person who renewed the membership invite = get_object_or_none(Invite, group=membership.group, redeemer=userprofile) if invite: invite.inviter = inviter invite.save()
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() update_basket_task.delay(userprofile.id) if old_status == GroupMembership.PENDING and send_email: # Request denied email_membership_change.delay(self.pk, userprofile.user.pk, old_status, None)
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 group is functional area, we want to sent this update to Basket if self.functional_area: update_basket_task.delay(userprofile.id) if old_status == GroupMembership.PENDING and send_email: # Request denied email_membership_change.delay(self.pk, userprofile.user.pk, old_status, None)
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 group is functional area, we want to sent this update to Basket if self.functional_area: update_basket_task.delay(userprofile.id) 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 and send_email: # Member removed member_removed_email.delay(self.pk, userprofile.user.pk)
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 and 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. """ 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 add_member(self, userprofile, status=GroupMembership.MEMBER): """ Add a user to this group. Optionally specify status other than member. If user is already in the group with the given status, this is a no-op. If user is already in the group with a different status, their status will be updated if the change is a promotion. Otherwise, their status will not change. If the group in question is the NDA group, also add the user to the NDA newsletter. """ defaults = dict(status=status, date_joined=now()) membership, created = GroupMembership.objects.get_or_create( userprofile=userprofile, group=self, defaults=defaults) if membership.status != status: # Status changed # The only valid status change states are: # PENDING to MEMBER # PENDING to PENDING_TERMS # PENDING_TERMS to MEMBER old_status = membership.status membership.status = status statuses = [ (GroupMembership.PENDING, GroupMembership.MEMBER), (GroupMembership.PENDING, GroupMembership.PENDING_TERMS), (GroupMembership.PENDING_TERMS, GroupMembership.MEMBER) ] if (old_status, status) in statuses: # Status changed membership.save() if membership.status in [ GroupMembership.PENDING, GroupMembership.MEMBER ]: email_membership_change.delay(self.pk, userprofile.user.pk, old_status, status) # Since there is no demotion, we can check if the new status is MEMBER and # subscribe the user to the NDA newsletter if the group is NDA if self.name == settings.NDA_GROUP and status == GroupMembership.MEMBER: update_basket_task.delay(userprofile.id, [settings.BASKET_NDA_NEWSLETTER])
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 add_member(self, userprofile, status=GroupMembership.MEMBER): """ Add a user to this group. Optionally specify status other than member. If user is already in the group with the given status, this is a no-op. If user is already in the group with a different status, their status will be updated if the change is a promotion. Otherwise, their status will not change. If the group in question is the NDA group, also add the user to the NDA newsletter. """ defaults = dict(status=status, date_joined=now()) membership, created = GroupMembership.objects.get_or_create(userprofile=userprofile, group=self, defaults=defaults) if membership.status != status: # Status changed # The only valid status change states are: # PENDING to MEMBER # PENDING to PENDING_TERMS # PENDING_TERMS to MEMBER old_status = membership.status membership.status = status statuses = [(GroupMembership.PENDING, GroupMembership.MEMBER), (GroupMembership.PENDING, GroupMembership.PENDING_TERMS), (GroupMembership.PENDING_TERMS, GroupMembership.MEMBER)] if (old_status, status) in statuses: # Status changed membership.save() if membership.status in [GroupMembership.PENDING, GroupMembership.MEMBER]: email_membership_change.delay(self.pk, userprofile.user.pk, old_status, status) # Since there is no demotion, we can check if the new status is MEMBER and # subscribe the user to the NDA newsletter if the group is NDA if self.name == settings.NDA_GROUP and status == GroupMembership.MEMBER: subscribe_user_to_basket.delay(userprofile.id, [settings.BASKET_NDA_NEWSLETTER])
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 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)