From 5a896451fc6ff07c59e068781c26878efcb569dd Mon Sep 17 00:00:00 2001 From: Athena Funderburg Date: Fri, 6 Nov 2026 01:05:44 +0000 Subject: [PATCH] fix the fix --- .../http/tmpl/abservice/ABFindAllResponse.xml | 2 +- .../abservice/ABFindContactsPagedResponse.xml | 2 +- front/msn/http/util.py | 34 +++++++++++++++++-- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/front/msn/http/tmpl/abservice/ABFindAllResponse.xml b/front/msn/http/tmpl/abservice/ABFindAllResponse.xml index 2123828..5874de7 100644 --- a/front/msn/http/tmpl/abservice/ABFindAllResponse.xml +++ b/front/msn/http/tmpl/abservice/ABFindAllResponse.xml @@ -1,4 +1,4 @@ -{% from 'msn:_funcs.xml' import contact_entry, group_entry, generate_me_entry, ab_properties -%} +{% from 'msn:_funcs.xml' import contact_entry, group_entry, generate_me_entry, ab_properties with context -%} diff --git a/front/msn/http/tmpl/abservice/ABFindContactsPagedResponse.xml b/front/msn/http/tmpl/abservice/ABFindContactsPagedResponse.xml index ee3fbe7..b99b886 100644 --- a/front/msn/http/tmpl/abservice/ABFindContactsPagedResponse.xml +++ b/front/msn/http/tmpl/abservice/ABFindContactsPagedResponse.xml @@ -1,4 +1,4 @@ -{% from 'msn:_funcs.xml' import contact_entry, group_entry, generate_me_entry -%} +{% from 'msn:_funcs.xml' import contact_entry, group_entry, generate_me_entry with context -%} diff --git a/front/msn/http/util.py b/front/msn/http/util.py index b433032..4189e7f 100644 --- a/front/msn/http/util.py +++ b/front/msn/http/util.py @@ -13,8 +13,38 @@ def render(req: web.Request, tmpl_name: str, ctxt: Optional[Dict[str, Any]] = No tmpl = req.app['jinja_env'].get_template(tmpl_name) template_context = dict(ctxt or {}) backend = req.app.get('backend') - if backend is not None: - template_context['display_email'] = display_email + + def display_email(user: Any, fallback: Optional[str] = None) -> str: + if isinstance(user, str): + identifier = user + if backend is None: + return fallback or (identifier if '@' in identifier else '') + user = backend.user_service.get(identifier) + if user is None and fallback: + uuid = backend.user_service.get_uuid(fallback) + if uuid is not None: + user = backend.user_service.get(uuid) + if user is None: + return fallback or (identifier if '@' in identifier else '') + elif user is None and fallback and backend is not None: + uuid = backend.user_service.get_uuid(fallback) + if uuid is not None: + user = backend.user_service.get(uuid) + + if user is None: + return fallback or '' + + if backend is not None: + return backend.util_get_display_email(user) + + if getattr(user, 'alias_active', False): + username = getattr(user, 'username', None) + if username: + return '{}@crosstalk.im'.format(username) + + return getattr(user, 'email', None) or fallback or '' + + template_context['display_email'] = display_email content = tmpl.render(**template_context) return web.Response(status = status, content_type = content_type, text = content)