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
27 changes: 12 additions & 15 deletions kitsune/customercare/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,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 @@ -77,6 +77,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 @@ -153,6 +157,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 @@ -181,20 +186,12 @@ def send(self, user, product):
if settings.STAGE:
zendesk_tags.append("stage")

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,
zendesk_tags=zendesk_tags,
status=SupportTicket.STATUS_PENDING,
)
self.instance.product = product
self.instance.user = user if (user and user.is_authenticated) else None
self.instance.zendesk_tags = zendesk_tags
self.instance.status = SupportTicket.STATUS_PENDING

submission = super().save()

from kitsune.customercare.tasks import zendesk_submission_classifier

Expand Down
4 changes: 2 additions & 2 deletions kitsune/customercare/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class SupportTicket(ModelBase):
)

subject = models.CharField(max_length=255)
description = models.TextField()
category = models.CharField(max_length=255)
description = models.TextField(max_length=65563)
category = models.CharField(max_length=255, blank=True, default="")
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 @@ -301,6 +301,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().

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 the change in the model, the empty category shouldn't raise a validation error

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.

@akatsoulas It raises a form (not model) validation error, because the field is still required (and from the form perspective cannot be empty)

# Since we don't care about the form, we'll just clear the errors to run send().
form._errors = ""
submission = form.send(self.user, self.vpn_product)

self.assertIsInstance(submission, SupportTicket)
Expand Down