use crate::bridge::envelope::PhysicalPlan;
use crate::control::security::identity::{Permission, required_permission};
use nodedb_physical::physical_plan::MetaOp;
pub fn plan_is_write(plan: &PhysicalPlan) -> bool {
if matches!(
plan,
PhysicalPlan::Meta(
MetaOp::StageWrite { .. }
| MetaOp::MarkSavepoint { .. }
| MetaOp::RollbackToSavepoint { .. }
)
) {
return false;
}
matches!(required_permission(plan), Permission::Write)
}
#[cfg(test)]
mod tests {
use super::*;
use nodedb_physical::physical_plan::{DocumentOp, KvOp};
#[test]
fn point_get_is_not_a_write() {
let plan = PhysicalPlan::Document(DocumentOp::PointGet {
collection: "c".into(),
document_id: "d".into(),
surrogate: nodedb_types::Surrogate::ZERO,
pk_bytes: Vec::new(),
rls_filters: Vec::new(),
system_time: nodedb_types::SystemTimeScope::Current,
valid_at_ms: None,
});
assert!(!plan_is_write(&plan));
}
#[test]
fn kv_put_is_a_write() {
let plan = PhysicalPlan::Kv(KvOp::Put {
collection: "c".into(),
key: b"k".to_vec(),
value: b"v".to_vec(),
ttl_ms: 0,
surrogate: nodedb_types::Surrogate::ZERO,
});
assert!(plan_is_write(&plan));
}
#[test]
fn cancel_meta_op_is_not_a_write() {
let plan = PhysicalPlan::Meta(MetaOp::Cancel {
target_request_id: crate::types::RequestId::new(1),
});
assert!(!plan_is_write(&plan));
}
}