Пример #1
0
    def _test_thread_read(self):
        """thread read flag is set for user, then its set as unread by reply"""
        self.reply_thread(self.thread)

        add_acl(self.user, self.categories)
        threadstracker.make_read_aware(self.user, self.thread)
        self.assertFalse(self.thread.is_read)

        threadstracker.read_thread(self.user, self.thread, self.post)
        threadstracker.make_read_aware(self.user, self.thread)
        self.assertTrue(self.thread.is_read)
        categoriestracker.make_read_aware(self.user, self.categories)
        self.assertTrue(self.category.is_read)

        self.thread.last_post_on = timezone.now()
        self.thread.save()
        self.category.synchronize()
        self.category.save()

        self.reply_thread()
        threadstracker.make_read_aware(self.user, self.thread)
        self.assertFalse(self.thread.is_read)
        categoriestracker.make_read_aware(self.user, self.categories)
        self.assertFalse(self.category.is_read)

        posts = [post for post in self.thread.post_set.order_by('id')]
        threadstracker.make_posts_read_aware(self.user, self.thread, posts)

        for post in posts[:-1]:
            self.assertTrue(post.is_read)
        self.assertFalse(posts[-1].is_read)
Пример #2
0
    def test_new(self):
        """new returns link to first unread post"""
        self.user.new_threads = MockThreadsCounter()
        self.user.unread_threads = MockThreadsCounter()

        post_link = goto.new(self.user, self.thread)
        self.assertEqual(post_link, goto.last(self.user, self.thread))

        # add 18 posts to add extra page to thread, then read them
        [reply_thread(self.thread) for p in xrange(18)]
        threadstracker.read_thread(
            self.user, self.thread, self.thread.last_post)

        # add extra unread posts
        first_unread = reply_thread(self.thread)
        [reply_thread(self.thread) for p in xrange(30)]

        new_link = goto.new(self.user, self.thread)
        post_link = goto.get_post_link(
            50, self.thread.post_set, self.thread, first_unread)
        self.assertEqual(new_link, post_link)

        # read thread
        threadstracker.read_thread(
            self.user, self.thread, self.thread.last_post)

        # assert new() points to last reply
        post_link = goto.new(self.user, self.thread)
        self.assertEqual(post_link, goto.last(self.user, self.thread))
Пример #3
0
    def test_thread_read(self):
        """thread read flag is set for user, then its set as unread by reply"""
        self.reply_thread()

        add_acl(self.user, self.categories)
        threadstracker.make_read_aware(self.user, self.thread)
        self.assertFalse(self.thread.is_read)

        threadstracker.read_thread(self.user, self.thread, self.post)
        threadstracker.make_read_aware(self.user, self.thread)
        self.assertTrue(self.thread.is_read)
        categoriestracker.make_read_aware(self.user, self.categories)
        self.assertTrue(self.category.is_read)

        self.thread.last_post_on = timezone.now()
        self.thread.save()
        self.category.synchronize()
        self.category.save()

        self.reply_thread()
        threadstracker.make_read_aware(self.user, self.thread)
        self.assertFalse(self.thread.is_read)
        categoriestracker.make_read_aware(self.user, self.categories)
        self.assertFalse(self.category.is_read)

        posts = [post for post in self.thread.post_set.order_by('id')]
        threadstracker.make_posts_read_aware(self.user, self.thread, posts)

        for post in posts[:-1]:
            self.assertTrue(post.is_read)
        self.assertFalse(posts[-1].is_read)
Пример #4
0
    def test_new(self):
        """new returns link to first unread post"""
        self.user.new_threads = MockThreadsCounter()
        self.user.unread_threads = MockThreadsCounter()

        post_link = goto.new(self.user, self.thread, self.thread.post_set)
        last_link = goto.last(self.thread, self.thread.post_set)
        self.assertEqual(post_link, last_link)

        # add 18 posts to add extra page to thread, then read them
        [reply_thread(self.thread) for p in xrange(18)]
        threadstracker.read_thread(
            self.user, self.thread, self.thread.last_post)

        # add extra unread posts
        first_unread = reply_thread(self.thread)
        [reply_thread(self.thread) for p in xrange(30)]

        new_link = goto.new(self.user, self.thread, self.thread.post_set)
        post_link = goto.get_post_link(
            50, self.thread.post_set, self.thread, first_unread)
        self.assertEqual(new_link, post_link)

        # read thread
        threadstracker.read_thread(
            self.user, self.thread, self.thread.last_post)

        # assert new() points to last reply
        post_link = goto.new(self.user, self.thread, self.thread.post_set)
        last_link = goto.last(self.thread, self.thread.post_set)
        self.assertEqual(post_link, last_link)
