feat(teams): manually link Teams users to workspace members

Merged
AB
5d ago
+3542-9

What

Teams senders are matched to a workspace member only automatically, by email, when they first message the bot. When the email does not match, the sender silently falls through and there is no way to map them by hand.

This adds a settings surface (ported from the Slack app's manual-link flow) where an admin picks a person from the Microsoft org directory and maps them to a workspace member, writing a MANUAL teamsUserLink.

How

  • New Graph scope User.ReadBasic.All to enumerate and search the directory (delegated, user-consentable, returns id / displayName / mail / userPrincipalName).
  • Three ROLES-gated logic functions that run as the application:
    • teams-list-unlinked-users — directory users with no link yet (capped, with a truncation flag).
    • teams-search-users — type-ahead over the directory ($filter=startswith(...), OData-escaped).
    • teams-set-user-link — writes a MANUAL link; relink updates the row in place.
  • A TeamsUserLinksSettings container mounted inside ChatSettings, behind the chat-enabled gate plus a canManage (ROLES) gate.

Design notes

  • Admin-set, no consent. A MANUAL link is authoritative the moment an admin sets it. Slack's consent / eager-auto-match machinery is intentionally not ported.
  • MANUAL is sticky for free. The inbound resolve path already looks up an existing link by Entra object id and early-returns before the email auto-match branch, so a manual link is never overwritten.
  • Tenant is resolved server-side from the workspace connection, never trusted from the client, so a caller cannot write a link into another tenant.
  • No new DB entity (the teamsUserLink object and MANUAL source already exist), so no migration.

Demo

teams-manual-user-linking