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:
+26
-3
@@ -342,11 +342,20 @@ impl AppState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Reserves call `id` for one upload; released when the claim is
|
/// 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> {
|
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());
|
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 })
|
Ok(UploadClaim { state: self, id })
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1604,6 +1613,7 @@ mod tests {
|
|||||||
fn a_call_is_uploaded_once_at_a_time() {
|
fn a_call_is_uploaded_once_at_a_time() {
|
||||||
let f = fixture();
|
let f = fixture();
|
||||||
let (id, _, _) = finished_call(&f, "a");
|
let (id, _, _) = finished_call(&f, "a");
|
||||||
|
let (other, _, _) = finished_call(&f, "b");
|
||||||
assert!(!f.state.call_detail(id).unwrap().uploading);
|
assert!(!f.state.call_detail(id).unwrap().uploading);
|
||||||
|
|
||||||
let claim = f.state.claim_upload(id).unwrap();
|
let claim = f.state.claim_upload(id).unwrap();
|
||||||
@@ -1613,13 +1623,26 @@ mod tests {
|
|||||||
f.state.claim_upload(id).err(),
|
f.state.claim_upload(id).err(),
|
||||||
Some("Wird bereits hochgeladen".to_string())
|
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);
|
drop(claim);
|
||||||
assert!(!f.state.is_uploading(id));
|
assert!(!f.state.is_uploading(id));
|
||||||
assert!(f.state.claim_upload(id).is_ok());
|
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]
|
#[test]
|
||||||
fn an_upload_is_recorded_on_the_call() {
|
fn an_upload_is_recorded_on_the_call() {
|
||||||
let f = fixture();
|
let f = fixture();
|
||||||
|
|||||||
@@ -49,7 +49,6 @@
|
|||||||
// take a while); their errors are kept per call too.
|
// take a while); their errors are kept per call too.
|
||||||
let uploading = $state<CallId[]>([])
|
let uploading = $state<CallId[]>([])
|
||||||
let uploadErrors = $state<Record<CallId, string>>({})
|
let uploadErrors = $state<Record<CallId, string>>({})
|
||||||
let confirmingUpload = $state(false)
|
|
||||||
|
|
||||||
let editingTitle = $state(false)
|
let editingTitle = $state(false)
|
||||||
let titleDraft = $state('')
|
let titleDraft = $state('')
|
||||||
@@ -106,7 +105,6 @@
|
|||||||
actionError = ''
|
actionError = ''
|
||||||
editingTitle = false
|
editingTitle = false
|
||||||
titleError = ''
|
titleError = ''
|
||||||
confirmingUpload = false
|
|
||||||
refreshDetail()
|
refreshDetail()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +115,6 @@
|
|||||||
actionError = ''
|
actionError = ''
|
||||||
editingTitle = false
|
editingTitle = false
|
||||||
titleError = ''
|
titleError = ''
|
||||||
confirmingUpload = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
@@ -192,18 +189,12 @@
|
|||||||
refreshList()
|
refreshList()
|
||||||
})
|
})
|
||||||
|
|
||||||
/** "Transkript hochladen"; an upload done before asks first. */
|
/** Uploads the shown call's transcript (logging in first if needed). A
|
||||||
function uploadClick() {
|
* call already uploaded has no button any more: the CRM never gets a
|
||||||
if (!detail) return
|
* duplicate. */
|
||||||
if (detail.call.uploaded_at) confirmingUpload = true
|
|
||||||
else upload()
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Uploads the shown call's transcript (logging in first if needed). */
|
|
||||||
async function upload() {
|
async function upload() {
|
||||||
if (!detail) return
|
if (!detail) return
|
||||||
const id = detail.call.id
|
const id = detail.call.id
|
||||||
confirmingUpload = false
|
|
||||||
if (uploading.includes(id)) return
|
if (uploading.includes(id)) return
|
||||||
uploading = [...uploading, id]
|
uploading = [...uploading, id]
|
||||||
delete uploadErrors[id]
|
delete uploadErrors[id]
|
||||||
@@ -360,22 +351,14 @@
|
|||||||
{:else if call.status === 'failed'}
|
{:else if call.status === 'failed'}
|
||||||
<button class="btn primary" disabled={busy} onclick={retry}>Erneut versuchen</button>
|
<button class="btn primary" disabled={busy} onclick={retry}>Erneut versuchen</button>
|
||||||
<button class="btn danger" disabled={busy} onclick={discard}>Verwerfen</button>
|
<button class="btn danger" disabled={busy} onclick={discard}>Verwerfen</button>
|
||||||
{:else if call.status === 'done' && confirmingUpload}
|
{:else if call.status === 'done' && !call.uploaded_at}
|
||||||
<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'}
|
|
||||||
<button
|
<button
|
||||||
class="btn primary"
|
class="btn primary"
|
||||||
disabled={!call.transcribed_at || isUploading}
|
disabled={!call.transcribed_at || isUploading}
|
||||||
title={call.transcribed_at ? 'Transkript ins CRM hochladen' : 'Noch kein Transkript'}
|
title={call.transcribed_at ? 'Transkript ins CRM hochladen' : 'Noch kein Transkript'}
|
||||||
onclick={uploadClick}
|
onclick={upload}
|
||||||
>
|
>
|
||||||
{isUploading
|
{isUploading ? 'wird hochgeladen…' : 'Transkript hochladen'}
|
||||||
? 'wird hochgeladen…'
|
|
||||||
: call.uploaded_at
|
|
||||||
? 'Erneut hochladen'
|
|
||||||
: 'Transkript hochladen'}
|
|
||||||
</button>
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
</span>
|
</span>
|
||||||
@@ -568,8 +551,7 @@
|
|||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.uploaded,
|
.uploaded {
|
||||||
.confirm {
|
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user