Milestone 4: taking access back

Removing someone from a vault, a device, or the team opens departures
on the hub. Each device stops syncing, saves, goes read-only, hands
unshared work over (secrets redacted), and deletes the folder only if
the app created it. Managers review handovers (show/keep/discard/skip);
removed devices may only hand over, then their key is retired. Adds the
delete-from-devices vault setting and team restore.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-29 06:14:28 +07:00
parent 2b4ca84a6b
commit 4025726083
16 changed files with 1222 additions and 133 deletions

View File

@@ -29,6 +29,32 @@ pub struct Me {
pub owner: bool,
pub device_label: String,
pub vaults: Vec<HubVault>,
/// Vaults this device must leave (access ended).
#[serde(default)]
pub leaving: Vec<Departure>,
}
/// A vault this device has to hand over and leave (A6).
#[derive(Debug, Clone, Deserialize)]
pub struct Departure {
pub id: i64,
pub vault_id: i64,
pub vault: String,
pub delete_files: bool,
/// A manager chose "delete without saving".
pub without_saving: bool,
}
/// A departure as a manager sees it.
#[derive(Debug, Deserialize)]
pub struct Handover {
pub id: i64,
pub vault: String,
pub person: String,
pub device: String,
/// waiting (device hasn't reported in), received (to review), kept, discarded, done, skipped
pub state: String,
pub at: i64,
}
#[derive(Debug, Clone, Deserialize)]
@@ -153,6 +179,55 @@ impl HubLink {
}
}
impl HubLink {
pub fn remove(&self, person: &str, vault: &str, without_saving: bool) -> Result<usize> {
let v: Value = self.post("/api/remove", json!({"person": person, "vault": vault, "without_saving": without_saving}))?;
Ok(v["devices"].as_u64().unwrap_or(0) as usize)
}
pub fn remove_device(&self, label: &str, person: Option<&str>) -> Result<()> {
let _: Value = self.post("/api/device/remove", json!({"label": label, "person": person}))?;
Ok(())
}
pub fn team_remove(&self, person: &str) -> Result<()> {
let _: Value = self.post("/api/team/remove", json!({ "person": person }))?;
Ok(())
}
/// Re-enables a removed person; returns a one-time sign-in link.
pub fn team_restore(&self, person: &str) -> Result<String> {
let v: Value = self.post("/api/team/restore", json!({ "person": person }))?;
Ok(v["link"].as_str().unwrap_or_default().to_string())
}
pub fn handovers(&self) -> Result<Vec<Handover>> {
self.get("/api/handovers")
}
/// Changed files in a received handover, as "added/changed/removed path".
pub fn handover_show(&self, id: i64) -> Result<Vec<String>> {
self.post("/api/handovers/show", json!({ "id": id }))
}
/// keep, discard or skip.
pub fn handover_decide(&self, id: i64, decision: &str) -> Result<String> {
let v: Value = self.post("/api/handovers/decide", json!({"id": id, "decision": decision}))?;
Ok(v["message"].as_str().unwrap_or_default().to_string())
}
pub fn vault_setting(&self, vault: &str, delete_from_devices: bool) -> Result<()> {
let _: Value = self.post("/api/vaults/settings", json!({"vault": vault, "delete_from_devices": delete_from_devices}))?;
Ok(())
}
/// Tells the hub this device has handed over (`head`, if anything) and is leaving.
pub fn departure_done(&self, id: i64, head: Option<String>) -> Result<()> {
let _: Value = self.post("/api/departures/done", json!({"id": id, "head": head}))?;
Ok(())
}
}
/// Is `role` allowed to share changes?
pub fn can_edit(role: &str) -> bool {
role == "edit" || role == "manage"