From: Ian Jackson Date: Sun, 25 Oct 2020 11:23:51 +0000 (+0000) Subject: wip new account etc., adding acctid etc. X-Git-Tag: otter-0.2.0~594 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=d81a5b723a3bb0f1628304f4f837a9830d037b73;p=otter.git wip new account etc., adding acctid etc. Signed-off-by: Ian Jackson --- diff --git a/src/cmdlistener.rs b/src/cmdlistener.rs index 197b9822..07a6db59 100644 --- a/src/cmdlistener.rs +++ b/src/cmdlistener.rs @@ -91,9 +91,9 @@ fn execute(cs: &mut CommandStream, cmd: MgmtCommand) -> MgmtResponse { CreateAccont(AccountDetails { account, nick, timezone, access }) => { let auth = authorise_for_account(cs, &account)?; - let access = access - .map(Into::into) + let access = access.map(Into::into) .unwrap_or_else(|| Arc::new(PlayerAccessUnset) as Arc<_>); + let nick = nick.unwrap_or_else(|| account.to_string()); let record = AccountRecord { nick, access, timezone: timezone.unwrap_or_default(), @@ -102,20 +102,21 @@ fn execute(cs: &mut CommandStream, cmd: MgmtCommand) -> MgmtResponse { AccountRecord::insert_entry(account, auth, record)?; Fine } -/* + UpdateAccont(AccountDetails { account, nick, timezone, access }) => { let auth = authorise_for_account(cs, &account)?; - let access = access.map(Into::into); - - .unwrap_or_else(|| Arc::new(PlayerAccessUnset) as Arc<_>); - let record = AccountRecord { - nick, access, - timezone: timezone.unwrap_or_default(), - tokens_revealed: default(), - }; - AccountRecord::insert_entry(account, auth, record)?; - Fine - }*/ + AccountRecord::with_entry_mut(&account, auth, |record, acctid|{ + fn update_from(spec: Option, record: &mut T) { + if let Some(new) = spec { *record = new; } + } + update_from(nick, &mut record.nick ); + update_from(timezone, &mut record.timezone); + update_from(access.map(Into::into), &mut record.access ); + Fine + }) + ? + .map_err(|(e,_)|e) ? + } SetAccount(wanted_account) => { let auth = authorise_scope_direct(cs, &wanted_account.scope)?; diff --git a/src/commands.rs b/src/commands.rs index 6eb1a253..a3ff0ad0 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -38,7 +38,7 @@ pub enum MgmtCommand { #[derive(Debug,Serialize,Deserialize)] pub struct AccountDetails { pub account: AccountName, - pub nick: String, + pub nick: Option, pub timezone: Option, #[serde(flatten)] pub access: Option>,