aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/users.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/users.rs')
-rw-r--r--src/api/users.rs36
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, &registry::user_path(name)).ok()??;
+ let mut entry = view::read_plain(doc, &registry::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, &registry::entry(by, since, &caps))?;
+ view::write_path(doc, &path, &registry::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,
&registry::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, &registry::entry(by, since, &caps))?;
+ view::write_path(doc, &path, &registry::entry(by, since, &caps))?;
}
Ok(())
})