From 89c28d42b120db59bc868f820d5665985ae46cae Mon Sep 17 00:00:00 2001 From: bflatastic Date: Mon, 23 Nov 2026 04:28:52 +0700 Subject: [PATCH] ui-patterns: the hosted PDF dialog takes the open and permissions passwords as automation fields (never listed), under the rows' standard rule --- .../patterns/form_dialogs/pdf_export/hosted.rs | 11 ++++++++++- .../form_dialogs/pdf_export/sections.rs | 2 +- .../tests/it/form_dialogs/pdf_export.rs | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/crates/ui-patterns/src/patterns/form_dialogs/pdf_export/hosted.rs b/crates/ui-patterns/src/patterns/form_dialogs/pdf_export/hosted.rs index e2973048d..471f8d1ce 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/pdf_export/hosted.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/pdf_export/hosted.rs @@ -449,7 +449,8 @@ impl StackDialog for HostedPdfExport { Some(fields) } - /// Sets one of the fields `json_fields` lists, else a settings field; a write to a disabled setting is refused. + /// Sets one of the fields `json_fields` lists, else a settings field, or one of the two passwords, which the settings + /// never serialise and `json_fields` never lists; a write to a disabled setting is refused. fn set_json_field(&mut self, _: &Context, field: &str, value: Value) -> Result<(), String> { let rejects = || FieldRefusal::Rejects(&value).message(field); match field { @@ -478,6 +479,14 @@ impl StackDialog for HostedPdfExport { (bleed.bottom, bleed.left, bleed.right) = (bleed.top, bleed.top, bleed.top); } } + "security.openPassword" | "security.permissionsPassword" => { + if !enabled(&self.settings, field) { + return Err(FieldRefusal::Inactive.message(field)); + } + let password = value.as_str().ok_or_else(rejects)?.to_owned(); + let security = &mut self.settings.security; + *(if field == "security.openPassword" { &mut security.open_password } else { &mut security.permissions_password }) = password; + } "name" | "description" if self.mode == PdfExportMode::PresetEditor => { let text = value.as_str().ok_or_else(rejects)?.to_owned(); if field == "name" { diff --git a/crates/ui-patterns/src/patterns/form_dialogs/pdf_export/sections.rs b/crates/ui-patterns/src/patterns/form_dialogs/pdf_export/sections.rs index 8849563b7..12168dd02 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/pdf_export/sections.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/pdf_export/sections.rs @@ -437,7 +437,7 @@ pub(super) fn enabled(settings: &PdfSettings, path: &str) -> bool { // PDF 1.3 files (PDF/X-1a and PDF/X-3 ones too) have no transparency: it is flattened. "flattenerPreset" => settings.pdf13(), "bleed.top" | "bleed.bottom" | "bleed.left" | "bleed.right" => !settings.bleed.use_document, - "security.printing" | "security.changes" | "security.copy" => plain, + "security.openPassword" | "security.permissionsPassword" | "security.printing" | "security.changes" | "security.copy" => plain, // What can be copied can be read out. "security.screenReader" => plain && !settings.security.copy, "security.plaintextMetadata" => plain && !matches!(settings.compatibility, Compatibility::Pdf13 | Compatibility::Pdf14), diff --git a/crates/ui-patterns/tests/it/form_dialogs/pdf_export.rs b/crates/ui-patterns/tests/it/form_dialogs/pdf_export.rs index f78c26a3f..936d7288b 100644 --- a/crates/ui-patterns/tests/it/form_dialogs/pdf_export.rs +++ b/crates/ui-patterns/tests/it/form_dialogs/pdf_export.rs @@ -93,6 +93,24 @@ fn the_hosted_dialog_takes_the_artboards_and_refuses_what_a_standard_disables() } } +/// Automation sets the two passwords the settings never serialise, as typing them does, never lists them, and is +/// refused them under a standard, as the rows are. +#[trial] +fn the_hosted_dialog_takes_the_passwords_and_never_lists_them() { + let ctx = Context::default(); + let mut host = DialogHost::new(); + let id = host.open(dialog()); + let set = |host: &mut DialogHost, field: &str, value: Value| write_field(host, &ctx, id, field, value); + assert_eq!(set(&mut host, "security.openPassword", json!("open")), Ok(())); + assert_eq!(set(&mut host, "security.permissionsPassword", json!("own")), Ok(())); + assert!(set(&mut host, "security.openPassword", json!(7)).is_err(), "a password is text"); + let security = host.get_mut_by_id::(id).expect("open").settings().security.clone(); + assert_eq!((security.open_password.as_str(), security.permissions_password.as_str()), ("open", "own")); + assert_eq!(listed(&host, id, "security.openPassword"), Value::Null, "a password is never listed"); + assert_eq!(set(&mut host, "standard", json!("pdfX3")), Ok(())); + assert!(set(&mut host, "security.openPassword", json!("other")).is_err(), "a standard takes no password"); +} + /// OK files the settings for the app, which takes them once while the dialog waits for its answer. #[trial] fn ok_files_the_settings_once_for_the_app() {