From fa55dcb7bc0b8451123526dd4396c869a04ddac7 Mon Sep 17 00:00:00 2001 From: hauke Date: Fri, 6 Nov 2026 15:40:31 +0100 Subject: [PATCH] fix #14740: upload a transcript only once MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A call once uploaded can no longer be sent again: claim_upload refuses a call that already carries a CRM transcript id ("Bereits hochgeladen"), checked under the same lock that already serializes uploads per call, so a concurrent second upload can never slip through between the check and the one upload it allows. upload_transcript runs this check before any HTTP request, so a rejected re-upload never reaches the backend. The call detail view drops "Erneut hochladen" and its confirmation dialog: once a call has uploaded_at/crm_transcript_id, only "Hochgeladen am …" is shown, no button. Co-Authored-By: Claude Sonnet 5 --- src-tauri/src/state.rs | 29 ++++++++++++++++++++++++++--- ui/src/routes/Main.svelte | 32 +++++++------------------------- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src-tauri/src/state.rs b/src-tauri/src/state.rs index a0cf769..593ac2b 100644 --- a/src-tauri/src/state.rs +++ b/src-tauri/src/state.rs @@ -342,11 +342,20 @@ impl AppState { } /// Reserves call `id` for one upload; released when the claim is - /// dropped. A second upload of the same call is refused meanwhile. + /// dropped. A second upload of the same call is refused meanwhile, and a + /// call that already carries a CRM transcript id is refused outright: + /// the CRM must never get a duplicate. Both checks happen while + /// `uploading` is locked, so a second upload can never slip in between + /// this check and the one upload it allows. pub fn claim_upload(&self, id: CallId) -> Result, String> { - if !lock(&self.uploading).insert(id) { + let mut uploading = lock(&self.uploading); + if uploading.contains(&id) { return Err("Wird bereits hochgeladen".to_string()); } + if self.find_call(id)?.crm_transcript_id.is_some() { + return Err("Bereits hochgeladen".to_string()); + } + uploading.insert(id); Ok(UploadClaim { state: self, id }) } @@ -1604,6 +1613,7 @@ mod tests { fn a_call_is_uploaded_once_at_a_time() { let f = fixture(); let (id, _, _) = finished_call(&f, "a"); + let (other, _, _) = finished_call(&f, "b"); assert!(!f.state.call_detail(id).unwrap().uploading); let claim = f.state.claim_upload(id).unwrap(); @@ -1613,13 +1623,26 @@ mod tests { f.state.claim_upload(id).err(), Some("Wird bereits hochgeladen".to_string()) ); - assert!(f.state.claim_upload(id + 1).is_ok(), "other calls are free"); + assert!(f.state.claim_upload(other).is_ok(), "other calls are free"); drop(claim); assert!(!f.state.is_uploading(id)); assert!(f.state.claim_upload(id).is_ok()); } + #[test] + fn a_call_already_uploaded_is_not_claimed_again() { + let f = fixture(); + let (id, _, _) = finished_call(&f, "a"); + f.state.mark_uploaded(id, "4711").unwrap(); + + assert_eq!( + f.state.claim_upload(id).err(), + Some("Bereits hochgeladen".to_string()) + ); + assert!(!f.state.is_uploading(id)); + } + #[test] fn an_upload_is_recorded_on_the_call() { let f = fixture(); diff --git a/ui/src/routes/Main.svelte b/ui/src/routes/Main.svelte index eeb5f8a..55e1356 100644 --- a/ui/src/routes/Main.svelte +++ b/ui/src/routes/Main.svelte @@ -49,7 +49,6 @@ // take a while); their errors are kept per call too. let uploading = $state([]) let uploadErrors = $state>({}) - let confirmingUpload = $state(false) let editingTitle = $state(false) let titleDraft = $state('') @@ -106,7 +105,6 @@ actionError = '' editingTitle = false titleError = '' - confirmingUpload = false refreshDetail() } @@ -117,7 +115,6 @@ actionError = '' editingTitle = false titleError = '' - confirmingUpload = false } onMount(() => { @@ -192,18 +189,12 @@ refreshList() }) - /** "Transkript hochladen"; an upload done before asks first. */ - function uploadClick() { - if (!detail) return - if (detail.call.uploaded_at) confirmingUpload = true - else upload() - } - - /** Uploads the shown call's transcript (logging in first if needed). */ + /** Uploads the shown call's transcript (logging in first if needed). A + * call already uploaded has no button any more: the CRM never gets a + * duplicate. */ async function upload() { if (!detail) return const id = detail.call.id - confirmingUpload = false if (uploading.includes(id)) return uploading = [...uploading, id] delete uploadErrors[id] @@ -360,22 +351,14 @@ {:else if call.status === 'failed'} - {:else if call.status === 'done' && confirmingUpload} - Dieses Transkript wurde bereits hochgeladen. Nochmal hochladen? - - - {:else if call.status === 'done'} + {:else if call.status === 'done' && !call.uploaded_at} {/if} @@ -568,8 +551,7 @@ margin-left: auto; } - .uploaded, - .confirm { + .uploaded { font-size: 12px; }