feat #14740: track uploads per backend server

Schema v4 adds calls.crm_base_url; existing uploads are tagged with the
test backend. A call counts as uploaded (list/detail fields, the
"Hochgeladen am" line, the upload-once guard) only if it was uploaded to
this build's backend. Uploading to the other server replaces the single
upload record; nothing is deleted.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
hauke
2026-11-09 10:52:16 +01:00
co-authored by Claude Opus 5.5
parent d0ece263a2
commit 3a16c76257
5 changed files with 265 additions and 42 deletions
+90 -10
View File
@@ -28,7 +28,13 @@ pub struct CallListItem {
}
impl CallListItem {
pub fn of(call: &Call) -> Self {
/// `backend_url` is this build's backend (`crate::backend::BACKEND_URL`
/// in the app): an upload recorded for a different one is shown as not
/// uploaded at all ([`uploaded_here`]) — e.g. a transcript sent to the
/// test backend must not look done to a release build reading the same
/// row. Nothing is deleted; the fields are just not shown as set.
pub fn of(call: &Call, backend_url: &str) -> Self {
let uploaded = uploaded_here(call, backend_url);
Self {
id: call.id,
app: call.app.clone(),
@@ -37,8 +43,12 @@ impl CallListItem {
status: call.status,
interrupted: call.interrupted,
title: call.title.clone(),
crm_transcript_id: call.crm_transcript_id.clone(),
uploaded_at: call.uploaded_at,
crm_transcript_id: if uploaded {
call.crm_transcript_id.clone()
} else {
None
},
uploaded_at: if uploaded { call.uploaded_at } else { None },
}
}
}
@@ -50,6 +60,16 @@ pub fn duration_secs(call: &Call) -> i64 {
.map_or(0, |end| (end - call.started_at).num_seconds().max(0))
}
/// Whether `call`'s upload belongs to `backend_url`: its
/// `crm_transcript_id` is set *and* `crm_base_url` is exactly this
/// backend. An upload recorded for a different one (e.g. the test backend,
/// read by a release build) counts as not uploaded: the CRM this
/// `backend_url` talks to has never seen the transcript, so the UI offers
/// the normal upload control again instead of claiming it is done.
pub fn uploaded_here(call: &Call, backend_url: &str) -> bool {
call.crm_transcript_id.is_some() && call.crm_base_url.as_deref() == Some(backend_url)
}
/// The selected call's header data: its list row plus the error of a
/// failed run and when it was transcribed (only a transcribed call can be
/// uploaded).
@@ -104,12 +124,14 @@ pub struct CallDetail {
impl CallDetail {
/// `segments` are the stored ones; `merges` the stored speaker merges
/// (source key → target key).
/// (source key → target key); `backend_url` is this build's backend
/// (see [`CallListItem::of`]).
pub fn of(
call: &Call,
segments: &[Segment],
speaker_names: BTreeMap<String, String>,
merges: &BTreeMap<String, String>,
backend_url: &str,
) -> Self {
let segments = merge::apply_merges(segments, merges)
.iter()
@@ -123,7 +145,7 @@ impl CallDetail {
.collect();
Self {
call: CallHeader {
item: CallListItem::of(call),
item: CallListItem::of(call, backend_url),
error: call.error.clone(),
transcribed_at: call.transcribed_at,
},
@@ -234,6 +256,11 @@ mod tests {
use super::*;
use crate::model::Speaker;
/// This build's backend, for `CallListItem::of`/`CallDetail::of`.
const BACKEND: &str = "https://backend.example";
/// A different backend, for the "uploaded elsewhere" cases.
const OTHER_BACKEND: &str = "https://other.example";
fn at(h: u32, m: u32, s: u32) -> DateTime<Local> {
Local.with_ymd_and_hms(2026, 11, 5, h, m, s).unwrap()
}
@@ -253,6 +280,7 @@ mod tests {
audio_deleted: false,
title: None,
crm_transcript_id: None,
crm_base_url: None,
uploaded_at: None,
}
}
@@ -283,7 +311,7 @@ mod tests {
c.status = CallStatus::AwaitingDecision;
c.interrupted = true;
assert_eq!(
CallListItem::of(&c),
CallListItem::of(&c, BACKEND),
CallListItem {
id: 7,
app: "Microsoft Teams".into(),
@@ -299,13 +327,51 @@ mod tests {
c.title = Some("Angebot Rioja".into());
c.crm_transcript_id = Some("4711".into());
c.crm_base_url = Some(BACKEND.into());
c.uploaded_at = Some(at(11, 0, 0));
let item = CallListItem::of(&c);
let item = CallListItem::of(&c, BACKEND);
assert_eq!(item.title.as_deref(), Some("Angebot Rioja"));
assert_eq!(item.crm_transcript_id.as_deref(), Some("4711"));
assert_eq!(item.uploaded_at, Some(at(11, 0, 0)));
}
#[test]
fn uploaded_here_needs_a_transcript_id_and_a_matching_backend() {
let mut c = call(Some(at(10, 15, 0)));
assert!(!uploaded_here(&c, BACKEND), "never uploaded");
c.crm_transcript_id = Some("4711".into());
c.crm_base_url = Some(OTHER_BACKEND.into());
assert!(
!uploaded_here(&c, BACKEND),
"uploaded, but to a different backend"
);
c.crm_base_url = Some(BACKEND.into());
assert!(uploaded_here(&c, BACKEND));
}
#[test]
fn an_upload_to_another_backend_is_hidden_from_the_list_item() {
// Uploaded to OTHER_BACKEND; this build's backend is BACKEND: the
// row still has crm_transcript_id/uploaded_at, but the view must
// not show them, so the UI offers the normal upload control again.
let mut c = call(Some(at(10, 15, 0)));
c.crm_transcript_id = Some("4711".into());
c.crm_base_url = Some(OTHER_BACKEND.into());
c.uploaded_at = Some(at(11, 0, 0));
let item = CallListItem::of(&c, BACKEND);
assert_eq!(item.crm_transcript_id, None);
assert_eq!(item.uploaded_at, None);
// The same row, read by a build whose backend actually matches:
// shown normally.
let item = CallListItem::of(&c, OTHER_BACKEND);
assert_eq!(item.crm_transcript_id.as_deref(), Some("4711"));
assert_eq!(item.uploaded_at, Some(at(11, 0, 0)));
}
#[test]
fn detail_labels_segments_with_renames_and_defaults() {
let segments = [
@@ -322,6 +388,7 @@ mod tests {
&segments,
names.clone(),
&BTreeMap::new(),
BACKEND,
);
let lines: Vec<_> = detail
@@ -366,7 +433,13 @@ mod tests {
("remote:10", "remote:4"),
]);
let detail = CallDetail::of(&call(Some(at(10, 15, 0))), &segments, names, &merges);
let detail = CallDetail::of(
&call(Some(at(10, 15, 0))),
&segments,
names,
&merges,
BACKEND,
);
let lines: Vec<_> = detail
.segments
@@ -418,7 +491,8 @@ mod tests {
let merges = keys(&[("remote:2", "remote:1")]);
let value =
serde_json::to_value(CallDetail::of(&c, &[], BTreeMap::new(), &merges)).unwrap();
serde_json::to_value(CallDetail::of(&c, &[], BTreeMap::new(), &merges, BACKEND))
.unwrap();
assert_eq!(
value,
@@ -450,7 +524,13 @@ mod tests {
}
fn detail_with(c: &Call, segments: &[Segment], names: &[(&str, &str)]) -> CallDetail {
CallDetail::of(c, segments, keys(names), &keys(&[("remote:2", "remote:1")]))
CallDetail::of(
c,
segments,
keys(names),
&keys(&[("remote:2", "remote:1")]),
BACKEND,
)
}
#[test]