From 7564c5739b385c129fc9dd844296dde3bb3a23f5 Mon Sep 17 00:00:00 2001 From: bbe Date: Sat, 31 Oct 2020 18:24:22 +0100 Subject: [PATCH] Add a clean method on TicketCC model in order to be sure not to add a user who doesn't have an email address. --- helpdesk/models.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/helpdesk/models.py b/helpdesk/models.py index 95ab7601..d6355779 100644 --- a/helpdesk/models.py +++ b/helpdesk/models.py @@ -10,7 +10,7 @@ models.py - Model (and hence database) definitions. This is the core of the from django.contrib.auth.models import Permission from django.contrib.auth import get_user_model from django.contrib.contenttypes.models import ContentType -from django.core.exceptions import ObjectDoesNotExist +from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.db import models from django.conf import settings from django.utils import timezone @@ -1666,6 +1666,10 @@ class TicketCC(models.Model): def __str__(self): return '%s for %s' % (self.display, self.ticket.title) + def clean(self): + if self.user and not self.user.email: + raise ValidationError('User has no email address') + class CustomFieldManager(models.Manager):