diff options
| author | tv <tv@krebsco.de> | 2026-11-29 03:21:43 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-29 03:21:43 +0000 |
| commit | e63d30c2581033a85489b10c3f5b252fdbb5049e (patch) | |
| tree | 5f4e6f65f1cecfb32f841e7ad7d9d106aeb69b20 /src/access/registry.rs | |
| parent | 9188fa6e13ea7facfab5fb6f55bf26444ec2c01e (diff) | |
state: plain writes take a view to write, Automerge's are asked for as such
AppState::mutate_doc, mutate_doc_registering and mutate_doc_by hand what
they are given a document::view::Write: the member registry, the users,
sessions, forgetting and bootstrap write through them, and take whatever
kind of document gives it. AppState::mutate_doc_for is for what asks
more of an Automerge document than values at paths (the store's API, a
remake's host, a store's events), and gives the heads after the write.
What reads a view takes one of any size (dyn Write among them).
Diffstat (limited to 'src/access/registry.rs')
| -rw-r--r-- | src/access/registry.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/access/registry.rs b/src/access/registry.rs index 5a58e1f..f0034ba 100644 --- a/src/access/registry.rs +++ b/src/access/registry.rs @@ -35,12 +35,12 @@ pub(crate) fn user_path(name: &str) -> Vec<String> { /// Whether the swarm has a registry: until it has, every user a node lets in may do /// everything but write protocol data (`docs/access.md`, A swarm without a registry). -pub(crate) fn exists(doc: &impl Read) -> bool { +pub(crate) fn exists(doc: &(impl Read + ?Sized)) -> bool { matches!(view::keys_at(doc, &users_dir()), Ok(Some(_))) } /// The registered users' names, sorted. -pub(crate) fn names(doc: &impl Read) -> Vec<String> { +pub(crate) fn names(doc: &(impl Read + ?Sized)) -> Vec<String> { let mut names = view::keys_at(doc, &users_dir()) .ok() .flatten() @@ -128,7 +128,7 @@ impl User { } /// The entry of user `name`, if it has one. -pub(crate) fn user(doc: &impl Read, name: &str) -> Option<User> { +pub(crate) fn user(doc: &(impl Read + ?Sized), name: &str) -> Option<User> { let value = view::read_plain(doc, &user_path(name)).ok()??; let mut user = value.is_object().then(|| User::from_json(&value))?; // A damaged one revokes every token. @@ -156,7 +156,7 @@ pub(crate) fn session_path(name: &str, session: &str) -> Vec<String> { } /// Whether user `name`'s session `session` was ended (`session_path`). -pub(crate) fn session_ended(doc: &impl Read, name: &str, session: &str) -> bool { +pub(crate) fn session_ended(doc: &(impl Read + ?Sized), name: &str, session: &str) -> bool { view::read_path(doc, &session_path(name, session)) .ok() .flatten() @@ -164,7 +164,7 @@ pub(crate) fn session_ended(doc: &impl Read, name: &str, session: &str) -> bool } /// The users who may manage users: enabled, with `write` on `_continuum/users`. -pub(crate) fn managers(doc: &impl Read) -> Vec<String> { +pub(crate) fn managers(doc: &(impl Read + ?Sized)) -> Vec<String> { names(doc) .into_iter() .filter(|name| caps_of(doc, name).allows(Right::Write, &users_dir())) @@ -172,7 +172,7 @@ pub(crate) fn managers(doc: &impl Read) -> Vec<String> { } /// What user `name` may do: none if it isn't registered (or is disabled). -pub(crate) fn caps_of(doc: &impl Read, name: &str) -> Caps { +pub(crate) fn caps_of(doc: &(impl Read + ?Sized), name: &str) -> Caps { user(doc, name).map(|user| user.caps()).unwrap_or_default() } |
