Example #1
0
def unsubscribe(request,
                form_class=NetworkUnsubscribeForm,
                template_name='networks/unsubscribe.html'):
    message = None

    if request.method == 'POST':
        form = form_class(request.POST)
        if form.is_valid():
            email = form.cleaned_data['email']
            email_user = get_email_user(email)

            if email_user:
                if email_user.is_bulk:
                    email_user.softdelete()
                    message = _(
                        "The email address has been successfully removed from our mailing lists."
                    )
                else:
                    message = _(
                        "The email address is associated with a myEWB account - you must sign in to delete your account.."
                    )
            else:
                message = _(
                    "The email address you entered is not listed in our records as a mailing list recipient. Please ensure you entered the address correctly, or enter another email address."
                )
    else:
        form = form_class()

    return render_to_response(template_name, {
        "form": form,
        "message": message,
    },
                              context_instance=RequestContext(request))
Example #2
0
def bulk_remove(request,
                group_slug,
                model=BaseGroup,
                form_class=GroupBulkImportForm,
                template_name=None):
    group = get_object_or_404(model, slug=group_slug)

    if not group.can_bulk_add(request.user):
        return render_to_response('denied.html',
                                  context_instance=RequestContext(request))

    if request.method == 'POST':
        form = form_class(request.POST)
        if form.is_valid():
            raw_emails = form.cleaned_data['emails']
            emails = raw_emails.split()  # splits by whitespace characters

            for email in emails:
                email_user = get_email_user(email)
                if email_user is not None:
                    group.remove_member(email_user)
            return HttpResponseRedirect(
                reverse('%s_detail' % model._meta.verbose_name,
                        kwargs={'group_slug': group.slug}))
    else:
        form = form_class()
    return render_to_response(template_name, {
        "group": group,
        "form": form,
    },
                              context_instance=RequestContext(request))
Example #3
0
def mass_delete(request):
    if request.method == 'POST':
        # re-use GroupBulkImportForm because it does all we need
        # (TODO: genericize that =) )
        form = GroupBulkImportForm(request.POST)
        if form.is_valid():
            raw_emails = form.cleaned_data['emails']
            emails = raw_emails.split()  # splits by whitespace characters
            success = 0

            for email in emails:
                email_user = get_email_user(email)
                if email_user is not None and email_user.is_bulk:
                    email_user.softdelete()
                    success += 1

            request.user.message_set.create(message="Deleted %d of %d" %
                                            (success, len(emails)))
            return HttpResponseRedirect(reverse('home'))
    else:
        form = GroupBulkImportForm()
    return render_to_response("profiles/mass_delete.html", {
        "form": form,
    },
                              context_instance=RequestContext(request))
Example #4
0
def bulk_import(request, group_slug, form_class=NetworkBulkImportForm, template_name='networks/bulk_import.html'):
    group = get_object_or_404(Network, slug=group_slug)
    if request.method == 'POST':
        form = form_class(request.POST)
        if form.is_valid():
            raw_emails = form.cleaned_data['emails']
            emails = raw_emails.split()   # splits by whitespace characters
            
            for email in emails:
                email_user = get_email_user(email)
                if email_user is None:
                    username = User.objects.make_random_password()     # not a password per se, just a random string
                    while User.objects.filter(username=username).count() > 0:   # ensure uniqueness
                        username = User.objects.make_random_password()
                    email_user = User.extras.create_bulk_user(username, email)      # sets "unusable" password
                
                existing_members = group.members.filter(user=email_user)
                if existing_members.count() == 0:              
                    nm = group.add_member(email_user)
            # redirect to network home page on success
            return HttpResponseRedirect(reverse('network_detail', kwargs={'group_slug': group.slug}))
    else:
        form = form_class()
    return render_to_response(template_name, {
        "group": group,
        "form": form,
    }, context_instance=RequestContext(request))
Example #5
0
def clean_up_bulk_users(sender, instance, created, **kwargs):
    if instance.verified:
        # XXX Warning! This only works because get_email_user returns
        # the user with their email set to the argument before it returns
        # users with EmailAddress's with the argument
        email_user = get_email_user(instance.email)
        user = instance.user
        # a 
        if email_user and not email_user == user:
            # update group memberships
            for membership in email_user.member_groups.all():
                if not user.member_groups.filter(group=membership.group):
                    membership.user = instance.user
                    membership.save()
                else:
                    membership.delete()
                    
            # update membership records (should we just delete them instead?)
            for record in email_user.group_records.all():
                record.user = instance.user
                record.save()
                
            # update invitations
            for invitation in email_user.pending_memberships.all():
                if not user.pending_memberships.filter(group=invitation.group):
                    invitation.user = instance.user
                    invitation.save()
                else:
                    invitation.delete()
                
            # delete old bulk user
            email_user.delete()
