11from __future__ import annotations
22
3- import logging
43import os
54import sys
65from datetime import datetime
5958 UpdateSessionNotFoundErrorResponse ,
6059 UpdateSessionUnprocessableEntityErrorResponse ,
6160 Contacts ,
61+ ContactInfo ,
6262 # signup
6363 UserCreateRequest ,
6464 UserCreateResponse ,
@@ -193,7 +193,7 @@ def create_session(
193193
194194 if eval_as_bool (config .get_conf_val ("Capabilities" ,
195195 "Password" , "Force" ,
196- default = "False" )):
196+ default = "False" )):
197197 # forcefully allow this method to be called even if the
198198 # adapter declares it as not implemented. This is useful
199199 # in case when app UI should not display this type of login
@@ -205,7 +205,7 @@ def create_session(
205205 is_method_allowed (Capabilities .passwordSignin )
206206
207207 user_ref = safely_extract_scalar_value (body .user_ref ) or \
208- safely_extract_scalar_value (body .login )
208+ safely_extract_scalar_value (body .login )
209209 if not (user_ref and body .password ):
210210 # missing parameters
211211 raise_webtrit_error (422 , "Missing username & password" )
@@ -579,6 +579,49 @@ def get_user_contact_list(
579579 return Contacts (items = [], )
580580
581581
582+ @router .get (
583+ '/user/contacts/{user_id}' ,
584+ response_model = ContactInfo ,
585+ responses = {
586+ '401' : {'model' : GetUserContactListUnauthorizedErrorResponse },
587+ '404' : {'model' : GetUserContactListNotFoundErrorResponse },
588+ '422' : {'model' : GetUserContactListUnprocessableEntityErrorResponse },
589+ '500' : {'model' : GetUserContactListInternalServerErrorErrorResponse },
590+ },
591+ tags = ['user' ],
592+ )
593+ def get_user_contact_by_id (
594+ user_id : str ,
595+ auth_data : HTTPAuthorizationCredentials = Depends (security ),
596+ x_webtrit_tenant_id : Optional [str ] = Header (None , alias = TENANT_ID_HTTP_HEADER ),
597+ ) -> (
598+ Union [
599+ ContactInfo ,
600+ GetUserContactListUnauthorizedErrorResponse ,
601+ GetUserContactListNotFoundErrorResponse ,
602+ GetUserContactListUnprocessableEntityErrorResponse ,
603+ GetUserContactListInternalServerErrorErrorResponse ,
604+ ]
605+ ):
606+ """
607+ Get contact information by user ID
608+ """
609+ global bss
610+
611+ access_token = auth_data .credentials
612+ session = bss .validate_session (access_token )
613+
614+ contact = bss .retrieve_contact_by_user_id (
615+ session ,
616+ ExtendedUserInfo (
617+ user_id = safely_extract_scalar_value (session .user_id ),
618+ tenant_id = bss .default_id_if_none (x_webtrit_tenant_id )
619+ ),
620+ user_id
621+ )
622+ return contact
623+
624+
582625@router .get (
583626 '/user/history' ,
584627 response_model = Calls ,
@@ -949,7 +992,7 @@ def create_user_event(
949992) -> Union [
950993 Response ,
951994 CreateUserEventUnauthorizedErrorResponse ,
952- CreateUserEventUnprocessableEntityErrorResponse ,
995+ CreateUserEventUnprocessableEntityErrorResponse ,
953996 CreateUserEventInternalServerErrorErrorResponse ,
954997]:
955998 """
0 commit comments