99 PUBLIC_VARIABLE_NAME_RE ,
1010 TWILIO_ALPHANUMERIC_SENDER_ID_RE ,
1111)
12+ from models_library .basic_types import HttpSecureUrl
1213from models_library .utils .change_case import snake_to_camel
13- from pydantic import BaseModel , Field , HttpUrl , validator
14+ from pydantic import BaseModel , EmailStr , Field , validator
1415from simcore_postgres_database .models .products import jinja2_templates
1516
1617from .db_base_repository import BaseRepository
2324#
2425# MODEL
2526#
27+
28+
2629class Product (BaseModel ):
2730 """
2831 Pydantic model associated to db_models.Products table
@@ -38,21 +41,21 @@ class Product(BaseModel):
3841 host_regex : Pattern
3942
4043 # EMAILS/PHONE
41- support_email : str
44+ support_email : EmailStr
4245 twilio_messaging_sid : Optional [str ] = Field (
4346 default = None ,
4447 min_length = 34 ,
4548 max_length = 34 ,
4649 )
4750
4851 # MANUALS
49- manual_url : HttpUrl
50- manual_extra_url : Optional [HttpUrl ] = None
52+ manual_url : HttpSecureUrl
53+ manual_extra_url : Optional [HttpSecureUrl ] = None
5154
5255 # ISSUE TRACKER
53- issues_login_url : Optional [HttpUrl ] = None
54- issues_new_url : Optional [HttpUrl ] = None
55- feedback_form_url : Optional [HttpUrl ] = None
56+ issues_login_url : Optional [HttpSecureUrl ] = None
57+ issues_new_url : Optional [HttpSecureUrl ] = None
58+ feedback_form_url : Optional [HttpSecureUrl ] = None
5659
5760 # TEMPLATES
5861 registration_email_template : Optional [str ] = Field (
@@ -76,6 +79,18 @@ class Config:
7679 if c .server_default and isinstance (c .server_default .arg , str )
7780 },
7881 },
82+ # Example of data in the dabase with a url set with blanks
83+ {
84+ "name" : "tis" ,
85+ "display_name" : "TI PT" ,
86+ "short_name" : "TIPI" ,
87+ "host_regex" : r"(^tis[\.-])|(^ti-solutions\.)|(^ti-plan\.)" ,
88+ "support_email" :
"[email protected] " ,
89+ "manual_url" : "https://foo.com" ,
90+ "issues_login_url" : None ,
91+ "issues_new_url" : "https://foo.com/new" ,
92+ "feedback_form_url" : "" , # <-- blanks
93+ },
7994 ]
8095 }
8196
@@ -88,6 +103,20 @@ def validate_name(cls, v):
88103 )
89104 return v
90105
106+ @validator (
107+ "manual_extra_url" ,
108+ "issues_login_url" ,
109+ "issues_new_url" ,
110+ "feedback_form_url" ,
111+ pre = True ,
112+ )
113+ @classmethod
114+ def parse_empty_string_url_as_null (cls , v ):
115+ """Safe measure: database entries are sometimes left blank instead of null"""
116+ if isinstance (v , str ) and len (v .strip ()) == 0 :
117+ return None
118+ return v
119+
91120 @property
92121 def twilio_alpha_numeric_sender_id (self ) -> str :
93122 return self .short_name or self .display_name .replace (string .punctuation , "" )[:11 ]
0 commit comments