Example #1
0
def report_bt_event(email, result, object, action):
    value = 1 if result.is_success else -1
    report_ga_event_async(email,
                          category=object,
                          action=action,
                          label='braintree',
                          value=value)
Example #2
0
def test_view(request):
    """Send a test message to an active autoresponder."""

    autoresponds = AutoResponse.objects.filter(user=request.user)

    if request.method == 'POST':
        email = request.POST.get("email")
        if email in [
                autorespond.credentials.email for autorespond in autoresponds
        ]:
            try:
                _request_test_message(email)
                messages.success(request, 'Successfully sent a test message.')
                report_ga_event_async(email,
                                      category='autoresponse',
                                      action='test',
                                      label='success')
            except:
                logger.exception('failed to send test message')
                messages.error(request, 'Failed to send a test message.')
                report_ga_event_async(email,
                                      category='autoresponse',
                                      action='test',
                                      label='failure')

            return redirect('autorespond')
    return HttpResponseBadRequest()
Example #3
0
def autorespond_view(request):
    """List/update accounts and autoresponses."""

    if not request.user.is_authenticated():
        return redirect('logged_out')

    gcredentials = GoogleCredential.objects.filter(user=request.user)
    license = request.user.currentlicense.license

    if request.method == 'GET':
        autoresponds = AutoResponse.objects.filter(user=request.user)

        formset = AutoResponseFormSet(credentials=gcredentials,
                                      queryset=autoresponds)

        c = {
            'user': request.user,
            'is_active': license.is_active,
            'gcredentials': gcredentials,
            'autorespond_formset': formset,
        }
        c.update(csrf(request))

        return render_to_response('logged_in.html', c)

    elif request.method == 'POST':
        formset = AutoResponseFormSet(gcredentials, request.POST)
        if formset.is_valid():
            autoresponds = formset.save(
                commit=False)  # save_m2m if add many 2 many
            for autorespond in formset.deleted_objects:
                thread_pool.submit(_send_to_worker, 'post',
                                   "/stop/%s" % autorespond.id)
                autorespond.delete()
                report_ga_event_async(autorespond.credentials.email,
                                      category='autoresponse',
                                      action='delete')

            for autorespond in autoresponds:
                autorespond.user = request.user
                autorespond.save()
                thread_pool.submit(_send_to_worker, 'post',
                                   "/restart/%s" % autorespond.id)
                report_ga_event_async(autorespond.credentials.email,
                                      category='autoresponse',
                                      action='upsert')

            return redirect('autorespond')
        else:
            c = {
                'user': request.user,
                'is_active': license.is_active,
                'gcredentials': gcredentials,
                'autorespond_formset': formset,
            }
            c.update(csrf(request))

            return render_to_response('logged_in.html', c, status=400)
    else:
        return HttpResponseBadRequest()
Example #4
0
    def _sent_reply(self, jid, message=None):
        """Perform any bookkeeping needed after a response is sent.

        Args:
            jid: the jid that was responded to.
            message (string): the message received. None if unknown.
        """

        self.response_throttle.update(jid.bare)
        report_ga_event_async(self.email, category='message', action='receive')
Example #5
0
def autorespond_view(request):
    """List/update accounts and autoresponses."""

    if not request.user.is_authenticated():
        return redirect('logged_out')

    gcredentials = GoogleCredential.objects.filter(user=request.user)
    license = request.user.currentlicense.license

    if request.method == 'GET':
        autoresponds = AutoResponse.objects.filter(user=request.user)

        formset = AutoResponseFormSet(credentials=gcredentials, queryset=autoresponds)

        c = {
            'user': request.user,
            'is_active': license.is_active,
            'gcredentials': gcredentials,
            'autorespond_formset': formset,
        }
        c.update(csrf(request))

        return render_to_response('logged_in.html', c)

    elif request.method == 'POST':
        formset = AutoResponseFormSet(gcredentials, request.POST)
        if formset.is_valid():
            autoresponds = formset.save(commit=False)   # save_m2m if add many 2 many
            for autorespond in formset.deleted_objects:
                thread_pool.submit(_send_to_worker, 'post', "/stop/%s" % autorespond.id)
                autorespond.delete()
                report_ga_event_async(autorespond.credentials.email, category='autoresponse', action='delete')

            for autorespond in autoresponds:
                autorespond.user = request.user
                autorespond.save()
                thread_pool.submit(_send_to_worker, 'post', "/restart/%s" % autorespond.id)
                report_ga_event_async(autorespond.credentials.email, category='autoresponse', action='upsert')

            return redirect('autorespond')
        else:
            c = {
                'user': request.user,
                'is_active': license.is_active,
                'gcredentials': gcredentials,
                'autorespond_formset': formset,
            }
            c.update(csrf(request))

            return render_to_response('logged_in.html', c, status=400)
    else:
        return HttpResponseBadRequest()
