[ledger] Household: profile.named, household.sharing_set, member.named, subscriptions.shared; shared_names sends only service keys; v0.3.0

This commit is contained in:
2026-11-04 16:17:14 +01:00
parent 11a4070151
commit 235f290412
8 changed files with 212 additions and 5 deletions
+46
View File
@@ -171,6 +171,10 @@ pub struct State {
/// SHA-256 (hex) of a share link's token → the link.
pub share_links: BTreeMap<String, ShareLink>,
pub account: Option<Account>,
/// The name shown to the members of my shared budgets (`profile.named`).
pub profile_name: Option<String>,
/// The shared budgets I share my subscription names with (`household.sharing_set`).
pub household_sharing: BTreeSet<BudgetId>,
pub rejected: Vec<Rejection>,
}
@@ -208,6 +212,10 @@ pub struct EffectivePayment {
pub trial_ends: Option<Date>,
}
/// A person's name, or one shared subscription name.
const MAX_PERSON: usize = 40;
const MAX_SHARED_NAMES: usize = 100;
fn text_ok(s: &str) -> bool {
s.chars().count() <= MAX_TEXT && !s.chars().any(|c| c.is_control())
}
@@ -586,6 +594,44 @@ impl State {
}
self.account = Some(Account { iban: iban.as_str().into(), name: name.trim().into() });
}
EventBody::ProfileNamed { name } => {
if !name_ok(name, MAX_PERSON) {
return Err("a name must be 1-40 characters");
}
self.profile_name = Some(name.trim().into());
}
EventBody::HouseholdSharingSet { budget, on } => {
if !self.budgets.contains_key(budget) || self.default_budget.as_ref() == Some(budget) {
return Err("subscription names are shared only with a shared budget");
}
if *on {
self.household_sharing.insert(budget.clone());
} else {
self.household_sharing.remove(budget);
}
}
EventBody::MemberNamed { budget, name } => {
if !self.budgets.contains_key(budget) {
return Err("no such budget");
}
if !name_ok(name, MAX_PERSON) {
return Err("a name must be 1-40 characters");
}
}
EventBody::SubscriptionsShared { budget, names } => {
if !self.budgets.contains_key(budget) {
return Err("no such budget");
}
if names.len() > MAX_SHARED_NAMES {
return Err("at most 100 subscription names");
}
if names.iter().any(|n| !name_ok(n, MAX_PERSON) || n.trim() != n) {
return Err("a subscription name must be 1-40 characters");
}
if names.iter().collect::<BTreeSet<_>>().len() != names.len() {
return Err("a subscription name appears twice");
}
}
}
Ok(())
}