Example #6
0
def clean_up_bulk_users(sender, instance, created, **kwargs):
    if instance.verified:
        # XXX Warning! This only works because get_email_user returns
        # the user with their email set to the argument before it returns
        # users with EmailAddress's with the argument
        email_user = get_email_user(instance.email)
        user = instance.user
        # a
        if email_user and not email_user == user:
            # update group memberships
            for membership in email_user.member_groups.all():
                if not user.member_groups.filter(group=membership.group):
                    membership.user = instance.user
                    membership.save()
                else:
                    membership.delete()

            # update membership records (should we just delete them instead?)
            for record in email_user.group_records.all():
                record.user = instance.user
                record.save()

            # update invitations
            for invitation in email_user.pending_memberships.all():
                if not user.pending_memberships.filter(group=invitation.group):
                    invitation.user = instance.user
                    invitation.save()
                else:
                    invitation.delete()

            # delete old bulk user
            email_user.delete()
Example #7
0
 def add_email(self, email):
     """
     Adds an email address to the group, creating the new bulk user if needed
     """
     email_user = get_email_user(email)
     if email_user is None:
         email_user = User.extras.create_bulk_user(email)
     
     self.add_member(email_user)
Example #8
0
    def add_email(self, email):
        """
        Adds an email address to the group, creating the new bulk user if needed
        """
        email_user = get_email_user(email)
        if email_user is None:
            email_user = User.extras.create_bulk_user(email)

        self.add_member(email_user)
Example #9
0
 def test_create_bulk_users(self):
     email_list = '''[email protected]
     [email protected]
     [email protected]
     [email protected]
     '''
     self.client.login(username='******', password='******')
     self.client.post('/networks/ewb/bulk/', {'emails':email_list})
     self.assertEquals(self.ewb.members.bulk().count(), 4)
     for email in email_list.split():
         self.assertTrue(get_email_user(email).member_groups.get(group__slug='ewb'))
Example #10
0
 def add_email(self, email):
     """
     Adds an email address to the group, creating the new bulk user if needed
     """
     email_user = get_email_user(email)
     if email_user is None:
         username = User.objects.make_random_password()     # not a password per se, just a random string
         while User.objects.filter(username=username).count() > 0:   # ensure uniqueness
             username = User.objects.make_random_password()
         email_user = User.extras.create_bulk_user(username, email)      # sets "unusable" password
     
     self.add_member(email_user)
Example #11
0
 def test_create_bulk_users(self):
     email_list = '''[email protected]
     [email protected]
     [email protected]
     [email protected]
     '''
     self.client.login(username='******', password='******')
     self.client.post('/networks/ewb/bulkimport/', {'emails': email_list})
     self.assertEquals(self.ewb.members.bulk().count(), 4)
     for email in email_list.split():
         self.assertTrue(
             get_email_user(email).member_groups.get(group__slug='ewb'))
Example #12
0
def clean_up_bulk_users(sender, instance, created, **kwargs):
    if instance.verified:
        # XXX Warning! This only works because get_email_user returns
        # the user with their email set to the argument before it returns
        # users with EmailAddress's with the argument
        email_user = get_email_user(instance.email)
        user = instance.user
        # a 
        if not email_user == user:
            for membership in email_user.member_groups.all():
                if not user.member_groups.filter(group=membership.group):
                    membership.user = instance.user
                    membership.save()
            # delete old bulk user - should delete GroupMember objects as well
            email_user.delete()
Example #13
0
 def test_verify_email_for_bulk_user(self):
     new_network = Network.objects.create(slug='new-net', name='new network', creator=self.superman)
     self.assertTrue(self.client.login(username='******', password='******'))
     self.client.post('/networks/new-net/bulk/', {'emails':'*****@*****.**'})
     bulk_user = get_email_user('*****@*****.**')
     self.joe.emailaddress_set.add(EmailAddress(email='*****@*****.**'))
     email_address = self.joe.emailaddress_set.get(email='*****@*****.**')
     email_address.verified = True
     email_address.save()
     joe_member = new_network.members.get(user=self.joe)
     # joe should be accepted
     self.assertTrue(joe_member.is_accepted)
     # old dummy user should be gone
     self.assertRaises(User.DoesNotExist, User.objects.get, id=bulk_user.id)
     self.assertEquals(new_network.members.bulk().count(), 0)
     new_network.delete()
