Scripts: only the person turns off the external script warning

Automation could answer Yes to the question a script asks before it turns
off the external script warning, through the dialog's answer field or a
pass it drives, and the warning was turned off. Setting Yes as the answer
now fails with "Only the person at the keyboard can turn off the external
script warning", and a Yes given while automation is acting is refused:
the warning stays on and the question opens again. No is still taken from
anyone, as Deny is in a script's file dialog.
This commit is contained in:
dotCooCoo committed 2026-11-28 03:32:28 -08:00
1 parent 6d9695a3a7
commit 7c7bdff24b
2 files changed
+49

No files matched your search

+15
View File
@@ -67,6 +67,8 @@ pub const PICKER_KIND: &str = "scriptFiles";
/// Why Allow Once and Always Allow are refused to automation.
pub(crate) const BY_PERSON: &str = "Only the person at the keyboard can allow a script's file access";
/// Why Yes to turning off the external script warning is refused to automation.
pub(crate) const WARNING_BY_PERSON: &str = "Only the person at the keyboard can turn off the external script warning";
/// The note the file dialog shows when the person picked more files than a script is given.
const PICKED_LEFT_OUT: &str = "A script is given at most 2,048 files: the files picked after them were left out";
@@ -273,6 +275,9 @@ impl StackDialog for ScriptNotice {
let Some(answer) = answers_for(&self.kind).split(", ").find(|answer| *answer == wanted) else {
return Err(format!("`answer` for this {} dialog must be one of: {}", self.kind, answers_for(&self.kind)));
};
if answer == "yes" && self.message == WARNING_OFF_QUESTION {
return Err(WARNING_BY_PERSON.into());
}
self.answer = Some(answer);
}
_ => return Err(FieldRefusal::Unknown.message(field)),
@@ -663,6 +668,16 @@ pub(crate) fn settle_notice(app: &mut VectorcraftApp, result: DialogResult<Scrip
ScriptAnswer { kind, answer, value: String::new() }
}
};
// Only the person at the keyboard turns off the external script warning: Yes from a pass
// automation drives is refused, the warning stays on, and the question opens again.
let warning_off = app.session.script_dialog().is_some_and(|d| d.message == WARNING_OFF_QUESTION);
if warning_off && answer.answer == "yes" && app.automation_is_acting() {
app.status(WARNING_BY_PERSON);
if let Some(d) = app.session.script_dialog() {
open_notice(app, &d);
}
return;
}
if let Err(e) = give(app, &answer) {
app.status(e);
if let Some(d) = app.session.script_dialog() {
@@ -317,3 +317,37 @@ fn the_app_and_a_run_with_nobody_to_ask_give_the_same_results() {
assert_eq!(framed["dialogs"], headless["dialogs"]);
assert_eq!(framed["log"], json!([true, "p", "done"]));
}
/// Only the person at the keyboard turns off the external script warning: Yes from automation, set
/// as the answer or given in a pass automation drives, is refused, the warning stays on and the
/// question opens again; No is taken from automation.
#[test]
fn only_the_person_turns_off_the_external_script_warning() {
let mut app = app();
app.session.prefs.show_external_script_warning = true;
// The warning before the run itself is answered by the person.
start(&mut app, "app.preferences.setBooleanPreference('ShowExternalJSXWarning', false); vc.log('done');");
if is_open::<script_run::RunQuestion>(&app) {
let id = open_id(&app, script_run::KIND);
script_run::with_host(&app, |host, ctx| host.confirm_by_id(ctx, id)).unwrap();
pump(&mut app);
}
assert!(until_dialog(&mut app));
assert_eq!(set(&app, NOTICE_KIND, "answer", json!("yes")).unwrap_err(), script_run::WARNING_BY_PERSON);
assert!(is_open::<ScriptNotice>(&app), "the question stays open");
assert!(app.session.script_dialog().is_some(), "the run still waits");
script_run::forget::<ScriptNotice>(&app);
app.ui.answering_control = true;
let yes = script_run::ScriptAnswer { kind: "confirm".into(), answer: "yes", value: String::new() };
script_run::settle_notice(&mut app, craft::ui::dialog::DialogResult::Ok(yes));
app.ui.answering_control = false;
assert_eq!(app.ui.status, script_run::WARNING_BY_PERSON);
assert!(is_open::<ScriptNotice>(&app), "the question opens again");
assert!(app.session.script_dialog().is_some(), "the run still waits");
set(&app, NOTICE_KIND, "answer", json!("no")).unwrap();
assert!(confirm(&mut app, NOTICE_KIND), "No is taken from automation");
assert!(!until_dialog(&mut app));
assert!(app.session.prefs.show_external_script_warning, "the warning stays on");
}