chiark / gitweb /
wip new account etc., adding acctid etc.
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 25 Oct 2020 11:23:51 +0000 (11:23 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 25 Oct 2020 11:23:51 +0000 (11:23 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/cmdlistener.rs
src/commands.rs

index 197b9822cdc6c66d7891eba83f606278ca35807d..07a6db599be2671c28518a5dc83d57e9f4f42592 100644 (file)
@@ -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<T>(spec: Option<T>, 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)?;
index 6eb1a25338d455f5e6613669a305a5cf995fce1e..a3ff0ad0522242d6fe0a196aaa624cc7c5f54adb 100644 (file)
@@ -38,7 +38,7 @@ pub enum MgmtCommand {
 #[derive(Debug,Serialize,Deserialize)]
 pub struct AccountDetails {
   pub account: AccountName,
-  pub nick: String,
+  pub nick: Option<String>,
   pub timezone: Option<String>,
   #[serde(flatten)]
   pub access: Option<Box<dyn PlayerAccessSpec>>,