Skip to content

TT-7681 Add bibleId ownership validation - #602

Open
gtryus wants to merge 2 commits into
developfrom
feature/TT-7681-bible-id-invalid-save
Open

TT-7681 Add bibleId ownership validation#602
gtryus wants to merge 2 commits into
developfrom
feature/TT-7681-bible-id-invalid-save

Conversation

@gtryus

@gtryus gtryus commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Root cause (TT-7681): In PublishExpansion.tsx, bibleIdIsValid short-circuited to "no error" whenever the typed value matched bible?.attributes?.bibleId — regardless of whether that loaded bible belonged to another team. When a user typed another team's Bible ID, TeamDialog loaded that foreign bible into the bible prop and flagged ownerName. Deleting and retyping the last character re-triggered validation while bible still referenced the foreign record, so newName === bible.attributes.bibleId was true and the function returned '', clearing the error and re-enabling Save — even though the ID still belonged to another team.

Fix: PublishExpansion.tsx:210 now only treats "typed value equals loaded bible's id" as "unchanged" when !ownerName (i.e., we actually own that bible). Otherwise it falls through to the existing "already exists" check, reusing the existing bibleidexists string — no new localization strings were needed.

Test: Added PublishExpansion bibleId ownership validation (TT-7681) in PublishExpansion.test.tsx, following this repo's existing RTL pattern for this component. It renders with a bible/ownerName shape matching another team's Bible ID, mirrors the exact repro (delete last char, retype it), and asserts the error stays non-empty and the field stays aria-invalid.

Verified red on the original code (error incorrectly went to '') and green after the fix, plus npm run typecheck and the existing resolveBibleForSave tests still pass.

@gtryus gtryus changed the title TT-7681 Add bibleId ownership validation and update test cases for existing Bible ID handling TT-7681 Add bibleId ownership validation Sep 12, 2026
In [TeamDialog.tsx:471-475](vscode-webview://1vvl62agp8nmso4u3onasscp49436tio9t463rhlr0pga78gsjbi/src/renderer/src/components/Team/TeamDialog.tsx#L471-L475), `ownerName` collapses to `undefined` whenever `owner` is truthy (a different team) but that team's `organization` record isn't in the local cache — `organizations.find(...)` just returns `undefined`. My earlier fix used `!ownerName` as a stand-in for "not foreign," so exactly that case (foreign owner, but org record not yet synced) bypassed validation again.

**Fix applied:**

- [TeamDialog.tsx:471](vscode-webview://1vvl62agp8nmso4u3onasscp49436tio9t463rhlr0pga78gsjbi/src/renderer/src/components/Team/TeamDialog.tsx#L471): now passes a new `foreignOwner` boolean, `Boolean(owner && owner !== values?.team.id)` — derived only from the already-available `owner` org id (via `getBibleOwner`, which reads `organizationbible` records directly and doesn't need the `organization` record itself), independent of the display-name lookup.

- [PublishExpansion.tsx:228](vscode-webview://1vvl62agp8nmso4u3onasscp49436tio9t463rhlr0pga78gsjbi/src/renderer/src/components/PublishExpansion.tsx#L228): `bibleIdIsValid` now gates on `!foreignOwner` instead of `!ownerName`; `ownerName` is used only for the alert text as recommended.

- [PublishExpansion.tsx:236-242](vscode-webview://1vvl62agp8nmso4u3onasscp49436tio9t463rhlr0pga78gsjbi/src/renderer/src/components/PublishExpansion.tsx#L236-L242): added an effect that revalidates the already-typed id whenever `foreignOwner` changes, since `owner`/`foreignOwner` resolve one render after `bible` (TeamDialog computes it in a separate effect) — closing the "later arrival doesn't re-run validation" gap too.

**Tests** ([PublishExpansion.test.tsx](vscode-webview://1vvl62agp8nmso4u3onasscp49436tio9t463rhlr0pga78gsjbi/src/renderer/src/components/PublishExpansion.test.tsx#L132-L216)): extended the TT-7681 describe block with a new case, `keeps the existing-bible error when the foreign owner name has not loaded`, rendering with `foreignOwner: true, ownerName: undefined`. Verified red against the `!ownerName` version (error incorrectly cleared to `''`) and green with the `foreignOwner`-based fix; the original TT-7681 test and `npm run typecheck` still pass.
@gtryus
gtryus marked this pull request as draft September 12, 2026 02:33
@gtryus
gtryus marked this pull request as ready for review September 12, 2026 02:45
@gtryus
gtryus requested a balanced review from Copilot September 12, 2026 02:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

An unused import may fail linting, and the delayed ownership transition lacks direct test coverage.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds robust Bible ID ownership validation to prevent saving IDs owned by another team.

Changes:

  • Introduces an explicit foreign-owner flag and revalidation.
  • Adds regression tests for missing or loaded owner names.
File summaries
File Description
TeamDialog.tsx Supplies foreign ownership state.
PublishExpansion.tsx Prevents foreign Bible IDs from passing validation.
PublishExpansion.test.tsx Adds ownership regression coverage.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

// eslint-disable-next-line @typescript-eslint/no-unused-vars
import React from 'react';
import { act, render, waitFor } from '@testing-library/react';
import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';
Comment on lines +236 to +240
useEffect(() => {
// `foreignOwner` can resolve one render after `bible` (TeamDialog looks
// up the owning org in a separate effect). Re-check the id already
// typed so a stale '' error doesn't leave Save wrongly enabled.
if (bibleId) setBibleIdError(bibleIdIsValid(bibleId));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants