Fix account update method for unasaved accounts

If the account passed to `saved_accounts.update()` doesn't exist in the
config file, return instead of failing with a KeyError.

An account can be absent from the file if "Remember my account" was
unchecked on login, or if the file hasn't been updated yet on disk after
login (race condition).
This commit is contained in:
miruka 2020-07-11 17:11:04 -04:00
parent 3daa60510a
commit 2644e6d8b0
2 changed files with 6 additions and 1 deletions

View File

@ -1,5 +1,7 @@
# TODO # TODO
- fix device section headers when members pane is small
- when promiting someone in room as admin, rank isn't updated in members list
- save and restore status in accounts.json - save and restore status in accounts.json
- mark accounts as offline when closing mirage - mark accounts as offline when closing mirage
- document new x11 dependnecy (auto-idle) - document new x11 dependnecy (auto-idle)

View File

@ -206,10 +206,13 @@ class Accounts(JSONDataFile):
presence: Optional[str] = None, presence: Optional[str] = None,
order: Optional[int] = None, order: Optional[int] = None,
) -> None: ) -> None:
"""Update existing account in the config and write to disk.""" """Update an account if found in the config file and write to disk."""
saved = await self.read() saved = await self.read()
if user_id not in saved:
return
if enabled is not None: if enabled is not None:
saved[user_id]["enabled"] = enabled saved[user_id]["enabled"] = enabled