feat #14740: admin backend client and transcript upload text

recorder-core side of linking the app to the euvino admin backend:
- backend: BackendClient (create a key with the admin's session cookie,
  check a key, upload a transcript; redirects never followed), German
  error messages, the login-window decision (LoginStep) and the upload
  flow with login, one retry after a refused key and no loop
- call_view: the upload text (header + merged, renamed lines) and the
  upload fields on the call
- store: schema v3 with crm_transcript_id and uploaded_at
- settings: backend_url (validated https), the app-managed login fields,
  kept on edit and cleared when the backend URL changes
- secrets: Service::Backend; http: per-request follow_redirects;
  FakeTransport can script transport errors

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
hauke
2026-11-06 14:52:50 +01:00
co-authored by Claude Opus 5.5
parent 54a81e5ba0
commit 58e96a2954
11 changed files with 1447 additions and 30 deletions
+151 -2
View File
@@ -21,6 +21,10 @@ pub struct CallListItem {
pub interrupted: bool,
/// The name the user gave the call, if any.
pub title: Option<String>,
/// The id the CRM gave the transcript at its last upload.
pub crm_transcript_id: Option<String>,
/// When the transcript was last uploaded.
pub uploaded_at: Option<DateTime<Local>>,
}
impl CallListItem {
@@ -33,6 +37,8 @@ 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,
}
}
}
@@ -45,12 +51,14 @@ pub fn duration_secs(call: &Call) -> i64 {
}
/// The selected call's header data: its list row plus the error of a
/// failed run.
/// failed run and when it was transcribed (only a transcribed call can be
/// uploaded).
#[derive(Serialize, Clone, Debug, PartialEq)]
pub struct CallHeader {
#[serde(flatten)]
pub item: CallListItem,
pub error: Option<String>,
pub transcribed_at: Option<DateTime<Local>>,
}
/// A transcript line with the speaker's display label.
@@ -114,6 +122,7 @@ impl CallDetail {
call: CallHeader {
item: CallListItem::of(call),
error: call.error.clone(),
transcribed_at: call.transcribed_at,
},
segments,
merges: merge_views(merges, &speaker_names),
@@ -122,6 +131,70 @@ impl CallDetail {
}
}
impl CallDetail {
/// The transcript as plain text for the CRM, as the user sees it
/// (speaker merges and renames applied): a header with title, date,
/// call app and duration, a blank line, then one `[mm:ss] Name: text`
/// line per segment (`h:mm:ss` from one hour on). Blank segments are
/// left out; with none left, the error is [`NO_TRANSCRIPT`].
pub fn upload_text(&self) -> Result<String, String> {
let lines: Vec<String> = self
.segments
.iter()
.filter(|segment| !segment.text.trim().is_empty())
.map(|segment| {
format!(
"[{}] {}: {}",
offset(segment.start),
segment.label,
segment.text.trim()
)
})
.collect();
if lines.is_empty() {
return Err(NO_TRANSCRIPT.to_string());
}
let item = &self.call.item;
let date = item.started_at.format("%d.%m.%Y %H:%M").to_string();
let title = match &item.title {
Some(title) => title.clone(),
None => format!("{} · {date}", item.app),
};
let minutes = ((item.duration_secs as f64 / 60.0).round() as i64).max(1);
let header = [
format!("Titel: {title}"),
format!("Datum: {date}"),
format!("Kanal: {}", item.app),
format!("Dauer: {minutes} min"),
String::new(),
];
Ok(header
.into_iter()
.chain(lines)
.collect::<Vec<_>>()
.join("\n"))
}
}
/// Why [`CallDetail::upload_text`] has nothing to upload.
pub const NO_TRANSCRIPT: &str = "Kein Transkript zum Hochladen";
/// Position in the recording: "04:07", or "1:02:07" from one hour on (like
/// the transcript view).
fn offset(secs: f64) -> String {
let total = if secs.is_finite() && secs > 0.0 {
secs as u64
} else {
0
};
let (h, m, s) = (total / 3600, total % 3600 / 60, total % 60);
if h > 0 {
format!("{h}:{m:02}:{s:02}")
} else {
format!("{m:02}:{s:02}")
}
}
fn merge_views(
merges: &BTreeMap<String, String>,
speaker_names: &BTreeMap<String, String>,
@@ -175,6 +248,8 @@ mod tests {
transcribed_at: None,
audio_deleted: false,
title: None,
crm_transcript_id: None,
uploaded_at: None,
}
}
@@ -213,11 +288,18 @@ mod tests {
status: CallStatus::AwaitingDecision,
interrupted: true,
title: None,
crm_transcript_id: None,
uploaded_at: None,
}
);
c.title = Some("Angebot Rioja".into());
assert_eq!(CallListItem::of(&c).title.as_deref(), Some("Angebot Rioja"));
c.crm_transcript_id = Some("4711".into());
c.uploaded_at = Some(at(11, 0, 0));
let item = CallListItem::of(&c);
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]
@@ -328,6 +410,7 @@ mod tests {
c.status = CallStatus::Failed;
c.error = Some("Netzwerkfehler".into());
c.title = Some("Reklamation".into());
c.transcribed_at = Some(at(10, 20, 0));
let merges = keys(&[("remote:2", "remote:1")]);
let value =
@@ -344,7 +427,10 @@ mod tests {
"status": "failed",
"interrupted": false,
"title": "Reklamation",
"crm_transcript_id": null,
"uploaded_at": null,
"error": "Netzwerkfehler",
"transcribed_at": serde_json::to_value(at(10, 20, 0)).unwrap(),
},
"segments": [],
"speaker_names": {},
@@ -357,4 +443,67 @@ mod tests {
})
);
}
fn detail_with(c: &Call, segments: &[Segment], names: &[(&str, &str)]) -> CallDetail {
CallDetail::of(c, segments, keys(names), &keys(&[("remote:2", "remote:1")]))
}
#[test]
fn the_upload_text_has_a_header_and_the_lines_the_user_sees() {
let segments = [
segment(Speaker::Remote(1), 0.0, "Guten Tag,"),
segment(Speaker::Remote(2), 2.5, "hier Weingut Beispiel."),
segment(Speaker::Me, 65.9, "Hallo."),
segment(Speaker::Remote(3), 600.0, " "),
segment(Speaker::Remote(1), 3725.0, "Zur Lieferung."),
];
let c = call(Some(at(10, 46, 0)));
let text = detail_with(&c, &segments, &[("remote:1", "Frau Beispiel")]).upload_text();
assert_eq!(
text.as_deref(),
Ok("Titel: Microsoft Teams · 05.11.2026 10:14\n\
Datum: 05.11.2026 10:14\n\
Kanal: Microsoft Teams\n\
Dauer: 32 min\n\
\n\
[00:00] Frau Beispiel: Guten Tag, hier Weingut Beispiel.\n\
[01:05] Ich: Hallo.\n\
[1:02:05] Frau Beispiel: Zur Lieferung.")
);
}
#[test]
fn the_upload_text_uses_the_title_and_at_least_one_minute() {
let mut c = call(Some(at(10, 14, 10)));
c.title = Some("Angebot Rioja".into());
let text = detail_with(&c, &[segment(Speaker::Me, 0.0, "Hallo.")], &[])
.upload_text()
.unwrap();
let header: Vec<_> = text.lines().take(4).collect();
assert_eq!(
header,
[
"Titel: Angebot Rioja",
"Datum: 05.11.2026 10:14",
"Kanal: Microsoft Teams",
"Dauer: 1 min",
]
);
}
#[test]
fn an_empty_transcript_is_not_uploaded() {
let c = call(Some(at(10, 46, 0)));
for segments in [vec![], vec![segment(Speaker::Me, 0.0, " ")]] {
assert_eq!(
detail_with(&c, &segments, &[]).upload_text(),
Err(NO_TRANSCRIPT.to_string())
);
}
assert_eq!(NO_TRANSCRIPT, "Kein Transkript zum Hochladen");
}
}