Example #14
0
def bulk_remove(request, group_slug, form_class=NetworkBulkImportForm, template_name='networks/bulk_remove.html'):
    group = get_object_or_404(Network, slug=group_slug)
    if request.method == 'POST':
        form = form_class(request.POST)
        if form.is_valid():
            raw_emails = form.cleaned_data['emails']
            emails = raw_emails.split()   # splits by whitespace characters
            
            for email in emails:
                email_user = get_email_user(email)
                if email_user is not None:
                    group.remove_member(email_user)
            return HttpResponseRedirect(reverse('network_detail', kwargs={'group_slug': group.slug}))
    else:
        form = form_class()
    return render_to_response(template_name, {
        "group": group,
        "form": form,
    }, context_instance=RequestContext(request))
Example #15
0
def unsubscribe(request, form_class=NetworkUnsubscribeForm, template_name='networks/unsubscribe.html'):
    if request.method == 'POST':
        form = form_class(request.POST)
        message = None
        if form.is_valid():
            email = form.cleaned_data['email']            
            email_user = get_email_user(email)
            
            if email_user and not email_user.has_usable_password():
                email_user.delete()
                message = _("The email address has been successfully removed from our mailing lists.")
            else:
                message = _("The email address you entered is not listed in our records as a mailing list recipient. Please ensure you entered the address correctly, or enter another email address.")
    
    form = form_class()
    return render_to_response(template_name, {
        "form": form,
        "message": message,
    }, context_instance=RequestContext(request))
Example #16
0
 def test_verify_email_for_bulk_user(self):
     new_network = Network.objects.create(slug='new-net',
                                          name='new network',
                                          creator=self.superman)
     self.assertTrue(
         self.client.login(username='******', password='******'))
     response = self.client.post('/networks/new-net/bulkimport/',
                                 {'emails': '*****@*****.**'})
     bulk_user = get_email_user('*****@*****.**')
     self.joe.emailaddress_set.add(EmailAddress(email='*****@*****.**'))
     email_address = self.joe.emailaddress_set.get(email='*****@*****.**')
     email_address.verified = True
     email_address.save()
     joe_member = new_network.members.get(user=self.joe)
     # joe should be accepted
     self.assertTrue(joe_member.is_accepted)
     # old dummy user should be gone
     self.assertRaises(User.DoesNotExist, User.objects.get, id=bulk_user.id)
     self.assertEquals(new_network.members.bulk().count(), 0)
     new_network.delete()
Example #17
0
def mass_delete(request):
    if request.method == 'POST':
        # re-use GroupBulkImportForm because it does all we need
        # (TODO: genericize that =) )
        form = GroupBulkImportForm(request.POST)
        if form.is_valid():
            raw_emails = form.cleaned_data['emails']
            emails = raw_emails.split()   # splits by whitespace characters
            success = 0
            
            for email in emails:
                email_user = get_email_user(email)
                if email_user is not None and email_user.is_bulk:
                    email_user.softdelete()
                    success += 1
                
            request.user.message_set.create(message="Deleted %d of %d" % (success, len(emails)))
            return HttpResponseRedirect(reverse('home'))
    else:
        form = GroupBulkImportForm()
    return render_to_response("profiles/mass_delete.html", {
        "form": form,
    }, context_instance=RequestContext(request))
Example #18
0
def bulk_remove(request, group_slug, model=BaseGroup, form_class=GroupBulkImportForm, template_name=None):
    group = get_object_or_404(model, slug=group_slug)

    if not group.can_bulk_add(request.user):
        return render_to_response('denied.html', context_instance=RequestContext(request))
    
    if request.method == 'POST':
        form = form_class(request.POST)
        if form.is_valid():
            raw_emails = form.cleaned_data['emails']
            emails = raw_emails.split()   # splits by whitespace characters
            
            for email in emails:
                email_user = get_email_user(email, verified_only=False)
                if email_user is not None:
                    group.remove_member(email_user)
            return HttpResponseRedirect(reverse('%s_detail' % model._meta.verbose_name, kwargs={'group_slug': group.slug}))
    else:
        form = form_class()
    return render_to_response(template_name, {
        "group": group,
        "form": form,
    }, context_instance=RequestContext(request))