diff options
| author | tv <tv@krebsco.de> | 2026-11-29 03:15:05 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-29 03:15:05 +0000 |
| commit | 9188fa6e13ea7facfab5fb6f55bf26444ec2c01e (patch) | |
| tree | 28b33908d0519bd21b03ee18bb34126c484ec0bb /src/api/users.rs | |
| parent | c396d33a34ee6685e9a561baa4d3ae4956b697be (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/api/users.rs')
| -rw-r--r-- | src/api/users.rs | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/api/users.rs b/src/api/users.rs index f27eff1..cf28ed1 100644 --- a/src/api/users.rs +++ b/src/api/users.rs @@ -49,7 +49,7 @@ use super::ApiError; use super::access::{Access, Before, registry_kept}; use super::auth::AuthenticatedUser; use crate::access::{Right, envelope, registry}; -use crate::document::store; +use crate::document::view; use crate::state::AppState; /// A capability as a request gives it. @@ -133,7 +133,7 @@ fn may_manage(state: &AppState, user: &str, access: &Access) -> Result<(), ApiEr /// A user's entry as the API shows it: as recorded, with its name. fn shown(doc: &impl crate::document::ReadDoc, name: &str) -> Option<JsonValue> { - let mut entry = store::read_plain(doc, ®istry::user_path(name)).ok()??; + let mut entry = view::read_plain(doc, ®istry::user_path(name)).ok()??; if let Some(object) = entry.as_object_mut() { object.insert("name".to_owned(), json!(name)); } @@ -148,11 +148,11 @@ pub(crate) async fn own_keys( ) -> Result<Json<JsonValue>, ApiError> { let replica = state.doc.read().await; let path = registry::user_path(&user.0); - let entry = store::read_plain(&replica.doc, &path) + let entry = view::read_plain(&replica.doc, &path) .ok() .flatten() .ok_or_else(|| ApiError(StatusCode::NOT_FOUND, Some("no entry of yours".to_owned())))?; - let signed = match store::read_path(&replica.doc, &path) { + let signed = match view::read_path(&replica.doc, &path) { Ok(Some(JsonValue::String(text))) if envelope::read(&text).is_ok() => Some(text), _ => None, }; @@ -218,7 +218,7 @@ async fn own_key( ), )); } - if store::read_path(&*doc, &entry)?.is_none() { + if view::read_path(&*doc, &entry)?.is_none() { return Err(ApiError( StatusCode::NOT_FOUND, Some("no entry of yours".to_owned()), @@ -227,7 +227,7 @@ async fn own_key( if line.is_none() && !password { let mut keys = entry.clone(); keys.push("keys".to_owned()); - let others = store::keys_at(&*doc, &keys)? + let others = view::keys_at(&*doc, &keys)? .unwrap_or_default() .into_iter() .filter(|other| *other != id_kept) @@ -244,8 +244,8 @@ async fn own_key( } } match line { - Some(line) => store::write_path(doc, &path, &json!(line))?, - None => match store::delete_path(doc, &path, false) { + Some(line) => view::write_path(doc, &path, &json!(line))?, + None => match view::delete_path(doc, &path, false) { Ok(()) => {} Err(crate::document::store::StoreError::NotFound) => { return Err(ApiError(StatusCode::NOT_FOUND, None)); @@ -340,7 +340,7 @@ pub(crate) async fn add( &user.0, format!("Added user {name}"), move |doc, by, since| { - if store::read_path(&*doc, &path)?.is_some() { + if view::read_path(&*doc, &path)?.is_some() { return Err(ApiError( StatusCode::CONFLICT, Some("the user exists".to_owned()), @@ -350,7 +350,7 @@ pub(crate) async fn add( .iter() .map(|(path, rights)| (path.clone(), rights.as_slice())) .collect(); - store::write_path(doc, &path, ®istry::entry(by, since, &caps))?; + view::write_path(doc, &path, ®istry::entry(by, since, &caps))?; Ok(()) }, ) @@ -372,7 +372,7 @@ pub(crate) async fn remove( &user.0, format!("Removed user {name}"), move |doc, _, _| { - store::delete_path(doc, &path, false)?; + view::delete_path(doc, &path, false)?; Ok(()) }, ) @@ -395,12 +395,12 @@ pub(crate) async fn set_disabled( if disabled { "Disabled" } else { "Enabled" } ); change(&state, &user.0, what, move |doc, _, _| { - if store::read_path(&*doc, &entry)?.is_none() { + if view::read_path(&*doc, &entry)?.is_none() { return Err(ApiError(StatusCode::NOT_FOUND, None)); } let mut path = entry; path.push("disabled".to_owned()); - store::write_path(doc, &path, &json!(disabled))?; + view::write_path(doc, &path, &json!(disabled))?; Ok(()) }) .await?; @@ -423,10 +423,10 @@ pub(crate) async fn grant( path.extend(["caps".to_owned(), id.clone()]); let what = format!("Granted user {name} {:?} on {:?}", cap.rights, cap.path); change(&state, &user.0, what, move |doc, by, since| { - if store::read_path(&*doc, &entry)?.is_none() { + if view::read_path(&*doc, &entry)?.is_none() { return Err(ApiError(StatusCode::NOT_FOUND, None)); } - store::write_path( + view::write_path( doc, &path, ®istry::capability(by, since, &cap.path, &rights), @@ -452,7 +452,7 @@ pub(crate) async fn revoke( &user.0, format!("Revoked capability {id} of user {name}"), move |doc, _, _| { - store::delete_path(doc, &path, false)?; + view::delete_path(doc, &path, false)?; Ok(()) }, ) @@ -498,7 +498,7 @@ pub(crate) async fn add_several( change(&state, &user.0, what, move |doc, by, since| { for (name, caps) in &users { let path = registry::user_path(name); - if store::read_path(&*doc, &path)?.is_some() { + if view::read_path(&*doc, &path)?.is_some() { return Err(ApiError( StatusCode::CONFLICT, Some(format!("user {name} exists")), @@ -508,7 +508,7 @@ pub(crate) async fn add_several( .iter() .map(|(path, rights)| (path.clone(), rights.as_slice())) .collect(); - store::write_path(doc, &path, ®istry::entry(by, since, &caps))?; + view::write_path(doc, &path, ®istry::entry(by, since, &caps))?; } Ok(()) }) |
