Skip to content

Commit 52a49f9

Browse files
authored
Merge pull request #7283 from akatsoulas/zd-brand
Add brand_id to ZD tickets
2 parents 37bc8f7 + c9e96d5 commit 52a49f9

File tree

5 files changed

+97
-1
lines changed

5 files changed

+97
-1
lines changed

kitsune/customercare/tests/test_zendesk.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,71 @@ def test_create_ticket_omits_empty_deployment_fields(self, mock_zenpy):
299299

300300
self.assertNotIn(127, field_ids)
301301
self.assertNotIn(128, field_ids)
302+
303+
@patch("kitsune.customercare.zendesk.Zenpy")
304+
@patch("django.conf.settings.ZENDESK_PRODUCT_FIELD_ID", 123)
305+
@patch("django.conf.settings.ZENDESK_OS_FIELD_ID", 124)
306+
@patch("django.conf.settings.ZENDESK_COUNTRY_FIELD_ID", 125)
307+
@patch("django.conf.settings.ZENDESK_CATEGORY_FIELD_ID", 126)
308+
def test_create_ticket_includes_brand_id(self, mock_zenpy):
309+
"""Test that create_ticket sets brand_id on the ticket when provided."""
310+
mock_client = Mock()
311+
mock_zenpy.return_value = mock_client
312+
mock_client.tickets.create.return_value = Mock(id=789)
313+
self.user.profile.zendesk_id = "123"
314+
315+
client = ZendeskClient()
316+
client.update_user = Mock(return_value=Mock(id=456))
317+
318+
ticket_fields = {
319+
"product": "firefox",
320+
"product_title": "Firefox",
321+
"subject": "Test subject",
322+
"description": "Test description",
323+
"category": "technical",
324+
"os": "win10",
325+
"country": "US",
326+
"ticket_form_id": 456,
327+
"brand_id": "360000001234",
328+
}
329+
330+
client.create_ticket(self.user, ticket_fields)
331+
332+
mock_client.tickets.create.assert_called_once()
333+
call_args = mock_client.tickets.create.call_args[0][0]
334+
335+
self.assertEqual(call_args.brand_id, 360000001234)
336+
337+
@patch("kitsune.customercare.zendesk.Zenpy")
338+
@patch("django.conf.settings.ZENDESK_PRODUCT_FIELD_ID", 123)
339+
@patch("django.conf.settings.ZENDESK_OS_FIELD_ID", 124)
340+
@patch("django.conf.settings.ZENDESK_COUNTRY_FIELD_ID", 125)
341+
@patch("django.conf.settings.ZENDESK_CATEGORY_FIELD_ID", 126)
342+
def test_create_ticket_omits_brand_id_when_not_set(self, mock_zenpy):
343+
"""Test that create_ticket does not set brand_id when not provided."""
344+
mock_client = Mock()
345+
mock_zenpy.return_value = mock_client
346+
mock_client.tickets.create.return_value = Mock(id=789)
347+
self.user.profile.zendesk_id = "123"
348+
349+
client = ZendeskClient()
350+
client.update_user = Mock(return_value=Mock(id=456))
351+
352+
ticket_fields = {
353+
"product": "firefox",
354+
"product_title": "Firefox",
355+
"subject": "Test subject",
356+
"description": "Test description",
357+
"category": "technical",
358+
"os": "win10",
359+
"country": "US",
360+
"ticket_form_id": 456,
361+
"brand_id": "",
362+
}
363+
364+
client.create_ticket(self.user, ticket_fields)
365+
366+
mock_client.tickets.create.assert_called_once()
367+
call_args = mock_client.tickets.create.call_args[0][0]
368+
369+
self.assertFalse(hasattr(call_args, "brand_id") and call_args.brand_id)

kitsune/customercare/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ def _handle_zendesk_exception(error: Exception) -> bool:
115115
)
116116

117117
support_config = ProductSupportConfig.objects.get(product=submission.product, is_active=True)
118-
ticket_form_id = support_config.zendesk_config.ticket_form_id
118+
zendesk_config = support_config.zendesk_config
119+
ticket_form_id = zendesk_config.ticket_form_id
119120

120121
client = ZendeskClient()
121122
ticket_fields = {
@@ -131,6 +132,7 @@ def _handle_zendesk_exception(error: Exception) -> bool:
131132
"product_title": submission.product.title,
132133
"zendesk_tags": submission.zendesk_tags,
133134
"ticket_form_id": int(ticket_form_id),
135+
"brand_id": zendesk_config.brand_id,
134136
}
135137

136138
try:

kitsune/customercare/zendesk.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ def create_ticket(self, user, ticket_fields):
138138
"ticket_form_id": ticket_fields.get("ticket_form_id"),
139139
}
140140

141+
if brand_id := ticket_fields.get("brand_id"):
142+
ticket_kwargs["brand_id"] = int(brand_id)
143+
141144
tags = []
142145
# If this is the normal, athenticated form we want to use the category field
143146
if user and user.is_authenticated:
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 5.2.11 on 2026-03-03 14:27
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('products', '0033_add_deployment_fields'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='zendeskconfig',
15+
name='brand_id',
16+
field=models.CharField(blank=True, help_text='Zendesk brand ID to associate tickets with for this product', max_length=50),
17+
),
18+
]

kitsune/products/models.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,11 @@ class ZendeskConfig(ModelBase):
373373
blank=True,
374374
help_text="Zendesk ticket form ID to use for this product (leave blank to use global default)",
375375
)
376+
brand_id = models.CharField(
377+
max_length=50,
378+
blank=True,
379+
help_text="Zendesk brand ID to associate tickets with for this product",
380+
)
376381
enable_os_field = models.BooleanField(
377382
default=False, help_text="Show operating system selector in the support form"
378383
)

0 commit comments

Comments
 (0)