D3 writes: owner actions (Play rollout share / halt / resume / complete, iOS phased release, send one approved reply) answer the command's confirmation only with a verified host token; reviews reply edits a draft; native dialog names owner actions; token binding tests for every write the window offers

This commit is contained in:
CRTkafa 2026-10-10 20:19:47 +00:00
parent 6e6305a407
commit a66da010ec
11 changed files with 359 additions and 24 deletions

View file

@ -138,7 +138,7 @@ pub async fn sidecar_call(window: WebviewWindow, app: AppHandle, state: State<'_
let mut p = policy::sanitize_js_call(&method, kind, &params.unwrap_or(Value::Null)).map_err(Fail::host)?;
let args = p.get("args").cloned().unwrap_or_else(|| json!({}));
let mut cache_project = None;
if matches!(kind, Some(Kind::Read | Kind::Write)) {
if matches!(kind, Some(Kind::Read | Kind::Write | Kind::Owner)) {
let id = project_id.ok_or_else(|| Fail::host(format!("{method} needs a project")))?;
if id.starts_with("store:") {
// a store-only app: store reads only, through the sidecar's generated config
@ -242,8 +242,26 @@ pub fn dialog_summary(title: &str, description: &str, project: &str, network: bo
s
}
/// Summary of an owner action: users see it right away, so the dialog says so in plain words.
pub fn owner_summary(title: &str, description: &str, project: &str) -> String {
format!("{title} · {project}\n\n{description}\n\nThis is your decision: it changes what users get on the store right away. storebound does it only because you press the button below.")
}
/// Dialog title and the confirm button of a write: owner actions name the action on the button.
pub fn dialog_labels(kind: Kind, title: &str) -> (String, String) {
if kind == Kind::Owner {
(format!("Owner action: {title}"), format!("Yes: {title}"))
} else {
(format!("Apply: {title}"), "Apply".to_string())
}
}
/// Native Apply / Cancel dialog; true on Apply.
async fn confirm_dialog(window: &WebviewWindow, title: String, text: String) -> Res<bool> {
confirm_dialog_with(window, title, text, "Apply".into()).await
}
async fn confirm_dialog_with(window: &WebviewWindow, title: String, text: String, ok: String) -> Res<bool> {
let w = window.clone();
tauri::async_runtime::spawn_blocking(move || {
w.app_handle()
@ -251,7 +269,7 @@ async fn confirm_dialog(window: &WebviewWindow, title: String, text: String) ->
.message(text)
.title(title)
.kind(MessageDialogKind::Warning)
.buttons(MessageDialogButtons::OkCancelCustom("Apply".into(), "Cancel".into()))
.buttons(MessageDialogButtons::OkCancelCustom(ok, "Cancel".into()))
.parent(&w)
.blocking_show()
})
@ -266,9 +284,11 @@ pub async fn write_with_confirm(window: WebviewWindow, app: AppHandle, state: St
guard(&window)?;
let job = job_of(job)?;
let r = state.sidecar.get(&app).await?;
if r.kind(&method) != Some(Kind::Write) || method == "project.init" {
let kind = r.kind(&method);
if !matches!(kind, Some(Kind::Write | Kind::Owner)) || method == "project.init" {
return Err(Fail::host(format!("{method} is not a write method of an app folder")));
}
let kind = kind.unwrap_or(Kind::Write);
let d = r.descriptor(&method).cloned().ok_or_else(|| Fail::host("unknown method"))?;
let args = match args.unwrap_or(json!({})) {
Value::Object(o) => Value::Object(o),
@ -283,14 +303,11 @@ pub async fn write_with_confirm(window: WebviewWindow, app: AppHandle, state: St
if dry["ok"] != Value::Bool(true) {
return Ok(json!({ "confirmed": false, "stage": "dry-run", "dryRun": dry }));
}
let text = format!(
"{}\n\nDry run ({}):\n{}",
dialog_summary(&d.title, &d.description, &proj.name, d.network, d.destructive),
dry["command"].as_str().unwrap_or_default(),
dialog_excerpt(dry["output"].as_str().unwrap_or_default())
);
let summary = if kind == Kind::Owner { owner_summary(&d.title, &d.description, &proj.name) } else { dialog_summary(&d.title, &d.description, &proj.name, d.network, d.destructive) };
let text = format!("{summary}\n\nDry run ({}):\n{}", dry["command"].as_str().unwrap_or_default(), dialog_excerpt(dry["output"].as_str().unwrap_or_default()));
let home = app.path().home_dir().ok().map(|h| h.to_string_lossy().to_string());
if !confirm_dialog(&window, format!("Apply: {}", d.title), tilde(&text, home.as_deref())).await? {
let (title, ok) = dialog_labels(kind, &d.title);
if !confirm_dialog_with(&window, title, tilde(&text, home.as_deref()), ok).await? {
return Ok(json!({ "confirmed": false, "stage": "dialog", "dryRun": dry }));
}
let bound = json!({ "project": proj.path, "args": args });

View file

@ -53,6 +53,9 @@ pub enum Kind {
Session,
/// Account-scoped store reads (apps.list, account.check): the host runs them with one account's key.
Account,
/// Owner actions (rollout share, phased release, sending one approved reply): like writes, a dry run from the
/// window; the real run only through `write_with_confirm`, whose dialog says that users see it at once.
Owner,
}
impl Kind {
@ -64,6 +67,7 @@ impl Kind {
"portfolio" => Kind::Portfolio,
"session" => Kind::Session,
"account" => Kind::Account,
"owner" => Kind::Owner,
_ => return None,
})
}
@ -96,7 +100,7 @@ pub fn sanitize_js_call(method: &str, kind: Option<Kind>, params: &Value) -> Res
}
}
let mut out = obj.clone();
if kind == Kind::Write {
if matches!(kind, Kind::Write | Kind::Owner) {
out.insert("dryRun".into(), Value::Bool(true));
}
Ok(Value::Object(out))