예제 #1
0
 def post_save(self, form):
     if form.is_valid() and self.mode != START:
         if self.thread_is_closed != form.cleaned_data.get('is_closed'):
             if self.thread.is_closed:
                 moderation.open_thread(self.user, self.thread)
             else:
                 moderation.close_thread(self.user, self.thread)
예제 #2
0
    def test_close_invalid_thread(self):
        """close_thread fails gracefully for opened thread"""
        moderation.close_thread(self.request, self.thread)
        self.reload_thread()

        self.assertTrue(self.thread.is_closed)
        self.assertFalse(moderation.close_thread(self.request, self.thread))
예제 #3
0
    def test_close_invalid_thread(self):
        """close_thread fails gracefully for opened thread"""
        moderation.close_thread(self.user, self.thread)
        self.reload_thread()

        self.assertTrue(self.thread.is_closed)
        self.assertFalse(moderation.close_thread(self.user, self.thread))
예제 #4
0
 def post_save(self, form):
     if form.is_valid() and self.mode != START:
         if self.is_closed != form.cleaned_data.get('is_closed'):
             if self.thread.is_closed:
                 moderation.open_thread(self.user, self.thread)
             else:
                 moderation.close_thread(self.user, self.thread)
예제 #5
0
파일: split.py 프로젝트: tsim0/Misago
def split_posts_to_new_thread(request, thread, validated_data):
    new_thread = Thread(
        category=validated_data['category'],
        started_on=thread.started_on,
        last_post_on=thread.last_post_on,
    )

    new_thread.set_title(validated_data['title'])
    new_thread.save()

    for post in validated_data['posts']:
        post.move(new_thread)
        post.save()

    thread.synchronize()
    thread.save()

    new_thread.synchronize()
    new_thread.save()

    if validated_data.get('weight') == Thread.WEIGHT_GLOBAL:
        moderation.pin_thread_globally(request, new_thread)
    elif validated_data.get('weight'):
        moderation.pin_thread_locally(request, new_thread)
    if validated_data.get('is_hidden', False):
        moderation.hide_thread(request, new_thread)
    if validated_data.get('is_closed', False):
        moderation.close_thread(request, new_thread)

    thread.category.synchronize()
    thread.category.save()

    if new_thread.category != thread.category:
        new_thread.category.synchronize()
        new_thread.category.save()
예제 #6
0
    def post_save(self, serializer):
        if self.thread.category.acl['can_close_threads']:
            try:
                close = bool(self.request.data['close'])
            except (TypeError, ValueError):
                close = False

            if close:
                moderation.close_thread(self.request, self.thread)
예제 #7
0
def patch_is_closed(request, thread, value):
    if thread.acl.get('can_close'):
        if value:
            moderation.close_thread(request, thread)
        else:
            moderation.open_thread(request, thread)

        return {'is_closed': thread.is_closed}
    else:
        if value:
            raise PermissionDenied(_("You don't have permission to close this thread."))
        else:
            raise PermissionDenied(_("You don't have permission to open this thread."))
예제 #8
0
    def test_open_thread(self):
        """open_thread closes thread"""
        moderation.close_thread(self.request, self.thread)
        self.reload_thread()

        self.assertTrue(self.thread.is_closed)
        self.assertTrue(moderation.open_thread(self.request, self.thread))

        self.reload_thread()
        self.assertFalse(self.thread.is_closed)

        event = self.thread.last_post

        self.assertTrue(event.is_event)
        self.assertEqual(event.event_type, 'opened')
예제 #9
0
    def test_open_thread(self):
        """open_thread closes thread"""
        moderation.close_thread(self.user, self.thread)
        self.reload_thread()

        self.assertTrue(self.thread.is_closed)
        self.assertTrue(moderation.open_thread(self.user, self.thread))

        self.reload_thread()
        self.assertFalse(self.thread.is_closed)
        self.assertTrue(self.thread.has_events)
        event = self.thread.event_set.last()

        self.assertIn("opened thread.", event.message)
        self.assertEqual(event.icon, "unlock-alt")
예제 #10
0
    def action_close(self, request, threads):
        changed_threads = 0
        for thread in threads:
            if moderation.close_thread(request.user, thread):
                changed_threads += 1

        if changed_threads:
            message = ungettext('%(changed)d thread was closed.',
                                '%(changed)d threads were closed.',
                                changed_threads)
            messages.success(request, message % {'changed': changed_threads})
        else:
            message = _("No threads were closed.")
            messages.info(request, message)
예제 #11
0
파일: actions.py 프로젝트: nikescar/Misago
    def action_close(self, request, threads):
        changed_threads = 0
        for thread in threads:
            if moderation.close_thread(request.user, thread):
                changed_threads += 1

        if changed_threads:
            message = ungettext(
                '%(changed)d thread was closed.',
                '%(changed)d threads were closed.',
            changed_threads)
            messages.success(request, message % {'changed': changed_threads})
        else:
            message = _("No threads were closed.")
            messages.info(request, message)
예제 #12
0
 def action_close(self, request, thread):
     moderation.close_thread(request.user, thread)
     messages.success(request, _("Thread was closed."))
예제 #13
0
 def post_save(self, serializer):
     if self.thread.category.acl['can_close_threads']:
         if serializer.validated_data.get('close'):
             moderation.close_thread(self.request, self.thread)
예제 #14
0
 def action_close(self, request, thread):
     moderation.close_thread(request.user, thread)
     messages.success(request, _("Thread was closed."))
예제 #15
0
def threads_merge_endpoint(request):
    serializer = MergeThreadsSerializer(
        data=request.data,
        context={'user': request.user},
    )

    serializer.is_valid(raise_exception=True)

    threads = serializer.validated_data['threads']

    data = serializer.validated_data
    threads = data['threads']

    new_thread = Thread(
        category=data['category'],
        started_on=threads[0].started_on,
        last_post_on=threads[0].last_post_on,
    )

    new_thread.set_title(data['title'])
    new_thread.save()

    # handle merge conflict
    best_answer = data.get('best_answer')
    if best_answer:
        new_thread.best_answer_id = best_answer.best_answer_id
        new_thread.best_answer_is_protected = best_answer.best_answer_is_protected
        new_thread.best_answer_marked_on = best_answer.best_answer_marked_on
        new_thread.best_answer_marked_by_id = best_answer.best_answer_marked_by_id
        new_thread.best_answer_marked_by_name = best_answer.best_answer_marked_by_name
        new_thread.best_answer_marked_by_slug = best_answer.best_answer_marked_by_slug

    poll = data.get('poll')
    if poll:
        poll.move(new_thread)

    categories = []
    for thread in threads:
        categories.append(thread.category)
        new_thread.merge(thread)
        thread.delete()

        record_event(
            request,
            new_thread,
            'merged',
            {'merged_thread': thread.title},
            commit=False,
        )

    new_thread.synchronize()
    new_thread.save()

    if data.get('weight') == Thread.WEIGHT_GLOBAL:
        moderation.pin_thread_globally(request, new_thread)
    elif data.get('weight'):
        moderation.pin_thread_locally(request, new_thread)
    if data.get('is_hidden', False):
        moderation.hide_thread(request, new_thread)
    if data.get('is_closed', False):
        moderation.close_thread(request, new_thread)

    if new_thread.category not in categories:
        categories.append(new_thread.category)

    for category in categories:
        category.synchronize()
        category.save()

    # set extra attrs on thread for UI
    new_thread.is_read = False
    new_thread.subscription = None

    add_acl(request.user, new_thread)

    return Response(ThreadsListSerializer(new_thread).data)