feat(persona): extract organization data from detection extras#446
feat(persona): extract organization data from detection extras#446
Conversation
LFXV2-1475 Extract organization data (Salesforce account ID, name) from board_member detection extras returned by the persona service and propagate through the SSR and client-side flows. - Add organizations field to PersonaApiResponse, SsrPersonaResult, and PersistedPersonaState interfaces - Extract organizations from board_member detection extras in PersonaDetectionService - Propagate organizations through SSR cookie and NATS paths - Forward organizations to AccountContextService on client refresh - Merge detected organizations into predefined ACCOUNTS list so organizations not in the hardcoded list appear in the selector - Update dev toolbar to use dynamic account list from service - Always refresh persona data from API after hydration - Delete unused organization-matcher.ts Generated with [Claude Code](https://claude.ai/code) Signed-off-by: Asitha de Silva <asithade@gmail.com>
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.
Tip: disable this comment in your organization's Code Review settings.
|
Caution Review failedPull request was closed or merged during review WalkthroughExtracts organizations from persona detections, persists them with persona state (cookies), surfaces them through SSR to the client, merges detected organizations with hardcoded accounts, and updates the dev toolbar selector to use the merged accounts signal. Changes
Sequence DiagramsequenceDiagram
participant API as External API/NATS
participant PDS as PersonaDetectionService
participant Server
participant Helper as PersonaHelper
participant SSR as SSR Handler
participant Client
participant PS as PersonaService
participant ACS as AccountContextService
API->>PDS: detection payload
PDS->>PDS: extractOrganizations() -> Account[]
PDS-->>Server: PersonaApiResponse { personas, organizations }
Server->>Helper: resolvePersonaForSsr()
Helper-->>Server: SsrPersonaResult { persona, personas, organizations }
Server->>SSR: populate auth + organizations
SSR-->>Client: initial state (includes organizations)
Client->>PS: hydrate
PS->>PS: setPersonas(..., organizations)
PS->>ACS: initializeUserOrganizations(organizations)
ACS->>ACS: merge ACCOUNTS with detected organizations
ACS-->>Client: availableAccounts() updated
Client->>Client: dev toolbar selector renders merged accounts
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
This PR wires organization metadata (Salesforce account id/name) from persona detection “extras” through the shared interfaces, SSR auth context, and the client-side persona/account flows, so the dev toolbar’s organization selector can include detected organizations beyond the hardcoded ACCOUNTS list.
Changes:
- Extend shared persona/persona-detection interfaces to include
organizations: Account[]where appropriate (API response, SSR result, persisted cookie state). - Extract unique organizations from
board_memberdetection extras on the server and propagate them into SSR auth context and the/api/user/personasresponse. - Update the Angular account/persona/dev-toolbar flow to merge detected orgs into
ACCOUNTSand always refresh persona data post-hydration; remove deadorganization-matcher.ts.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/shared/src/interfaces/persona.interface.ts | Adds organizations?: Account[] to persisted persona cookie state. |
| packages/shared/src/interfaces/persona-detection.interface.ts | Adds organizations: Account[] to API response + SSR persona result. |
| apps/lfx-one/src/server/utils/persona-helper.ts | Includes organizations in SSR resolution and persists them in persona cookie. |
| apps/lfx-one/src/server/utils/organization-matcher.ts | Deletes unused org matching helper (dead code). |
| apps/lfx-one/src/server/services/persona-detection.service.ts | Logs detection extras (debug) and extracts unique org accounts from board_member extras. |
| apps/lfx-one/src/server/server.ts | Propagates SSR-detected organizations into AuthContext. |
| apps/lfx-one/src/app/shared/services/persona.service.ts | Always refreshes persona post-hydration; forwards detected organizations to AccountContextService. |
| apps/lfx-one/src/app/shared/services/account-context.service.ts | Merges detected orgs into ACCOUNTS for selection. |
| apps/lfx-one/src/app/layouts/dev-toolbar/dev-toolbar.component.ts | Uses computed availableAccounts signal instead of static ACCOUNTS. |
| apps/lfx-one/src/app/layouts/dev-toolbar/dev-toolbar.component.html | Updates template to call the accounts signal (availableAccounts()). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/lfx-one/src/app/shared/services/account-context.service.ts`:
- Around line 42-49: When a refresh returns an empty detected list, clear the
cached org state so stale orgs aren't shown: inside initializeUserOrganizations
(the code path that handles detected arrays) when detected.length === 0, call
the userOrganizations setter with an empty array (userOrganizations([])) and
update the initialized flag/state (via initialized()/its setter or
setInitialized(true)) so the service reflects that a refresh occurred and
availableAccounts will return ACCOUNTS instead of stale entries.
In `@apps/lfx-one/src/app/shared/services/persona.service.ts`:
- Around line 87-92: The persist call in setPersonas(primary: PersonaType, all:
PersonaType[], multiProject = false, multiFoundation = false, organizations?:
Account[]) overwrites stored organizations when callers (like setPersona) omit
the organizations arg; update setPersonas to use the service's existing
organizations state (or last-known organizations) when the organizations
parameter is undefined before calling persistToCookie, or maintain and always
read from a this.organizations property and pass that into persistToCookie so
switching personas does not drop the detected organizations; ensure
persistToCookie receives the preserved organizations value.
- Around line 125-128: The code only calls
this.accountContextService.initializeUserOrganizations(...) when
response.organizations has items, so an API response with organizations: []
never clears client state; change PersonaService to always sync organization
state when response.organizations is present (including empty arrays) — e.g.,
remove the length check and call
initializeUserOrganizations(response.organizations) unconditionally, or call a
new accountContextService.resetUserOrganizations() when the array is empty; also
update AccountContextService (the methods around initializeUserOrganizations and
the no-op behavior at lines 58-77) to accept an empty array and clear/reset
stored org list and selection accordingly so the client state matches the cookie
cleared at Line 122.
In `@apps/lfx-one/src/server/services/persona-detection.service.ts`:
- Around line 329-333: The code currently only validates organization.id before
creating an Account entry; update the logic around
detection.extra['organization'] (the org variable) to ensure both org.id and
org.name exist and are strings before calling seen.add and accounts.push, e.g.
narrow types with typeof checks (validate org?.id && typeof org.id === 'string'
&& org?.name && typeof org.name === 'string'), and only push Account objects
when both accountId and accountName are valid to avoid undefined accountName
values in accounts and maintain the seen set consistency.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 749abd03-ec66-4387-a75a-aecaab476e96
📒 Files selected for processing (10)
apps/lfx-one/src/app/layouts/dev-toolbar/dev-toolbar.component.htmlapps/lfx-one/src/app/layouts/dev-toolbar/dev-toolbar.component.tsapps/lfx-one/src/app/shared/services/account-context.service.tsapps/lfx-one/src/app/shared/services/persona.service.tsapps/lfx-one/src/server/server.tsapps/lfx-one/src/server/services/persona-detection.service.tsapps/lfx-one/src/server/utils/organization-matcher.tsapps/lfx-one/src/server/utils/persona-helper.tspackages/shared/src/interfaces/persona-detection.interface.tspackages/shared/src/interfaces/persona.interface.ts
💤 Files with no reviewable changes (1)
- apps/lfx-one/src/server/utils/organization-matcher.ts
Remove deleted file from the backend architecture doc file tree. Signed-off-by: Asitha de Silva <asithade@gmail.com>
Address review comments from @MRashad26, copilot[bot], coderabbitai[bot]: - persona-detection.service.ts: validate both org.id and org.name as strings before mapping to Account (per @MRashad26, copilot[bot], coderabbitai[bot]) - persona-detection.service.ts: sanitize debug log to only emit org id/name, not full detection extras (per copilot[bot]) - persona.service.ts: preserve organizations across persona switches via lastKnownOrganizations signal (per coderabbitai[bot]) - persona.service.ts: persist organizations to cookie even when personas.length === 0 (per @MRashad26) - persona.service.ts: always sync organizations to AccountContextService including empty arrays to clear stale state (per coderabbitai[bot]) - persona.service.ts: document unconditional refreshFromApi trade-off with comment explaining NATS cache bounds (per @MRashad26) - account-context.service.ts: clear org state on empty refresh and validate stored selection against merged ACCOUNTS + detected set (per copilot[bot], coderabbitai[bot]) Resolves 11 review threads. Signed-off-by: Asitha de Silva <asithade@gmail.com>
Review Feedback AddressedCommit: 0aab7e6 Changes Made
No Change Needed
Threads Resolved11 of 11 unresolved threads addressed. |
Summary
board_memberdetection extras returned by the persona service and propagate through SSR and client-side flowsorganization-matcher.ts(dead code, never imported)LFXV2-1475
Related
Generated with Claude Code