0.1.3: upload a vault to a team from the app, detach first; AGPL-3.0
- The Lune window shows Upload on a vault that isn't on a team, for the team owner and anyone who manages a vault there. The hub now lets those people create vaults too (was owner only); /api/me and the canvas say can_create. - A vault on its own remote (GitHub, GitLab, Gitea…) must be detached first (`lunesync vault detach`, or the Upload sheet's Detach): it shares what's waiting one last time, then lives on this device only. Upload refuses anything else, and a check-in no longer silently moves a same-named vault off its own remote onto the hub. - Upload logic moved from the CLI into core (lune_core::upload). - Canvas: "1 person loses access". - License: AGPL-3.0-only. README and SPEC §8 updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
[package]
|
||||
name = "lunesync"
|
||||
version.workspace = true
|
||||
license.workspace = true
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -196,7 +196,9 @@ enum VaultCmd {
|
||||
#[arg(long)]
|
||||
yes: bool,
|
||||
},
|
||||
/// Move a vault from its plain Git remote onto the hub
|
||||
/// Stop syncing a vault with its own remote (GitHub, GitLab…): it stays on this device only, ready to upload
|
||||
Detach { name: String },
|
||||
/// Move a vault that's only on this device onto the hub (detach it from any other remote first)
|
||||
Upload {
|
||||
name: String,
|
||||
/// Upload only the current notes, not the earlier history
|
||||
@@ -331,6 +333,7 @@ fn run_cli(cli: Cli) -> Result<()> {
|
||||
}
|
||||
Command::Vault { action: VaultCmd::New { name } } => team::vault_new(&mut config, &name)?,
|
||||
Command::Vault { action: VaultCmd::Upload { name, fresh } } => team::vault_upload(&mut config, &name, fresh)?,
|
||||
Command::Vault { action: VaultCmd::Detach { name } } => team::vault_detach(&mut config, &name)?,
|
||||
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)?,
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
//! Hub commands: joining, pairing devices, vaults on the hub, invites, grants, members and the access log.
|
||||
|
||||
use anyhow::{Context, Result, bail};
|
||||
use anyhow::{Result, bail};
|
||||
use chrono::{Local, TimeZone};
|
||||
use lune_core::config::{Config, VaultConfig};
|
||||
use lune_core::config::Config;
|
||||
use lune_core::hub::{self, HubLink};
|
||||
use lune_core::remote;
|
||||
use lune_core::state;
|
||||
use lune_core::vault::Vault;
|
||||
use std::path::PathBuf;
|
||||
|
||||
static TEAM: std::sync::OnceLock<Option<String>> = std::sync::OnceLock::new();
|
||||
@@ -76,53 +73,24 @@ pub fn vault_new(config: &mut Config, name: &str) -> Result<()> {
|
||||
/// Moves a vault that syncs through a plain Git remote onto the hub.
|
||||
pub fn vault_upload(config: &mut Config, name: &str, fresh: bool) -> Result<()> {
|
||||
let h = link(config)?.clone();
|
||||
let label = config.device_label();
|
||||
let cfg: VaultConfig = config.find(name).with_context(|| format!("no vault named \"{name}\" on this device"))?.clone();
|
||||
if cfg.hub_vault.is_some() {
|
||||
bail!("{} already syncs through the hub", cfg.name);
|
||||
}
|
||||
let hv = match h.create_vault(&cfg.name) {
|
||||
Ok(hv) => hv,
|
||||
Err(e) if format!("{e}").contains("already a vault") => h
|
||||
.me()?
|
||||
.vaults
|
||||
.into_iter()
|
||||
.find(|v| v.name.eq_ignore_ascii_case(&cfg.name))
|
||||
.context("the hub has a vault with that name that you're not a member of")?,
|
||||
Err(e) => return Err(e),
|
||||
};
|
||||
let v = Vault::open(&cfg, &label)?;
|
||||
let _op = state::op_lock(&v.git_dir)?;
|
||||
v.save_changes(None, &Default::default())?;
|
||||
let before = if fresh { Some(v.fresh_start(&format!("Fresh start on the hub (earlier history stays on {label})"))?) } else { None };
|
||||
v.relink(&hv.git_url)?;
|
||||
state::write_role(&v.git_dir, &hv.role)?;
|
||||
let joined = v.join_unrelated();
|
||||
match joined.and_then(|_| v.sync()) {
|
||||
Ok(_) => {
|
||||
let vc = config.vaults.iter_mut().find(|x| x.path == cfg.path).unwrap();
|
||||
vc.remote = hv.git_url.clone();
|
||||
vc.hub_vault = Some(hv.id);
|
||||
vc.hub_url = Some(h.url.clone());
|
||||
config.save()?;
|
||||
println!("{} now syncs through the hub{}.", cfg.name, if fresh { ", starting fresh" } else { ", history included" });
|
||||
match lune_core::upload::upload(config, &h, name, fresh) {
|
||||
Ok(said) => {
|
||||
println!("{said}.");
|
||||
println!("Other devices with this vault: `lunesync pair` here, then `lunesync login …` there — it moves over on its own.");
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
v.relink(&cfg.remote)?;
|
||||
if let Some(id) = before {
|
||||
v.reset_history(id)?;
|
||||
}
|
||||
let why = remote::describe_error(&e);
|
||||
if why.contains("possible") && !fresh {
|
||||
bail!("{why}\nThe old history has a secret in it. `lunesync vault upload {name} --fresh` uploads just the current notes.");
|
||||
}
|
||||
bail!("{why}\n{} keeps syncing where it did before.", cfg.name)
|
||||
}
|
||||
Err(e) if format!("{e}").contains("A fresh start") => bail!("{e}\n`lunesync vault upload {name} --fresh` does that."),
|
||||
Err(e) if format!("{e}").contains("Detach it") => bail!("{e}: `lunesync vault detach {name}`."),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn vault_detach(config: &mut Config, name: &str) -> Result<()> {
|
||||
println!("{}.", lune_core::upload::detach(config, name)?);
|
||||
println!("Next: `lunesync vault upload {name}`. Other devices that sync it there should join the team for it instead.");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn invite(config: &Config, person: &str, vaults: &[String]) -> Result<()> {
|
||||
let grants: Vec<(String, String)> = vaults
|
||||
.iter()
|
||||
|
||||
Reference in New Issue
Block a user