fix(ux): book documents directly from inbox + attach existing underlag when booking transactions (#670)

* fix(inbox): re-add Bokför manuellt on unmatched documents

Pilot feedback: a document in Dokumentinkorg could not be booked
without first matching it to a bank transaction, which is impossible
for cash expenses and other entries with no bank movement. The
backend (/items/:id/book-direct) and BookDirectlyDialog already
support standalone booking — re-expose the button in the unmatched
state. The dialog still offers optional transaction selection inside.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* feat(transactions): pick existing inbox document when booking manually

Pilot feedback: "Bokför manuellt" from a transaction only allowed
uploading new files — an already-uploaded underlag from the inbox
could not be attached. Add a select mode to InboxDocumentPicker
(onSelect prop; journalEntryId now optional) and mount it in
TransactionBookingDialog: picked documents are linked after the
journal entry is created via /api/documents/{id}/link with
inbox_item_id, which also stamps the inbox item as consumed so it
drops out of every pending surface. Non-ok link responses now count
toward the failure toast (previously only network errors did).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(documents): address PR #670 review — stale preview dialog, JE tenancy check

Review findings:
- InboxDocumentPicker left the preview dialog floating open when a pick
  was confirmed from inside it (previewItem was never cleared before
  onClose; the component stays mounted, so the on-open reset never ran).
  Clear it in both select and link mode. (greptile)
- linkToJournalEntry verified the document's company but trusted the
  client-supplied journal_entry_id (FK only requires existence). Add an
  explicit company-scoped journal entry lookup; misses map to the
  existing DOC_LINK_ENTRY_NOT_FOUND envelope. RLS prevented any data
  leak either way — this makes the rejection explicit. New regression
  test covers the cross-tenant case. (compliance-swarm A.8.28)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jakob Wennberg
2026-06-05 09:37:26 +02:00
committed by GitHub
co-authored by Claude Opus 4.8
parent f7cd1b86e7
commit cac692e293
7 changed files with 188 additions and 42 deletions
+15
View File
@@ -305,6 +305,21 @@ export async function linkToJournalEntry(
journalEntryId: string,
journalEntryLineId?: string
): Promise<DocumentAttachment> {
// The document is company-filtered below, but the journal entry id arrives
// from the client and the FK only requires existence — verify it belongs to
// the same company so a crafted id can't anchor a document to another
// tenant's verifikation. (RLS hides foreign rows either way; this makes the
// rejection explicit instead of a confusing downstream state.)
const { data: entry, error: entryError } = await supabase
.from('journal_entries')
.select('id')
.eq('id', journalEntryId)
.eq('company_id', companyId)
.maybeSingle()
if (entryError || !entry) {
throw new Error('Failed to link document: journal entry not found')
}
const { data, error } = await supabase
.from('document_attachments')