From 90a55772df44dfaeadced5fb3dc4dab0c9c49c6f Mon Sep 17 00:00:00 2001 From: Sean Smith Date: Wed, 19 Aug 2020 11:58:56 -0400 Subject: Enforce company constraints Signed-off-by: Sean Smith Change-Id: Id5726e5c9930e684c23cebafb98d5fbcb95e67bc --- src/account/models.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/account/models.py b/src/account/models.py index 6828ee1..2c133bb 100644 --- a/src/account/models.py +++ b/src/account/models.py @@ -11,6 +11,8 @@ from django.contrib.auth.models import User from django.db import models from django.apps import apps +from django.core.exceptions import ValidationError +import re import json import random @@ -50,13 +52,27 @@ class UserProfile(models.Model): oauth_token = models.CharField(max_length=1024, blank=False) oauth_secret = models.CharField(max_length=1024, blank=False) - jira_url = models.CharField(max_length=100, default='') - full_name = models.CharField(max_length=100, default='') + jira_url = models.CharField(max_length=100, null=True, blank=True, default='') + full_name = models.CharField(max_length=100, null=True, blank=True, default='') booking_privledge = models.BooleanField(default=False) class Meta: db_table = 'user_profile' + def clean(self, *args, **kwargs): + company = self.company + regex = r'[a-z\_\-\.\$]*' + pattern = re.compile(regex) + + if not pattern.fullmatch(company): + raise ValidationError('Company may only include lowercase letters, _, -, . and $') + + super().clean(*args, **kwargs) + + def save(self, *args, **kwargs): + self.full_clean() + super().save(*args, **kwargs) + def __str__(self): return self.user.username -- cgit 1.2.3-korg