aboutsummaryrefslogtreecommitdiffstats
path: root/src/access/policy.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-29 03:15:05 +0000
committertv <tv@krebsco.de>2026-11-29 03:15:05 +0000
commit9188fa6e13ea7facfab5fb6f55bf26444ec2c01e (patch)
tree28b33908d0519bd21b03ee18bb34126c484ec0bb /src/access/policy.rs
parentc396d33a34ee6685e9a561baa4d3ae4956b697be (diff)
document: values read and written through a view any kind of document gives
document::view: Read (the value at a path, plain, typed, a map's keys) and Write (a value written, one deleted), which Automerge's documents, writes in progress and documents as they were all are. The member registry, the users, access control's reads and rules, the topology, forgetting and bootstrap read and write through them, and name neither Automerge's ReadDoc and Transactable nor document::store, which is what an Automerge document can do beyond. How a swarm holding a store judges what a change writes is handed to the rules (rules::judge_seen), being its kind of document's to say.
Diffstat (limited to 'src/access/policy.rs')
-rw-r--r--src/access/policy.rs20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/access/policy.rs b/src/access/policy.rs
index 1e28731..e4027b8 100644
--- a/src/access/policy.rs
+++ b/src/access/policy.rs
@@ -20,7 +20,8 @@
use serde_json::Value as JsonValue;
-use crate::document::{ReadDoc, meta, store};
+use crate::document::meta;
+use crate::document::view::{self, Read};
/// The policy versions this node knows: rules by path, and a swarm holding a store.
pub(crate) const VERSION: u64 = 1;
@@ -108,7 +109,7 @@ pub(crate) fn first(
pub(crate) fn as_written(value: &JsonValue) -> Result<Policy, String> {
let mut doc = crate::document::Document::new();
let mut write = doc.transaction();
- store::write_path(&mut write, &path(), value).map_err(|error| error.to_string())?;
+ view::write_path(&mut write, &path(), value).map_err(|error| error.to_string())?;
let policy = of(&write);
write.rollback();
Ok(policy)
@@ -118,8 +119,8 @@ pub(crate) fn as_written(value: &JsonValue) -> Result<Policy, String> {
/// where its `store` is, as continuum writes them: an Automerge text there, or one holding
/// the policy, reads as a string in plain JSON, so a policy that would read so only
/// through a text is one nobody knows, never what its characters spell.
-pub(crate) fn of(doc: &impl ReadDoc) -> Policy {
- match store::read_plain(doc, &path()) {
+pub(crate) fn of(doc: &impl Read) -> Policy {
+ match view::read_plain(doc, &path()) {
Ok(Some(value)) => match read(&value) {
policy if policy.strict() && !a_string(doc, "values") => {
Policy::Unknown("values not a string".to_owned())
@@ -137,13 +138,9 @@ pub(crate) fn of(doc: &impl ReadDoc) -> Policy {
/// Whether the policy `doc` holds, read in typed JSON (where a text is tagged, and an
/// envelope reads as its payload), has a string for its `key`.
-fn a_string(doc: &impl ReadDoc, key: &str) -> bool {
- let typed = crate::document::typed::JsonForm {
- typed: true,
- ..Default::default()
- };
+fn a_string(doc: &impl Read, key: &str) -> bool {
matches!(
- store::read_plain_as(doc, &path(), typed),
+ doc.read_typed(&path()),
Ok(Some(value)) if value.get(key).is_some_and(JsonValue::is_string)
)
}
@@ -211,13 +208,14 @@ fn store_of(value: &JsonValue) -> Policy {
mod tests {
use super::*;
use crate::document::Document;
+ use crate::document::store;
use crate::document::testing::change;
use serde_json::json;
fn with(policy: JsonValue) -> Policy {
let mut doc = Document::new();
change(&mut doc, |doc| {
- store::write_path(doc, &path(), &policy).unwrap();
+ view::write_path(doc, &path(), &policy).unwrap();
});
of(&doc)
}