Esempio n. 1
0
    def test_comment_reply_api_key(self):
        comment = PageComment()
        comment.page_object = self.page
        comment.scope_object = self.project
        comment.author = self.user
        comment.content = "blah blah"
        comment.save()

        data = {
            u"api-key": "notthecorrectkey",
            u"from": u"*****@*****.**",
            u"text": u"Some stealthy reply that won't make it in!\n",
        }

        response = self.client.post("/{0}/comments/{1}/email_reply/".format(self.locale, comment.id), data)
        self.assertEqual(response.status_code, 403)
Esempio n. 2
0
    def test_comment_reply_api_key(self):
        comment = PageComment()
        comment.page_object = self.page
        comment.scope_object = self.project
        comment.author = self.user
        comment.content = "blah blah"
        comment.save()
        
        data = {
            u'api-key': 'notthecorrectkey',
            u'from': self.test_username,
            u'text': u'Some stealthy reply that won\'t make it in!\n',
        }

        response = self.client.post('/{0}/comments/{1}/email_reply/'.format(self.locale, comment.id), data)
        self.assertEqual(response.status_code, 403)
Esempio n. 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)
Esempio n. 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)
Esempio n. 5
0
    def test_repy(self):
        comment = PageComment()
        comment.page_object = self.page
        comment.scope_object = self.project
        comment.author = self.user
        comment.content = "blah blah"
        comment.save()

        self.client.login(username=self.test_username, password=self.test_password)

        # post reply
        data = { 'content': 'This is a reply' }
        reply_url = '/{0}/comments/{1}/reply/'.format(self.locale, comment.id)
        response = self.client.post(reply_url, data)
            
        comments = PageComment.objects.all()
        self.assertEquals(comments.count(), 2)
Esempio n. 6
0
    def test_reply_by_email(self):
        # post a comment
        comment = PageComment()
        comment.page_object = self.page
        comment.scope_object = self.project
        comment.author = self.user
        comment.content = "blah blah"
        comment.save()

        data = {u"api-key": settings.INTERNAL_API_KEY, u"from": u"*****@*****.**", u"text": u"Maybe this time\n"}

        comment_count = PageComment.objects.filter(sent_by_email=True).count()
        response = self.client.post("/{0}/comments/{1}/email_reply/".format(self.locale, comment.id), data)
        self.assertEqual(response.status_code, 200)

        comments = PageComment.objects.filter(sent_by_email=True)
        self.assertEquals(comments.count(), comment_count + 1)
Esempio n. 7
0
    def test_repy(self):
        comment = PageComment()
        comment.page_object = self.page
        comment.scope_object = self.project
        comment.author = self.user
        comment.content = "blah blah"
        comment.save()

        self.client.login(username=self.test_username,
                          password=self.test_password)

        # post reply
        data = {'content': 'This is a reply'}
        reply_url = '/{0}/comments/{1}/reply/'.format(self.locale, comment.id)
        response = self.client.post(reply_url, data)

        comments = PageComment.objects.all()
        self.assertEquals(comments.count(), 2)
Esempio n. 8
0
    def test_comment_reply_api_key(self):
        comment = PageComment()
        comment.page_object = self.page
        comment.scope_object = self.project
        comment.author = self.user
        comment.content = "blah blah"
        comment.save()

        data = {
            u'api-key': 'notthecorrectkey',
            u'from': self.test_username,
            u'text': u'Some stealthy reply that won\'t make it in!\n',
        }

        response = self.client.post(
            '/{0}/comments/{1}/email_reply/'.format(self.locale, comment.id),
            data)
        self.assertEqual(response.status_code, 403)
Esempio n. 9
0
    def test_reply_by_email(self):
        # post a comment
        comment = PageComment()
        comment.page_object = self.page
        comment.scope_object = self.project
        comment.author = self.user
        comment.content = "blah blah"
        comment.save()
        
        data = {
            u'api-key': settings.INTERNAL_API_KEY,
            u'from': self.test_username,
            u'text': u'Maybe this time\n',
        }

        comment_count = PageComment.objects.filter(sent_by_email=True).count()
        response = self.client.post('/{0}/comments/{1}/email_reply/'.format(self.locale, comment.id), data)
        self.assertEqual(response.status_code, 200)

        comments = PageComment.objects.filter(sent_by_email=True)
        self.assertEquals(comments.count(), comment_count+1)
Esempio n. 10
0
    def test_reply_by_email(self):
        # post a comment
        comment = PageComment()
        comment.page_object = self.page
        comment.scope_object = self.project
        comment.author = self.user
        comment.content = "blah blah"
        comment.save()

        data = {
            u'api-key': settings.INTERNAL_API_KEY,
            u'from': self.test_username,
            u'text': u'Maybe this time\n',
        }

        comment_count = PageComment.objects.filter(sent_by_email=True).count()
        response = self.client.post(
            '/{0}/comments/{1}/email_reply/'.format(self.locale, comment.id),
            data)
        self.assertEqual(response.status_code, 200)

        comments = PageComment.objects.filter(sent_by_email=True)
        self.assertEquals(comments.count(), comment_count + 1)