• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rafalp / Misago / 9487666026

12 Jun 2024 06:16PM UTC coverage: 97.699% (-1.0%) from 98.716%
9487666026

push

github

web-flow
Replace forum options with account settings (#1742)

1947 of 1979 new or added lines in 68 files covered. (98.38%)

661 existing lines in 143 files now uncovered.

52601 of 53840 relevant lines covered (97.7%)

0.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.83
/misago/threads/api/postendpoints/split.py
1
from django.core.exceptions import PermissionDenied
1✔
2
from django.utils.translation import pgettext
1✔
3
from rest_framework.response import Response
1✔
4

5
from ...models import Thread
1✔
6
from ...moderation import threads as moderation
1✔
7
from ...serializers import SplitPostsSerializer
1✔
8

9

10
def posts_split_endpoint(request, thread):
1✔
11
    if not thread.acl["can_move_posts"]:
1✔
12
        raise PermissionDenied(
1✔
13
            pgettext("posts api", "You can't split posts from this thread.")
14
        )
15

16
    serializer = SplitPostsSerializer(
1✔
17
        data=request.data,
18
        context={
19
            "settings": request.settings,
20
            "thread": thread,
21
            "user_acl": request.user_acl,
22
        },
23
    )
24

25
    if not serializer.is_valid():
1✔
26
        if "posts" in serializer.errors:
1✔
27
            # Fix for KeyError - errors[0]
28
            errors = serializer.errors["posts"]
1✔
29
            try:
1✔
30
                errors = {"detail": errors[0]}
1✔
31
            except KeyError:
1✔
32
                if isinstance(errors, dict):
1✔
33
                    errors = {"detail": list(errors.values())[0][0]}
1✔
34
        else:
35
            errors = serializer.errors
1✔
36

37
        return Response(errors, status=400)
1✔
38

39
    split_posts_to_new_thread(request, thread, serializer.validated_data)
1✔
40

41
    return Response({})
1✔
42

43

44
def split_posts_to_new_thread(request, thread, validated_data):
1✔
45
    new_thread = Thread(
1✔
46
        category=validated_data["category"],
47
        started_on=thread.started_on,
48
        last_post_on=thread.last_post_on,
49
    )
50

51
    new_thread.set_title(validated_data["title"])
1✔
52
    new_thread.save()
1✔
53

54
    for post in validated_data["posts"]:
1✔
55
        post.move(new_thread)
1✔
56
        post.save()
1✔
57

58
    thread.synchronize()
1✔
59
    thread.save()
1✔
60

61
    new_thread.synchronize()
1✔
62
    new_thread.save()
1✔
63

64
    if validated_data.get("weight") == Thread.WEIGHT_GLOBAL:
1✔
65
        moderation.pin_thread_globally(request, new_thread)
1✔
66
    elif validated_data.get("weight"):
1✔
UNCOV
67
        moderation.pin_thread_locally(request, new_thread)
×
68
    if validated_data.get("is_hidden", False):
1✔
69
        moderation.hide_thread(request, new_thread)
1✔
70
    if validated_data.get("is_closed", False):
1✔
71
        moderation.close_thread(request, new_thread)
1✔
72

73
    thread.category.synchronize()
1✔
74
    thread.category.save()
1✔
75

76
    if new_thread.category != thread.category:
1✔
77
        new_thread.category.synchronize()
1✔
78
        new_thread.category.save()
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc