Esempio n. 1
0
    def test_thread_read_for_guest(self):
        """threads are always read for guests"""
        threadstracker.make_read_aware(self.anon, self.thread)
        self.assertTrue(self.thread.is_read)

        threadstracker.make_read_aware(self.anon, [self.thread])
        self.assertTrue(self.thread.is_read)
Esempio n. 2
0
    def __init__(self, request, pk, slug=None,
            read_aware=False, subscription_aware=False, poll_votes_aware=False, select_for_update=False):
        model = self.get_thread(request, pk, slug, select_for_update)

        model.path = self.get_thread_path(model.category)

        add_acl(request.user, model.category)
        add_acl(request.user, model)

        if read_aware:
            make_read_aware(request.user, model)
        if subscription_aware:
            make_subscription_aware(request.user, model)

        self._model = model
        self._category = model.category
        self._path = model.path

        try:
            self._poll = model.poll
            add_acl(request.user, self._poll)

            if poll_votes_aware:
                self._poll.make_choices_votes_aware(request.user)
        except Poll.DoesNotExist:
            self._poll = None
Esempio n. 3
0
    def test_thread_read_for_guest(self):
        """threads are always read for guests"""
        threadstracker.make_read_aware(self.anon, self.thread)
        self.assertTrue(self.thread.is_read)

        self.reply_thread()
        threadstracker.make_read_aware(self.anon, [self.thread])
        self.assertTrue(self.thread.is_read)
Esempio n. 4
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,
        })
Esempio n. 5
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,
        })
Esempio n. 6
0
def new(user, thread):
    make_read_aware(user, thread)
    if thread.is_read:
        return last(user, thread)

    posts, qs = posts_queryset(user, thread)
    try:
        first_unread = qs.filter(posted_on__gt=thread.last_read_on)[:1][0]
    except IndexError:
        return last(user, thread)

    return get_post_link(posts, qs, thread, first_unread)
Esempio n. 7
0
def new(user, thread):
    make_read_aware(user, thread)
    if thread.is_read:
        return last(user, thread)

    posts, qs = posts_queryset(user, thread)
    try:
        first_unread = qs.filter(posted_on__gt=thread.last_read_on)[:1][0]
    except IndexError:
        return last(user, thread)

    return get_post_link(posts, qs, thread, first_unread)
Esempio n. 8
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())
Esempio n. 9
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)
Esempio n. 10
0
    def __init__(self, request, pk, slug=None, read_aware=False, subscription_aware=False, select_for_update=False):
        model = self.get_thread(request, pk, slug, select_for_update)

        model.path = self.get_thread_path(model.category)

        add_acl(request.user, model.category)
        add_acl(request.user, model)

        if read_aware:
            make_read_aware(request.user, model)
        if subscription_aware:
            make_subscription_aware(request.user, model)

        self._model = model
        self._category = model.category
        self._path = model.path
Esempio n. 11
0
    def __init__(self, request, pk, slug=None, read_aware=False, subscription_aware=False):
        thread = self.get_thread(request, pk, slug)

        thread.path = self.get_thread_path(thread.category)

        add_acl(request.user, thread.category)
        add_acl(request.user, thread)

        if read_aware:
            make_read_aware(request.user, thread)
        if subscription_aware:
            make_subscription_aware(request.user, thread)

        self.thread = thread
        self.category = thread.category
        self.path = thread.path
Esempio n. 12
0
def post_read_endpoint(request, thread, post):
    poststracker.make_read_aware(request.user, post)
    if post.is_new:
        poststracker.save_read(request.user, post)
        if thread.subscription and thread.subscription.last_read_on < post.posted_on:
            thread.subscription.last_read_on = post.posted_on
            thread.subscription.save()

    threadstracker.make_read_aware(request.user, thread)

    # send signal if post read marked thread as read
    # used in some places, eg. syncing unread thread count
    if post.is_new and thread.is_read:
        thread_read.send(request.user, thread=thread)

    return Response({'thread_is_read': thread.is_read})
Esempio n. 13
0
    def __init__(self, request, category, list_type, page):
        self.allow_see_list(request, category, list_type)

        category_model = category.unwrap()

        base_queryset = self.get_base_queryset(request, category.categories,
                                               list_type)
        base_queryset = base_queryset.select_related('starter', 'last_poster')

        threads_categories = [category_model] + category.subcategories

        threads_queryset = self.get_remaining_threads_queryset(
            base_queryset, category_model, threads_categories)

        list_page = paginate(threads_queryset, page,
                             settings.MISAGO_THREADS_PER_PAGE,
                             settings.MISAGO_THREADS_TAIL)
        paginator = pagination_dict(list_page)

        if list_page.number > 1:
            threads = list(list_page.object_list)
        else:
            pinned_threads = list(
                self.get_pinned_threads(base_queryset, category_model,
                                        threads_categories))
            threads = list(pinned_threads) + list(list_page.object_list)

        add_categories_to_items(category_model, category.categories, threads)
        add_acl(request.user, threads)
        make_subscription_aware(request.user, threads)

        if list_type in ('new', 'unread'):
            # we already know all threads on list are unread
            for thread in threads:
                thread.is_read = False
                thread.is_new = True
        else:
            threadstracker.make_read_aware(request.user, threads)

        self.filter_threads(request, threads)

        # set state on object for easy access from hooks
        self.category = category
        self.threads = threads
        self.list_type = list_type
        self.paginator = paginator
Esempio n. 14
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)
Esempio n. 15
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)
Esempio n. 16
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,
        })
Esempio n. 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(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,
        })
Esempio n. 18
0
    def __init__(self, request, pk, slug=None, read_aware=False,
            subscription_aware=False, poll_votes_aware=False, select_for_update=False):
        model = self.get_thread(request, pk, slug, select_for_update)

        model.path = self.get_thread_path(model.category)

        add_acl(request.user, model.category)
        add_acl(request.user, model)

        if read_aware:
            make_read_aware(request.user, model)
        if subscription_aware:
            make_subscription_aware(request.user, model)

        self._model = model

        try:
            self._poll = model.poll
            add_acl(request.user, self._poll)

            if poll_votes_aware:
                self._poll.make_choices_votes_aware(request.user)
        except Poll.DoesNotExist:
            self._poll = None
Esempio n. 19
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)
Esempio n. 20
0
 def make_threads_read_aware(self, threads):
     threadstracker.make_read_aware(self.user, threads)
Esempio n. 21
0
    def test_thread_replied_unread_for_user(self):
        """replied thread is unread for user"""
        self.reply_thread()

        threadstracker.make_read_aware(self.user, self.thread)
        self.assertFalse(self.thread.is_read)
Esempio n. 22
0
 def test_thread_read_for_user(self):
     """thread is read for user"""
     threadstracker.make_read_aware(self.user, self.thread)
     self.assertTrue(self.thread.is_read)
Esempio n. 23
0
    def test_thread_replied_unread_for_user(self):
        """replied thread is unread for user"""
        self.reply_thread(self.thread)

        threadstracker.make_read_aware(self.user, self.thread)
        self.assertFalse(self.thread.is_read)
Esempio n. 24
0
 def test_thread_read_for_user(self):
     """thread is read for user"""
     threadstracker.make_read_aware(self.user, self.thread)
     self.assertTrue(self.thread.is_read)