~homeworkprod/byceps

ref: 87b31ba68669551f699c7d12cf18401663b2d043 byceps/byceps/announce/text_assembly/user.py -rw-r--r-- 3.5 KiB
87b31ba6 — Jochen Kupperschmidt Fix type errors 1 year, 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
"""
byceps.announce.text_assembly.user
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Announce user events.

:Copyright: 2006-2021 Jochen Kupperschmidt
:License: Revised BSD (see `LICENSE` file for details)
"""

from ...events.user import (
    UserAccountCreated,
    UserAccountDeleted,
    UserAccountSuspended,
    UserAccountUnsuspended,
    UserDetailsUpdated,
    UserEmailAddressInvalidated,
    UserScreenNameChanged,
)
from ...services.site import service as site_service

from ._helpers import get_screen_name_or_fallback


def assemble_text_for_user_account_created(event: UserAccountCreated) -> str:
    initiator_screen_name = get_screen_name_or_fallback(
        event.initiator_screen_name
    )
    user_screen_name = get_screen_name_or_fallback(event.user_screen_name)

    site = None
    if event.site_id:
        site = site_service.find_site(event.site_id)

    if site:
        return (
            f'{initiator_screen_name} '
            f'hat das Benutzerkonto "{user_screen_name}" '
            f'auf Site "{site.title}" angelegt.'
        )
    else:
        return (
            f'{initiator_screen_name} '
            f'hat das Benutzerkonto "{user_screen_name}" angelegt.'
        )


def assemble_text_for_user_screen_name_changed(
    event: UserScreenNameChanged,
) -> str:
    initiator_screen_name = get_screen_name_or_fallback(
        event.initiator_screen_name
    )

    return (
        f'{initiator_screen_name} hat das Benutzerkonto '
        f'"{event.old_screen_name}" in "{event.new_screen_name}" umbenannt.'
    )


def assemble_text_for_user_email_address_invalidated(
    event: UserEmailAddressInvalidated,
) -> str:
    initiator_screen_name = get_screen_name_or_fallback(
        event.initiator_screen_name
    )
    user_screen_name = get_screen_name_or_fallback(event.user_screen_name)

    return (
        f'{initiator_screen_name} hat die E-Mail-Adresse '
        f'des Benutzerkontos "{user_screen_name}" invalidiert.'
    )


def assemble_text_for_user_details_updated_changed(
    event: UserDetailsUpdated,
) -> str:
    initiator_screen_name = get_screen_name_or_fallback(
        event.initiator_screen_name
    )
    user_screen_name = get_screen_name_or_fallback(event.user_screen_name)

    return (
        f'{initiator_screen_name} hat die persönlichen Daten '
        f'des Benutzerkontos "{user_screen_name}" geändert.'
    )


def assemble_text_for_user_account_suspended(
    event: UserAccountSuspended,
) -> str:
    initiator_screen_name = get_screen_name_or_fallback(
        event.initiator_screen_name
    )
    user_screen_name = get_screen_name_or_fallback(event.user_screen_name)

    return (
        f'{initiator_screen_name} hat das Benutzerkonto '
        f'"{user_screen_name}" gesperrt.'
    )


def assemble_text_for_user_account_unsuspended(
    event: UserAccountUnsuspended,
) -> str:
    initiator_screen_name = get_screen_name_or_fallback(
        event.initiator_screen_name
    )
    user_screen_name = get_screen_name_or_fallback(event.user_screen_name)

    return (
        f'{initiator_screen_name} hat das Benutzerkonto '
        f'"{user_screen_name}" entsperrt.'
    )


def assemble_text_for_user_account_deleted(event: UserAccountDeleted) -> str:
    initiator_screen_name = get_screen_name_or_fallback(
        event.initiator_screen_name
    )
    user_screen_name = get_screen_name_or_fallback(event.user_screen_name)

    return (
        f'{initiator_screen_name} hat das Benutzerkonto '
        f'"{user_screen_name}" (ID "{event.user_id}") gelöscht.'
    )