Пример #5
0
def post_read_endpoint(request, thread, post):
    make_posts_read_aware(request.user, thread, [post])
    if not post.is_read:
        read_thread(request.user, thread, post)
        if thread.subscription:
            thread.subscription.last_read_on = post.posted_on
    return Response({'detail': 'ok'})
Пример #6
0
def post_read_endpoint(request, thread, post):
    make_posts_read_aware(request.user, thread, [post])
    if not post.is_read:
        read_thread(request.user, thread, post)
        if thread.subscription:
            thread.subscription.last_read_on = post.posted_on
        return Response({'thread_is_read': thread.last_post_on <= post.posted_on})
    return Response({'thread_is_read': True})
Пример #7
0
    def dispatch(self, request, *args, **kwargs):
        relations = ['forum', 'starter', 'last_poster', 'first_post']
        thread = self.fetch_thread(request, select_related=relations, **kwargs)
        forum = thread.forum

        self.check_forum_permissions(request, forum)
        self.check_thread_permissions(request, thread)

        validate_slug(thread, kwargs['thread_slug'])

        threadstracker.make_read_aware(request.user, thread)

        thread_actions = self.ThreadActions(user=request.user, thread=thread)
        posts_actions = self.PostsActions(user=request.user, thread=thread)

        if request.method == 'POST':
            if thread_actions.query_key in request.POST:
                response = thread_actions.handle_post(request, thread)
                if response:
                    return response
            if posts_actions.query_key in request.POST:
                queryset = self.get_posts_queryset(request.user, forum, thread)
                response = posts_actions.handle_post(request, queryset)
                if response:
                    return response

        page, posts = self.get_posts(request.user, forum, thread, kwargs)
        make_posts_reports_aware(request.user, thread, posts)

        threadstracker.make_posts_read_aware(request.user, thread, posts)
        threadstracker.read_thread(request.user, thread, posts[-1])

        try:
            allow_reply_thread(request.user, thread)
            thread_reply_message = None
        except PermissionDenied as e:
            thread_reply_message = unicode(e)

        return self.render(request, {
            'link_name': request.resolver_match.view_name,
            'links_params': {
                'thread_id': thread.id, 'thread_slug': thread.slug
            },

            'forum': forum,
            'path': get_forum_path(forum),

            'thread': thread,
            'thread_actions': thread_actions,
            'thread_reply_message': thread_reply_message,

            'posts': posts,
            'posts_actions': posts_actions,
            'selected_posts': posts_actions.get_selected_ids(),

            'paginator': page.paginator,
            'page': page,
        })
Пример #8
0
    def dispatch(self, request, *args, **kwargs):
        relations = ['forum', 'starter', 'last_poster', 'first_post']
        thread = self.fetch_thread(request, select_related=relations, **kwargs)
        forum = thread.forum

        self.check_forum_permissions(request, forum)
        self.check_thread_permissions(request, thread)

        validate_slug(thread, kwargs['thread_slug'])

        threadstracker.make_read_aware(request.user, thread)

        thread_actions = self.ThreadActions(user=request.user, thread=thread)
        posts_actions = self.PostsActions(user=request.user, thread=thread)

        if request.method == 'POST':
            if thread_actions.query_key in request.POST:
                response = thread_actions.handle_post(request, thread)
                if response:
                    return response
            if posts_actions.query_key in request.POST:
                queryset = self.get_posts_queryset(request.user, forum, thread)
                response = posts_actions.handle_post(request, queryset)
                if response:
                    return response

        page, posts = self.get_posts(request.user, forum, thread, kwargs)

        threadstracker.make_posts_read_aware(request.user, thread, posts)
        threadstracker.read_thread(request.user, thread, posts[-1])

        try:
            allow_reply_thread(request.user, thread)
            thread_reply_message = None
        except PermissionDenied as e:
            thread_reply_message = unicode(e)

        return self.render(request, {
            'link_name': thread.get_url_name(),
            'links_params': {
                'thread_id': thread.id, 'thread_slug': thread.slug
            },

            'forum': forum,
            'path': get_forum_path(forum),

            'thread': thread,
            'thread_actions': thread_actions,
            'thread_reply_message': thread_reply_message,

            'posts': posts,
            'posts_actions': posts_actions,
            'selected_posts': posts_actions.get_selected_ids(),

            'paginator': page.paginator,
            'page': page,
        })
