mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 02:09:00 +00:00
ui-patterns: the hosted PDF dialog takes the open and permissions passwords as automation fields (never listed), under the rows' standard rule
This commit is contained in:
@@ -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" {
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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::<HostedPdfExport>(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() {
|
||||
|
||||
Reference in New Issue
Block a user