Example #6
0
    def _sent_reply(self, jid, message=None):
        """Perform any bookkeeping needed after a response is sent.

        Args:
            jid: the jid that was responded to.
            message (string): the message received. None if unknown.
        """

        self.last_reply_datetime[jid] = datetime.datetime.now()

        report_ga_event_async(self.email, category='message', action='receive')

        if self.notify_email is not None:
            from_identifier = jid.jid
            from_nick = self.client_roster[jid.jid]['name']
            if from_nick:
                from_identifier = "%s (%s)" % (from_nick, jid.jid)

            body_paragraphs = ["gchat.simon.codes just responded to a message from %s." % from_identifier]

            if message is not None:
                body_paragraphs.append("The message we received was \"%s\"." % message.encode('utf-8'))
            else:
                body_paragraphs.append("Due to a bug on Google's end, we didn't receive a message body.")

            body_paragraphs.append("We replied with your autoresponse \"%s\"." % self.response.encode('utf-8'))

            body_paragraphs.append(
                "If any of this is unexpected or strange, email [email protected] for support.")

            email = EmailMessage(
                subject='gchat.simon.codes sent an autoresponse',
                to=[self.notify_email],
                body='\n\n'.join(body_paragraphs),
                reply_to=['*****@*****.**'],
            )
            email.send(fail_silently=True)
            self.logger.info("sent an email notification to %r", self.notify_email)
Example #7
0
def autorespond_view(request):
    """List/update accounts and autoresponses."""

    if not request.user.is_authenticated():
        return redirect('logged_out')

    gcredentials = GoogleCredential.objects.filter(user=request.user)
    autoresponds = AutoResponse.objects.filter(user=request.user)
    excludeds = ExcludedUser.objects.filter(autorespond__user=request.user)
    license = request.user.currentlicense.license

    if request.method == 'GET':
        autorespond_formset = AutoResponseFormSet(credentials=gcredentials,
                                                  queryset=autoresponds)
        excluded_formset = ExcludedUserFormSet(autoresponds=autoresponds,
                                               queryset=excludeds)

        c = {
            'user': request.user,
            'is_active': license.is_active,
            'gcredentials': gcredentials,
            'autorespond_formset': autorespond_formset,
            'excluded_formset': excluded_formset,
        }

        return render(request, 'logged_in.html', c)

    elif request.method == 'POST':
        autorespond_formset = AutoResponseFormSet(gcredentials, request.POST)
        excluded_formset = ExcludedUserFormSet(autoresponds, request.POST)

        if request.POST.get(
                "submit_autoresponses") and autorespond_formset.is_valid():
            autoresponds = autorespond_formset.save(
                commit=False)  # save_m2m if add many 2 many
            for autorespond in autorespond_formset.deleted_objects:
                thread_pool.submit(_send_to_worker, 'post',
                                   "/stop/%s" % autorespond.id)
                autorespond.delete()
                report_ga_event_async(autorespond.credentials.email,
                                      category='autoresponse',
                                      action='delete')

            for autorespond in autoresponds:
                autorespond.user = request.user
                autorespond.save()
                thread_pool.submit(_send_to_worker, 'post',
                                   "/restart/%s" % autorespond.id)
                report_ga_event_async(autorespond.credentials.email,
                                      category='autoresponse',
                                      action='upsert')

            return redirect('autorespond')
        elif request.POST.get(
                "submit_excludeds") and excluded_formset.is_valid():
            excludeds = excluded_formset.save(
                commit=False)  # save_m2m if add many 2 many
            restart_ids = set()
            for excluded in excluded_formset.deleted_objects:
                restart_ids.add(excluded.autorespond.id)
                excluded.delete()
                report_ga_event_async(excluded.autorespond.credentials.email,
                                      category='excluded',
                                      action='delete')

            for excluded in excludeds:
                restart_ids.add(excluded.autorespond.id)
                excluded.save()
                report_ga_event_async(excluded.autorespond.credentials.email,
                                      category='excluded',
                                      action='upsert')

            for restart_id in restart_ids:
                thread_pool.submit(_send_to_worker, 'post',
                                   "/restart/%s" % restart_id)

            return redirect('autorespond')
        else:
            # Don't use the empty submitted data for the other form.
            if request.POST.get("submit_excludeds"):
                autorespond_formset = AutoResponseFormSet(
                    credentials=gcredentials, queryset=autoresponds)
            elif request.POST.get("submit_autoresponses"):
                excluded_formset = ExcludedUserFormSet(
                    autoresponds=autoresponds, queryset=excludeds)

            c = {
                'user': request.user,
                'is_active': license.is_active,
                'gcredentials': gcredentials,
                'autorespond_formset': autorespond_formset,
                'excluded_formset': excluded_formset,
            }

            return render(request, 'logged_in.html', c, status=400)
    else:
        return HttpResponseBadRequest()
Example #8
0
def handle_activate(sender, user, **kwargs):
    report_ga_event_async(user.email, category='user', action='activate')
Example #9
0
def handle_register(sender, user, **kwargs):
    report_ga_event_async(user.email, category='user', action='register')
Example #10
0
def report_bt_event(email, result, object, action):
    value = 1 if result.is_success else -1
    report_ga_event_async(email, category=object, action=action, label='braintree', value=value)