fix #14740: upload a transcript only once

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 <noreply@anthropic.com>
This commit is contained in:
hauke
2026-11-06 15:40:31 +01:00
co-authored by Claude Sonnet 5
parent dad98b4558
commit fa55dcb7bc
2 changed files with 33 additions and 28 deletions
+26 -3
View File
@@ -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<UploadClaim<'_>, 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();
+7 -25
View File
@@ -49,7 +49,6 @@
// take a while); their errors are kept per call too.
let uploading = $state<CallId[]>([])
let uploadErrors = $state<Record<CallId, string>>({})
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'}
<button class="btn primary" disabled={busy} onclick={retry}>Erneut versuchen</button>
<button class="btn danger" disabled={busy} onclick={discard}>Verwerfen</button>
{:else if call.status === 'done' && confirmingUpload}
<span class="confirm">Dieses Transkript wurde bereits hochgeladen. Nochmal hochladen?</span>
<button class="btn primary" onclick={upload}>Hochladen</button>
<button class="btn" onclick={() => (confirmingUpload = false)}>Abbrechen</button>
{:else if call.status === 'done'}
{:else if call.status === 'done' && !call.uploaded_at}
<button
class="btn primary"
disabled={!call.transcribed_at || isUploading}
title={call.transcribed_at ? 'Transkript ins CRM hochladen' : 'Noch kein Transkript'}
onclick={uploadClick}
onclick={upload}
>
{isUploading
? 'wird hochgeladen…'
: call.uploaded_at
? 'Erneut hochladen'
: 'Transkript hochladen'}
{isUploading ? 'wird hochgeladen…' : 'Transkript hochladen'}
</button>
{/if}
</span>
@@ -568,8 +551,7 @@
margin-left: auto;
}
.uploaded,
.confirm {
.uploaded {
font-size: 12px;
}