Пример #9
0
def post_read_endpoint(request, thread, post):
    make_posts_read_aware(request.user, thread, [post])
    if not post.is_read:
        read_thread(request.user, thread, post)
        if thread.subscription and thread.subscription.last_read_on < post.posted_on:
            thread.subscription.last_read_on = post.posted_on
            thread.subscription.save()
        return Response(
            {'thread_is_read': thread.last_post_on <= post.posted_on})
    return Response({'thread_is_read': True})
Пример #10
0
    def test_goto_first_new_post_in_read_thread(self):
        """goto new in read thread points to last post"""
        for i in range(settings.MISAGO_POSTS_PER_PAGE + settings.MISAGO_POSTS_TAIL):
            post = testutils.reply_thread(self.thread, posted_on=timezone.now())

        make_thread_read_aware(self.user, self.thread)
        read_thread(self.user, self.thread, self.thread.last_post)

        response = self.client.get(self.thread.get_new_post_url())
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response['location'], GOTO_PAGE_URL % (self.thread.get_absolute_url(), 2, post.pk))
Пример #11
0
    def test_goto_first_new_post(self):
        """first unread post redirect url in already read thread is valid"""
        make_thread_read_aware(self.user, self.thread)
        read_thread(self.user, self.thread, self.thread.last_post)

        post = testutils.reply_thread(self.thread, posted_on=timezone.now())
        for i in range(settings.MISAGO_POSTS_PER_PAGE + settings.MISAGO_POSTS_TAIL - 1):
            testutils.reply_thread(self.thread, posted_on=timezone.now())

        response = self.client.get(self.thread.get_new_post_url())
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response['location'], GOTO_URL % (self.thread.get_absolute_url(), post.pk))
Пример #12
0
    def test_read_category_prunes_threadreads(self):
        """read_category prunes threadreads in this category"""
        thread = self.post_thread(timezone.now())

        threadstracker.make_read_aware(self.user, thread)
        threadstracker.read_thread(self.user, thread, thread.last_post)

        self.assertTrue(self.user.threadread_set.exists())

        categoriestracker.read_category(self.user, self.category)

        self.assertTrue(self.user.categoryread_set.get(category=self.category))
        self.assertFalse(self.user.threadread_set.exists())
Пример #13
0
    def test_goto_first_new_post(self):
        """first unread post redirect url in already read thread is valid"""
        make_thread_read_aware(self.user, self.thread)
        read_thread(self.user, self.thread, self.thread.last_post)

        post = testutils.reply_thread(self.thread, posted_on=timezone.now())
        for i in range(settings.MISAGO_POSTS_PER_PAGE +
                       settings.MISAGO_POSTS_TAIL - 1):
            testutils.reply_thread(self.thread, posted_on=timezone.now())

        response = self.client.get(self.thread.get_new_post_url())
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response['location'],
                         GOTO_URL % (self.thread.get_absolute_url(), post.pk))
Пример #14
0
    def test_sync_record_for_category_threads_behind_cutoff(self):
        """
        sync_record sets read flag on category with only thread being behind cutoff
        """
        self.post_thread(timezone.now() - timedelta(days=180))

        read_thread = self.post_thread(timezone.now())

        threadstracker.make_read_aware(self.user, read_thread)
        threadstracker.read_thread(self.user, read_thread, read_thread.last_post)

        category = Category.objects.get(pk=self.category.pk)
        categoriestracker.make_read_aware(self.user, [category])
        self.assertTrue(category.is_read)
Пример #15
0
    def test_goto_first_new_post_in_read_thread(self):
        """goto new in read thread points to last post"""
        for i in range(settings.MISAGO_POSTS_PER_PAGE +
                       settings.MISAGO_POSTS_TAIL):
            post = testutils.reply_thread(self.thread,
                                          posted_on=timezone.now())

        make_thread_read_aware(self.user, self.thread)
        read_thread(self.user, self.thread, self.thread.last_post)

        response = self.client.get(self.thread.get_new_post_url())
        self.assertEqual(response.status_code, 302)
        self.assertEqual(
            response['location'],
            GOTO_PAGE_URL % (self.thread.get_absolute_url(), 2, post.pk))
