mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
address review: Batch checks the authorization gate for each save point
This commit is contained in:
1 parent
262e76a9eb
commit
d77082dfd0
2 files changed
+22
No files matched your search
@@ -309,6 +309,10 @@ pub(super) fn batch(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let mut saved: Option<Arc<Document>> = None;
|
||||
for (id, params) in &steps {
|
||||
if batch_save_point(id) {
|
||||
// The scratch session never executes a save point, so the gate would not see it.
|
||||
if let Some(gate) = scratch.authorize {
|
||||
gate(id, params)?;
|
||||
}
|
||||
let st = scratch.active_mut().ok_or(EngineError::NoDocument)?;
|
||||
saved = Some(st.doc.clone());
|
||||
// Batch performs the action's Save / Save As (to its destination), so the
|
||||
|
||||
@@ -1262,6 +1262,24 @@ fn image_processor_scratch_sessions_answer_to_the_authorization_gate() {
|
||||
assert_eq!(r["errors"].as_array().unwrap().len(), 1, "{r}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn batch_save_points_answer_to_the_authorization_gate() {
|
||||
fn deny_save(id: &str, _: &Value) -> Result<()> {
|
||||
if id == "file.save" { Err(EngineError::Other(format!("automation command `{id}` is disabled"))) } else { Ok(()) }
|
||||
}
|
||||
let dir = tmp("batch-save-gate");
|
||||
let input = join(&dir, "in");
|
||||
std::fs::create_dir_all(&input).unwrap();
|
||||
png(&input, "a.png", 8, 8, "#ff0000");
|
||||
let mut s = Session::new();
|
||||
s.authorize = Some(deny_save);
|
||||
let out = join(&dir, "out");
|
||||
let r = s.execute("file.automate.batch", json!({"steps": [["file.save", {}]], "input": input, "output": out, "format": "png"})).unwrap();
|
||||
assert!(r["files"].as_array().unwrap().is_empty(), "{r}");
|
||||
assert_eq!(r["errors"].as_array().unwrap().len(), 1, "{r}");
|
||||
assert!(!std::path::Path::new(&join(&out, "a.png")).exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn load_files_into_stack_and_image_processor_and_batch() {
|
||||
let dir = tmp("batch");
|
||||
|
||||
Reference in new issue
Block a user