Use different Zammad groups per form

This commit is contained in:
Yannik Rödel 2022-06-12 17:58:10 +02:00
parent 8cf8becb56
commit 41c4ebd4d0
2 changed files with 11 additions and 3 deletions

View file

@ -137,6 +137,8 @@ ticket_details = collections.OrderedDict()
ticket_details["Kontaktperson"] = contact_name ticket_details["Kontaktperson"] = contact_name
ticket_details["Email"] = contact_email ticket_details["Email"] = contact_email
form_group = "csw-Allgemein"
match request_uri: match request_uri:
case "/kontakt": case "/kontakt":
form_name = "Allgemein" form_name = "Allgemein"
@ -152,6 +154,7 @@ match request_uri:
case "/computer-beantragen/organisation": case "/computer-beantragen/organisation":
form_name = "Computerantrag (Organisation)" form_name = "Computerantrag (Organisation)"
form_group = "csw-Anfragen"
ticket_details["Organisation"] = get_form_value("organization") ticket_details["Organisation"] = get_form_value("organization")
ticket_details["Adresse"] = get_form_value("addressline") ticket_details["Adresse"] = get_form_value("addressline")
ticket_details["PLZ"] = get_form_value("postalcode") ticket_details["PLZ"] = get_form_value("postalcode")
@ -162,6 +165,7 @@ match request_uri:
case "/computer-beantragen/privat": case "/computer-beantragen/privat":
form_name = "Computerantrag (privat)" form_name = "Computerantrag (privat)"
form_group = "csw-Anfragen"
ticket_details["Adresse"] = get_form_value("addressline") ticket_details["Adresse"] = get_form_value("addressline")
ticket_details["PLZ"] = get_form_value("postalcode") ticket_details["PLZ"] = get_form_value("postalcode")
ticket_details["Stadt"] = get_form_value("city") ticket_details["Stadt"] = get_form_value("city")
@ -172,11 +176,13 @@ match request_uri:
case "/hardware-spenden/organisation": case "/hardware-spenden/organisation":
form_name = "Hardwarespende (Organisation)" form_name = "Hardwarespende (Organisation)"
form_group = "csw-Hardwarespenden"
ticket_details["Organisation"] = get_form_value("organization") ticket_details["Organisation"] = get_form_value("organization")
attachment = get_form_value("inventory", cast=bytes) attachment = get_form_value("inventory", cast=bytes)
case "/hardware-spenden/privat/laptop": case "/hardware-spenden/privat/laptop":
form_name = "Laptopspende (privat)" form_name = "Laptopspende (privat)"
form_group = "csw-Hardwarespenden"
ticket_details["Gerätedetails"] = get_form_value("device") ticket_details["Gerätedetails"] = get_form_value("device")
case _: case _:
@ -186,10 +192,12 @@ match request_uri:
ticket_details["Kontaktformular"] = form_name ticket_details["Kontaktformular"] = form_name
# Allow the form group to be overriden using the environment variable (for
# testing).
form_group = os.environ.get("ZAMMAD_GROUP", "") or form_group
ZAMMAD_URL = os.environ.get("ZAMMAD_URL", "").rstrip("/") ZAMMAD_URL = os.environ.get("ZAMMAD_URL", "").rstrip("/")
ZAMMAD_TOKEN = os.environ.get("ZAMMAD_TOKEN", "") ZAMMAD_TOKEN = os.environ.get("ZAMMAD_TOKEN", "")
ZAMMAD_GROUP = os.environ.get("ZAMMAD_GROUP", "")
session = requests.Session() session = requests.Session()
session.headers.update(Authorization=f"Token token={ZAMMAD_TOKEN}") session.headers.update(Authorization=f"Token token={ZAMMAD_TOKEN}")
@ -199,7 +207,7 @@ try:
f"{ZAMMAD_URL}/api/v1/tickets", f"{ZAMMAD_URL}/api/v1/tickets",
json=dict( json=dict(
title=f"Kontaktformular {contact_name} {form_name}", title=f"Kontaktformular {contact_name} {form_name}",
group=ZAMMAD_GROUP, group=form_group,
customer_id=f"guess:{contact_email}", customer_id=f"guess:{contact_email}",
article=dict( article=dict(
type="web", type="web",

View file

@ -59,7 +59,7 @@
# We need to provide these default variables because otherwise # We need to provide these default variables because otherwise
# lighttpd doesn't even parse its configuration file: # lighttpd doesn't even parse its configuration file:
"ZAMMAD_URL=https://ticket.z31.it" "ZAMMAD_URL=https://ticket.z31.it"
"ZAMMAD_GROUP=testgruppe" "ZAMMAD_GROUP="
]; ];
ExposedPorts = { ExposedPorts = {
"80/tcp" = {}; "80/tcp" = {};