aboutsummaryrefslogtreecommitdiffstats
path: root/src/access
diff options
context:
space:
mode:
Diffstat (limited to 'src/access')
-rw-r--r--src/access/rules.rs23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/access/rules.rs b/src/access/rules.rs
index 43404cf..745dd7e 100644
--- a/src/access/rules.rs
+++ b/src/access/rules.rs
@@ -95,6 +95,9 @@ pub(crate) struct Reads {
member: HashMap<String, bool>,
/// By user: what the registry lets it do.
caps: HashMap<String, Caps>,
+ /// Whether the document's own policy, at its heads then, is strict
+ /// (`before_strict`): kept across `seen`, read again once the document takes more.
+ strict_now: Option<(Vec<ChangeHash>, bool)>,
}
impl Reads {
@@ -103,11 +106,25 @@ impl Reads {
if self.seen != seen {
*self = Self {
seen: seen.to_vec(),
+ strict_now: self.strict_now.take(),
..Self::default()
};
}
self
}
+
+ /// Whether `doc`'s policy, as it stands, is strict: read once for its heads.
+ fn strict_now(&mut self, doc: &Document) -> bool {
+ let heads = doc.get_heads();
+ match &self.strict_now {
+ Some((at, strict)) if *at == heads => *strict,
+ _ => {
+ let strict = super::policy::of(doc).strict();
+ self.strict_now = Some((heads, strict));
+ strict
+ }
+ }
+ }
}
impl Reads {
@@ -161,6 +178,7 @@ pub(crate) fn judge_reading(
.get_or_insert_with(|| super::policy::of(&at))
.clone();
if !policy.strict()
+ && reads.strict_now(doc)
&& let Some(why) = before_strict(doc, change)
{
return Err(Refusal::Rule(why));
@@ -359,11 +377,8 @@ pub(crate) fn judge_reading(
/// later, strict over strict, names the same change; one written beside it, strict or
/// not, is refused like any other, so a change made later to look as old can't take its
/// place. A swarm strict from its genesis change (`--bootstrap-policy`) has no such
-/// time. None where `doc`'s policy isn't strict: there, nothing changes.
+/// time. Asked only where `doc`'s policy is strict: elsewhere, nothing changes.
fn before_strict(doc: &Document, change: &Change<'_>) -> Option<String> {
- if !super::policy::of(doc).strict() {
- return None;
- }
let held = crate::document::changes::holds(doc, &change.hash);
let beside = turned_strict(doc).into_iter().find(|turned| {
*turned != change.hash