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
|
||||
/// 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();
|
||||
|
||||
Reference in New Issue
Block a user