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:
117
cli/src/team.rs
117
cli/src/team.rs
@@ -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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user