88from models_library .basic_types import IDStr
99from models_library .emails import LowerCaseEmailStr
1010from models_library .users import FirstNameStr , LastNameStr , UserID
11- from pydantic import BaseModel , ConfigDict , Field , field_validator , model_validator
11+ from pydantic import BaseModel , ConfigDict , Field , field_validator
1212from simcore_postgres_database .models .users import UserRole
1313
14- from ..utils import gravatar_hash
1514from ._models import ProfilePrivacyGet , ProfilePrivacyUpdate
1615
1716
@@ -59,13 +58,15 @@ class ProfileGet(BaseModel):
5958
6059 role : Literal ["ANONYMOUS" , "GUEST" , "USER" , "TESTER" , "PRODUCT_OWNER" , "ADMIN" ]
6160 groups : MyGroupsGet | None = None
62- gravatar_id : str | None = None
61+ gravatar_id : Annotated [ str | None , Field ( deprecated = True )] = None
6362
64- expiration_date : date | None = Field (
65- default = None ,
66- description = "If user has a trial account, it sets the expiration date, otherwise None" ,
67- alias = "expirationDate" ,
68- )
63+ expiration_date : Annotated [
64+ date | None ,
65+ Field (
66+ description = "If user has a trial account, it sets the expiration date, otherwise None" ,
67+ alias = "expirationDate" ,
68+ ),
69+ ] = None
6970
7071 privacy : ProfilePrivacyGet
7172 preferences : AggregatedPreferences
@@ -76,37 +77,19 @@ class ProfileGet(BaseModel):
7677 populate_by_name = True ,
7778 json_schema_extra = {
7879 "examples" : [
79- # 1. with gravatar
80- {
81- "id" : 1 ,
82- 83- "userName" : "bla123" ,
84- "role" : "Admin" ,
85- "gravatar_id" : "205e460b479e2e5b48aec07710c08d50" ,
86- "preferences" : {},
87- },
88- # 2. with expiration date
8980 {
9081 "id" : 42 ,
91829283 "userName" : "bla123" ,
9384 "role" : UserRole .ADMIN .value ,
9485 "expirationDate" : "2022-09-14" ,
9586 "preferences" : {},
87+ "privacy" : {"hide_fullname" : 0 , "hide_email" : 1 },
9688 },
9789 ]
9890 },
9991 )
10092
101- @model_validator (mode = "before" )
102- @classmethod
103- def _auto_generate_gravatar (cls , values ):
104- gravatar_id = values .get ("gravatar_id" )
105- email = values .get ("login" )
106- if not gravatar_id and email :
107- values ["gravatar_id" ] = gravatar_hash (email )
108- return values
109-
11093 @field_validator ("role" , mode = "before" )
11194 @classmethod
11295 def _to_upper_string (cls , v ):
0 commit comments