Beispiel #1
0
def email_reply(request, comment_id):
    """ handle a reply received via email """

    log.debug("replies.views.email_reply")

    api_key = request.POST.get('api-key')
    if not api_key == settings.INTERNAL_API_KEY:
        log.error('Invalid API KEY used for internal API!')
        return http.HttpResponseForbidden()
    
    from_user = request.POST.get('from')
    reply_text = request.POST.get('text')
    reply_text = utils.extract_reply(reply_text)
    
    comment = None
    try:
        comment = PageComment.objects.get(id=comment_id)
    except PageComment.DoesNotExist:
        log.error("Reply does not exist")

    user = None
    try:
        user = UserProfile.objects.get(username=from_user)
    except UserProfile.DoesNotExist:
        log.error("Invalid user attempted reply: {0}".format(from_user))

    if comment and user and reply_text and not comment.deleted:
        comment.reply(user, reply_text, True)

    return http.HttpResponse(status=200)
Beispiel #2
0
def email_reply(request, comment_id):
    """ handle a reply received via email """

    log.debug("replies.views.email_reply")

    api_key = request.POST.get('api-key')
    if not api_key == settings.INTERNAL_API_KEY:
        log.error('Invalid API KEY used for internal API!')
        return http.HttpResponseForbidden()

    from_user = request.POST.get('from')
    reply_text = request.POST.get('text')
    reply_text = utils.extract_reply(reply_text)

    comment = None
    try:
        comment = PageComment.objects.get(id=comment_id)
    except PageComment.DoesNotExist:
        log.error("Reply does not exist")

    user = None
    try:
        user = UserProfile.objects.get(username=from_user)
    except UserProfile.DoesNotExist:
        log.error("Invalid user attempted reply: {0}".format(from_user))

    if comment and user and reply_text and not comment.deleted:
        comment.reply(user, reply_text, True)

    return http.HttpResponse(status=200)
Beispiel #3
0
def comment_page_callback(request, page_model, page_app_label, page_pk,
                          scope_model, scope_app_label, scope_pk):
    """ callback used when replying by email to an activity"""

    log.debug("replies.views.comment_page_callback")

    api_key = request.POST.get('api-key')
    if not api_key == settings.INTERNAL_API_KEY:
        log.error('Invalid API KEY used for internal API!')
        return http.HttpResponseForbidden()

    from_user = request.POST.get('from')
    reply_text = request.POST.get('text')
    reply_text = utils.extract_reply(reply_text)

    user = None
    try:
        user = UserProfile.objects.get(username=from_user)
    except UserProfile.DoesNotExist:
        log.error("Invalid user attempted reply: {0}".format(from_user))

    page_object = None
    try:
        page_ct_cls = ContentType.objects.get(
            model=page_model, app_label=page_app_label).model_class()
        page_object = page_ct_cls.objects.get(pk=page_pk)
    except:
        log.error("could not find page object")

    scope_object = None
    try:
        scope_ct_cls = ContentType.objects.get(
            model=scope_model, app_label=scope_app_label).model_class()
        scope_object = get_object_or_404(scope_ct_cls, pk=scope_pk)
    except:
        log.error("could not find scope object")

    if user and user.can_post() and page_object and page_object.can_comment(
            user.user) and scope_object and reply_text:
        comment = PageComment(content=reply_text)
        comment.page_object = page_object
        comment.scope_object = scope_object
        comment.author = user
        comment.sent_by_email = True
        comment.save()

    return http.HttpResponse(status=200)
Beispiel #4
0
def comment_page_callback(request, page_model, page_app_label, page_pk,
        scope_model, scope_app_label, scope_pk):
    """ callback used when replying by email to an activity"""

    log.debug("replies.views.comment_page_callback")

    api_key = request.POST.get('api-key')
    if not api_key == settings.INTERNAL_API_KEY:
        log.error('Invalid API KEY used for internal API!')
        return http.HttpResponseForbidden()
    
    from_user = request.POST.get('from')
    reply_text = request.POST.get('text')
    reply_text = utils.extract_reply(reply_text)

    user = None
    try:
        user = UserProfile.objects.get(username=from_user)
    except UserProfile.DoesNotExist:
        log.error("Invalid user attempted reply: {0}".format(from_user))

    page_object = None
    try:
        page_ct_cls = ContentType.objects.get(model=page_model,
        app_label=page_app_label).model_class()
        page_object = page_ct_cls.objects.get(pk=page_pk)
    except:
        log.error("could not find page object")

    scope_object = None
    try:
        scope_ct_cls = ContentType.objects.get(model=scope_model,
            app_label=scope_app_label).model_class()
        scope_object = get_object_or_404(scope_ct_cls, pk=scope_pk)
    except:
        log.error("could not find scope object")

    if user and page_object and page_object.can_comment(user.user) and scope_object and reply_text:
        comment = PageComment(content=reply_text)
        comment.page_object = page_object
        comment.scope_object = scope_object
        comment.author = user
        comment.sent_by_email = True
        comment.save()

    return http.HttpResponse(status=200)