Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions kitsune/customercare/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
ZENDESK_PRODUCT_SLUGS = {v: k for k, v in PRODUCT_SLUG_ALIASES.items()}


class ZendeskForm(forms.Form):
class ZendeskForm(forms.ModelForm):
"""Form for submitting a ticket to Zendesk."""

required_css_class = "required"
Expand Down Expand Up @@ -112,6 +112,10 @@ class ZendeskForm(forms.Form):
description = forms.CharField(label=_lazy("Tell us more"), widget=forms.Textarea())
country = forms.CharField(widget=forms.HiddenInput, required=False)

class Meta:
model = SupportTicket
fields = ["subject", "description", "category", "email", "os", "country", "update_channel", "policy_distribution"]

def __init__(self, *args, product, user=None, **kwargs):
super().__init__(*args, **kwargs)

Expand Down Expand Up @@ -188,6 +192,7 @@ def clean_email(self):

def send(self, user, product):
"""Create a SupportTicket record and trigger async classification."""

selected_category_slug = self.cleaned_data.get("category")
zendesk_tags = []

Expand Down Expand Up @@ -232,21 +237,13 @@ def send(self, user, product):
from kitsune.customercare.tasks import zendesk_submission_classifier
from kitsune.customercare.utils import resolve_org_group

submission = SupportTicket.objects.create(
subject=self.cleaned_data["subject"],
description=self.cleaned_data["description"],
category=self.cleaned_data.get("category", ""),
email=self.cleaned_data["email"],
os=self.cleaned_data.get("os", ""),
country=self.cleaned_data.get("country", ""),
update_channel=self.cleaned_data.get("update_channel", ""),
policy_distribution=self.cleaned_data.get("policy_distribution", ""),
product=product,
user=user if (user and user.is_authenticated) else None,
org_group=resolve_org_group(user, product),
zendesk_tags=zendesk_tags,
submission_status=SupportTicket.STATUS_PENDING,
)
self.instance.product = product
self.instance.user = user if (user and user.is_authenticated) else None
self.instance.org_group = resolve_org_group(user, product)
self.instance.zendesk_tags = zendesk_tags
self.instance.submission_status = SupportTicket.STATUS_PENDING

submission = super().save()

zendesk_submission_classifier.delay(submission.id)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 5.2.14 on 2026-07-14 13:07

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('customercare', '0012_supportticket_zd_deleted_at'),
]

operations = [
migrations.AlterField(
model_name='supportticket',
name='category',
field=models.CharField(blank=True, default='', max_length=255),
),
migrations.AlterField(
model_name='supportticket',
name='description',
field=models.TextField(max_length=65535),
),
]
4 changes: 2 additions & 2 deletions kitsune/customercare/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ class SupportTicket(ModelBase):
}

subject = models.CharField(max_length=255)
description = models.TextField()
category = models.CharField(max_length=255)
description = models.TextField(max_length=65535)
category = models.CharField(max_length=255, blank=True, default="")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that the form does not allow an empty value, I would argue that the model shouldn't allow this as well.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect this change will also need a schema migration

@denyshon denyshon Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

form does allow an empty value: category=self.cleaned_data.get("category", "")
in case we'll unmark the field as required

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a handwritten migration, but from what I understand, it should ideally be generated by django?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(updated the comment above, the current behavior regarding an empty value is not consistent, so you'll be the best person to decide on this)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can run ./manage.py makemigrations to create the migration and ./manage migrate to apply it

email = models.EmailField()
os = models.CharField(max_length=50, blank=True, default="")
country = models.CharField(max_length=255, blank=True, default="")
Expand Down
3 changes: 3 additions & 0 deletions kitsune/customercare/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ def test_send_with_no_category_selected(self, mock_task):
"description": "Test description",
"category": "", # Empty category
}
# An empty category field will result in a form validation error in send()->save().
Comment thread
denyshon marked this conversation as resolved.
# Since we don't care about the form, we'll just clear the errors to run send().
form._errors = ""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why we are bypassing the form errors here. We shouldn't be able to send() given the invalid form

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can pass a random topic if you want

submission = form.send(self.user, self.vpn_product)

self.assertIsInstance(submission, SupportTicket)
Expand Down