aboutsummaryrefslogtreecommitdiffstats
path: root/src/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/api')
-rw-r--r--src/api/users.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/api/users.rs b/src/api/users.rs
index 122fc4b..1dda33b 100644
--- a/src/api/users.rs
+++ b/src/api/users.rs
@@ -197,6 +197,7 @@ async fn own_key(
let mut path = entry.clone();
path.extend(["keys".to_owned(), id.clone()]);
let adding = line.is_some();
+ let id_kept = id.clone();
state
.mutate_doc_for(Some(user.to_owned()), Sign::Protocol, move |doc| {
if crate::access::policy::of(&*doc).strict() {
@@ -215,6 +216,21 @@ async fn own_key(
Some("no entry of yours".to_owned()),
));
}
+ if line.is_none() {
+ let mut keys = entry.clone();
+ keys.push("keys".to_owned());
+ let others = store::keys_at(&*doc, &keys)?
+ .unwrap_or_default()
+ .into_iter()
+ .filter(|other| *other != id_kept)
+ .count();
+ if others == 0 {
+ return Err(ApiError(
+ StatusCode::CONFLICT,
+ Some("your last key: add another first".to_owned()),
+ ));
+ }
+ }
match line {
Some(line) => store::write_path(doc, &path, &json!(line))?,
None => match store::delete_path(doc, &path, false) {