4ea0e88c98
- 新增中心联系人展示名解析服务,支持从逗号分隔用户 ID 解析姓名\n- 中心列表接口返回 contact_display,避免前端依赖项目成员权限才能展示联系人姓名\n- 中心管理和立项会议授权页面优先使用后端联系人展示名\n- 补充联系人解析服务测试和立项会议授权页面展示顺序测试
46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
import uuid
|
|
from typing import Mapping
|
|
|
|
|
|
def parse_contact_user_ids(contact: str | None) -> set[uuid.UUID]:
|
|
ids: set[uuid.UUID] = set()
|
|
for token in _contact_tokens(contact):
|
|
try:
|
|
ids.add(uuid.UUID(token))
|
|
except ValueError:
|
|
continue
|
|
return ids
|
|
|
|
|
|
def build_contact_display(contact: str | None, users: Mapping[uuid.UUID, object]) -> str | None:
|
|
labels: list[str] = []
|
|
for token in _contact_tokens(contact):
|
|
try:
|
|
user_id = uuid.UUID(token)
|
|
except ValueError:
|
|
labels.append(token)
|
|
continue
|
|
|
|
user = users.get(user_id)
|
|
label = _user_display_name(user)
|
|
if label:
|
|
labels.append(label)
|
|
|
|
return "、".join(labels) if labels else None
|
|
|
|
|
|
def _contact_tokens(contact: str | None) -> list[str]:
|
|
return [part.strip() for part in str(contact or "").split(",") if part.strip()]
|
|
|
|
|
|
def _user_display_name(user: object | None) -> str | None:
|
|
if user is None:
|
|
return None
|
|
for attr in ("full_name", "username", "email"):
|
|
value = getattr(user, attr, None)
|
|
if value:
|
|
return str(value)
|
|
return None
|