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

@@ -110,6 +110,27 @@ enum Command {
},
/// Who has access to a vault, and their devices
Members { vault: String },
/// Take someone's access to one vault away; their unshared work comes back as a handover
Remove {
person: String,
#[arg(long)]
vault: String,
/// Delete their copy without sending anything back
#[arg(long)]
without_saving: bool,
},
/// Remove someone from the team, or bring them back (team owner)
Team {
#[command(subcommand)]
action: TeamCmd,
},
/// Unshared work that came back from people and devices leaving vaults
Handovers,
/// Look at a handover and decide about it
Handover {
#[command(subcommand)]
action: HandoverCmd,
},
/// The hub's access log (team owner)
Hub {
#[command(subcommand)]
@@ -124,10 +145,42 @@ enum Command {
},
}
#[derive(Subcommand)]
enum TeamCmd {
/// Ends every vault and device of theirs; the account is disabled (restorable)
Remove {
person: String,
/// Don't ask for confirmation
#[arg(long)]
yes: bool,
},
/// Re-enable a removed person (no vaults); prints a one-time sign-in link
Restore { person: String },
}
#[derive(Subcommand)]
enum HandoverCmd {
/// Which notes it changes
Show { id: i64 },
/// Bring it into the vault (same-lines clashes keep both)
Keep { id: i64 },
/// Drop it
Discard { id: i64 },
/// For a device that hasn't reported in: delete its copy without saving
Skip { id: i64 },
}
#[derive(Subcommand)]
enum VaultCmd {
/// Create an empty vault on the hub
New { name: String },
/// Change a vault's settings
Set {
name: String,
/// Delete a person's copy from their devices when they're removed: on or off
#[arg(long)]
delete_from_devices: OnOff,
},
/// Move a vault from its plain Git remote onto the hub
Upload {
name: String,
@@ -150,6 +203,13 @@ enum HubCmd {
enum DeviceCmd {
/// Set the label shown on everything this device shares
Name { label: String },
/// Remove a device (e.g. a lost laptop): it hands over and leaves every vault, then its key stops working
Remove {
label: String,
/// Someone else's device (team owner)
#[arg(long)]
person: Option<String>,
},
}
#[derive(Subcommand)]
@@ -194,6 +254,12 @@ enum HeldCmd {
},
}
#[derive(Clone, Copy, ValueEnum)]
enum OnOff {
On,
Off,
}
#[derive(Clone, Copy, ValueEnum)]
enum KeepArg {
Mine,
@@ -236,6 +302,29 @@ fn run_cli(cli: Cli) -> Result<()> {
Command::Invite { person, vaults } => team::invite(&config, &person, &vaults)?,
Command::Grant { person, vault, role } => team::grant(&config, &person, &vault, &role)?,
Command::Members { vault } => team::members(&config, &vault)?,
Command::Remove { person, vault, without_saving } => team::remove(&config, &person, &vault, without_saving)?,
Command::Team { action: TeamCmd::Remove { person, yes } } => team::team_remove(&config, &person, yes)?,
Command::Team { action: TeamCmd::Restore { person } } => team::team_restore(&config, &person)?,
Command::Handovers => team::handovers(&config)?,
Command::Handover { action } => match action {
HandoverCmd::Show { id } => team::handover_show(&config, id)?,
HandoverCmd::Keep { id } => team::handover_decide(&config, id, "keep")?,
HandoverCmd::Discard { id } => team::handover_decide(&config, id, "discard")?,
HandoverCmd::Skip { id } => team::handover_decide(&config, id, "skip")?,
},
Command::Vault { action: VaultCmd::Set { name, delete_from_devices } } => {
team::link(&config)?.vault_setting(&name, matches!(delete_from_devices, OnOff::On))?;
let what = match delete_from_devices {
OnOff::On => "deleted from their devices",
OnOff::Off => "left on their devices, read-only",
};
println!("When someone is removed from {name}, their copy is {what}.");
}
Command::Device { action: Some(DeviceCmd::Remove { label, person }) } => {
team::link(&config)?.remove_device(&label, person.as_deref())?;
println!("\"{label}\" is removed. Next time it's online it hands over anything unshared and leaves every vault;");
println!("after that its key stops working. If it never comes back: `lunesync handovers`, then `handover skip <id>`.");
}
Command::Hub { action: HubCmd::Log { count } } => team::log(&config, count)?,
Command::Service { action: ServiceCmd::Install { print } } => service::install(print)?,
Command::Service { action: ServiceCmd::Uninstall } => service::uninstall()?,
@@ -496,6 +585,8 @@ fn run() -> Result<()> {
}
}
}
// A vault that left (access ended) can come back later at the same place.
started.retain(|p| config.vaults.iter().any(|v| &v.path == p));
for cfg in &config.vaults {
if !started.insert(cfg.path.clone()) {
continue;

View File

@@ -6,7 +6,7 @@ use lune_core::config::{Config, VaultConfig};
use lune_core::hub::{self, HubLink};
use lune_core::remote;
use lune_core::state;
use lune_core::vault::{self, Vault};
use lune_core::vault::Vault;
use std::path::PathBuf;
pub fn link(config: &Config) -> Result<&HubLink> {
@@ -53,49 +53,7 @@ pub fn pair(config: &Config) -> Result<()> {
Ok(())
}
/// Brings this device in line with its hub memberships: new vaults arrive, same-named local vaults
/// move onto the hub, roles are refreshed. Returns what happened, in plain words.
pub fn arrive(config: &mut Config) -> Result<Vec<String>> {
let Some(h) = config.hub.clone() else { return Ok(vec![]) };
let me = h.me()?;
let label = config.device_label();
let mut said = vec![];
for hv in me.vaults {
if let Some(vc) = config.vaults.iter().find(|v| v.hub_vault == Some(hv.id)) {
let v = Vault::open(vc, &label)?;
state::write_role(&v.git_dir, &hv.role)?;
continue;
}
if let Some(vc) = config.vaults.iter_mut().find(|v| v.hub_vault.is_none() && v.name.eq_ignore_ascii_case(&hv.name)) {
let v = Vault::open(vc, &label)?;
let _op = state::op_lock(&v.git_dir)?;
v.relink(&hv.git_url)?;
state::write_role(&v.git_dir, &hv.role)?;
v.join_unrelated()?;
vc.remote = hv.git_url.clone();
vc.hub_vault = Some(hv.id);
config.save()?;
said.push(format!("{} now syncs through the hub", hv.name));
continue;
}
let path = config.vaults_dir().join(&hv.name);
if path.exists() && std::fs::read_dir(&path)?.next().is_some() && !path.join(".git").exists() {
said.push(format!("{} can't arrive: {} already has other files in it", hv.name, path.display()));
continue;
}
let (mut cfg, _, err) = vault::add(&hv.name, &path, &hv.git_url, &label)?;
cfg.hub_vault = Some(hv.id);
state::write_role(&path.join(".git"), &hv.role)?;
config.vaults.push(cfg);
config.save()?;
let note = if hub::can_edit(&hv.role) { String::new() } else { " (read access)".into() };
said.push(format!("{} arrived in {}{note}", hv.name, path.display()));
if let Some(e) = err {
said.push(format!(" not synced yet: {e}"));
}
}
Ok(said)
}
pub use lune_core::membership::arrive;
pub fn vault_new(config: &mut Config, name: &str) -> Result<()> {
let hv = link(config)?.create_vault(name)?;
@@ -190,3 +148,74 @@ pub fn log(config: &Config, count: usize) -> Result<()> {
}
Ok(())
}
pub fn remove(config: &Config, person: &str, vault: &str, without_saving: bool) -> Result<()> {
let n = link(config)?.remove(person, vault, without_saving)?;
println!("{person} no longer has access to {vault}. Their other vaults are untouched.");
match (n, without_saving) {
(0, _) => println!("They had no devices to clean up."),
(n, false) => println!(
"{n} device(s) will hand over anything unshared (see `lunesync handovers`), then delete their copy."
),
(n, true) => println!("{n} device(s) will delete their copy without sending anything."),
}
println!("Copies made elsewhere, or already given to other tools, can't be recalled.");
Ok(())
}
pub fn team_remove(config: &Config, person: &str, yes: bool) -> Result<()> {
if !yes {
println!("This ends every vault and device {person} has, and disables their account (it can be restored).");
print!("Type their name to confirm: ");
std::io::Write::flush(&mut std::io::stdout())?;
let mut answer = String::new();
std::io::stdin().read_line(&mut answer)?;
if !answer.trim().eq_ignore_ascii_case(person) {
bail!("not confirmed — nothing changed");
}
}
link(config)?.team_remove(person)?;
println!("{person} is removed from the team. Their devices hand over anything unshared, delete their copies, and stop working.");
println!("History keeps their name. Copies made elsewhere can't be recalled.");
Ok(())
}
pub fn team_restore(config: &Config, person: &str) -> Result<()> {
let link = link(config)?.team_restore(person)?;
println!("{person} is back on the team, with no vaults yet (`lunesync grant`). Send them this one-time link:\n");
println!(" lunesync join {link} --name <their device>");
Ok(())
}
pub fn handovers(config: &Config) -> Result<()> {
let list = link(config)?.handovers()?;
if list.is_empty() {
println!("No handovers.");
}
for h in list {
let at = Local.timestamp_opt(h.at, 0).single().map(|t| t.format("%Y-%m-%d %H:%M").to_string()).unwrap_or_default();
let state = match h.state.as_str() {
"waiting" => "waiting for the device to come online",
"received" => "TO REVIEW — `lunesync handover show|keep|discard`",
"kept" => "kept",
"discarded" => "discarded",
"skipped" => "deleted without saving",
_ => "nothing was unshared",
};
println!("{:>4} {at} {:<10} {} ({}) {state}", h.id, h.vault, h.person, h.device);
}
Ok(())
}
pub fn handover_show(config: &Config, id: i64) -> Result<()> {
for line in link(config)?.handover_show(id)? {
println!(" {line}");
}
println!("Bring it in with `lunesync handover keep {id}`, or drop it with `lunesync handover discard {id}`.");
Ok(())
}
pub fn handover_decide(config: &Config, id: i64, decision: &str) -> Result<()> {
println!("{}", link(config)?.handover_decide(id, decision)?);
Ok(())
}