-
-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathzammad.py
60 lines (45 loc) · 2.27 KB
/
zammad.py
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
from __future__ import annotations
from typing import TYPE_CHECKING
from django.conf import settings
from zammad_py import ZammadAPI
if TYPE_CHECKING:
from weblate_web.models import Subscription
def get_zammad_client() -> ZammadAPI:
return ZammadAPI(
url="https://care.weblate.org/api/v1/",
http_token=settings.ZAMMAD_TOKEN,
)
def create_dedicated_hosting_ticket(subscription: Subscription) -> None:
zammad = get_zammad_client()
# Get first user email (there should be only one for initial subscription anyway)
emails: list[str] = subscription.service.user_emails.split(",")
email: str = emails[0]
if not email:
raise ValueError(f"Subscription without an email: {subscription}")
# Extract TLD as best guess for cloud name
domain: str = email.split("@")[1].split(".")[0]
zammad.ticket.create(
params={
"title": f"Your dedicated Weblate instance ({domain})",
"customer_id": f"guess:{email}",
"group": "Users",
"article": {
"subject": "Your dedicated Weblate instance",
"from": "Weblate Care",
"to": email,
"cc": ",".join(emails[1:]),
"body": f"""Hello,
Thank you for purchasing a dedicated Weblate instance! We will prepare it promptly after you provide the information below.
If you want to use your own domain, please create a CNAME DNS entry to {domain}.weblate.cloud and let us know.
Your weblate.cloud domain name can also be changed; if the one mentioned above doesn't fit you, tell us.
In case you would like to use another authentication method(s) than the native username+password login, please provide us credentials for your chosen method.
You can check available options like GitHub, OAuth, SAML, Azure AD, and many more at https://docs.weblate.org/en/latest/admin/auth.html#social-authentication.
It is also possible to keep settings default and customize anything later. It’s your instance, your choice. We will also gladly help with any of your Weblate questions; please don’t hesitate to ask by replying to this message.
Kind regards from Weblate
""",
"type": "email",
"sender": "Agent",
"internal": False,
},
}
)