Пример #16
0
    def test_vie_handles_unapproved_posts(self):
        """if thread has unapproved posts, redirect to first of them"""
        for i in range(settings.MISAGO_POSTS_PER_PAGE + settings.MISAGO_POSTS_TAIL):
            testutils.reply_thread(self.thread, posted_on=timezone.now())

        make_thread_read_aware(self.user, self.thread)
        read_thread(self.user, self.thread, self.thread.last_post)

        post = testutils.reply_thread(self.thread, is_unapproved=True, posted_on=timezone.now())
        for i in range(settings.MISAGO_POSTS_PER_PAGE + settings.MISAGO_POSTS_TAIL - 1):
            testutils.reply_thread(self.thread, posted_on=timezone.now())

        self.grand_permission()

        response = self.client.get(self.thread.get_new_post_url())
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response['location'], GOTO_PAGE_URL % (self.thread.get_absolute_url(), 2, post.pk))
Пример #17
0
    def dispatch(self, request, *args, **kwargs):
        relations = ['forum', 'starter', 'last_poster', 'first_post']
        thread = self.fetch_thread(request, select_related=relations, **kwargs)
        forum = thread.forum

        self.check_forum_permissions(request, forum)
        self.check_thread_permissions(request, thread)

        threadstracker.make_read_aware(request.user, thread)

        page, posts = self.get_posts(request.user, forum, thread, kwargs)
        threadstracker.make_posts_read_aware(thread, posts)
        threadstracker.read_thread(request.user, thread, posts[-1])

        return self.render(request, {
            'forum': forum,
            'path': get_forum_path(forum),
            'thread': thread,
            'posts': posts,
            'page': page,
            'paginator': page.paginator,
        })
Пример #18
0
    def test_thread_read_category_cutoff(self):
        """thread read is handled when category cutoff is present"""
        self.reply_thread()

        add_acl(self.user, self.categories)
        threadstracker.make_read_aware(self.user, self.thread)
        self.assertFalse(self.thread.is_read)

        categoriestracker.read_category(self.user, self.category)
        threadstracker.make_read_aware(self.user, self.thread)
        self.assertTrue(self.thread.is_read)

        categoriestracker.make_read_aware(self.user, self.categories)
        self.assertTrue(self.category.is_read)

        posts = list(self.thread.post_set.order_by('id'))
        threadstracker.make_posts_read_aware(self.user, self.thread, posts)

        for post in posts:
            self.assertTrue(post.is_read)

        # post reply
        self.reply_thread()

        # test if only last post is unread
        posts = list(self.thread.post_set.order_by('id'))
        threadstracker.make_read_aware(self.user, self.thread)
        threadstracker.make_posts_read_aware(self.user, self.thread, posts)

        for post in posts[:-1]:
            self.assertTrue(post.is_read)
        self.assertTrue(posts[-1].is_new)

        # last post read will change readstate of categories
        threadstracker.make_read_aware(self.user, self.thread)
        threadstracker.read_thread(self.user, self.thread, posts[-1])

        categoriestracker.make_read_aware(self.user, self.categories)
        self.assertTrue(self.category.is_read)
Пример #19
0
    def dispatch(self, request, *args, **kwargs):
        relations = ['forum', 'starter', 'last_poster', 'first_post']
        thread = self.fetch_thread(request, select_related=relations, **kwargs)
        forum = thread.forum

        self.check_forum_permissions(request, forum)
        self.check_thread_permissions(request, thread)

        threadstracker.make_read_aware(request.user, thread)

        page, posts = self.get_posts(request.user, forum, thread, kwargs)
        threadstracker.make_posts_read_aware(request.user, thread, posts)
        threadstracker.read_thread(request.user, thread, posts[-1])

        return self.render(request, {
            'forum': forum,
            'path': get_forum_path(forum),
            'thread': thread,
            'posts': posts,
            'page': page,
            'paginator': page.paginator,
        })
Пример #20
0
    def test_vie_handles_unapproved_posts(self):
        """if thread has unapproved posts, redirect to first of them"""
        for i in range(settings.MISAGO_POSTS_PER_PAGE +
                       settings.MISAGO_POSTS_TAIL):
            testutils.reply_thread(self.thread, posted_on=timezone.now())

        make_thread_read_aware(self.user, self.thread)
        read_thread(self.user, self.thread, self.thread.last_post)

        post = testutils.reply_thread(self.thread,
                                      is_unapproved=True,
                                      posted_on=timezone.now())
        for i in range(settings.MISAGO_POSTS_PER_PAGE +
                       settings.MISAGO_POSTS_TAIL - 1):
            testutils.reply_thread(self.thread, posted_on=timezone.now())

        self.grant_permission()

        response = self.client.get(self.thread.get_new_post_url())
        self.assertEqual(response.status_code, 302)
        self.assertEqual(
            response['location'],
            GOTO_PAGE_URL % (self.thread.get_absolute_url(), 2, post.pk))