[Fixes: #11579] Add only certain fields to multiaccount on login

`multiaccounts` has some fields that should not be overriden
(`save-password`), so we expliciltly `assoc` only certain fields.

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
Andrea Maria Piana 2020-12-28 12:30:50 +01:00
parent 37ccc6f825
commit 6099262c98
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
3 changed files with 26 additions and 6 deletions

View File

@ -139,13 +139,17 @@
(handlers/register-handler-fx
:multiaccounts.login.ui/multiaccount-selected
(fn [{:keys [db] :as cofx} [_ key-uid]]
(let [multiaccount (get-in db [:multiaccounts/multiaccounts key-uid])]
;; We specifically pass a bunch of fields instead of the whole multiaccount
;; as we want store some fields in multiaccount that are not here
(let [multiaccount
(get-in db [:multiaccounts/multiaccounts key-uid])]
(fx/merge
cofx
{:db (-> db
(dissoc :intro-wizard)
(update :keycard dissoc :application-info))}
(multiaccounts.login/open-login multiaccount)))))
(multiaccounts.login/open-login
(select-keys multiaccount [:key-uid :name :public-key :identicon :images]))))))
(handlers/register-handler-fx
:login/filters-initialized

View File

@ -27,8 +27,13 @@
[cofx {:keys [logout?]}]
(let [{{:multiaccounts/keys [multiaccounts]} :db} cofx]
(when (and (seq multiaccounts) (not logout?))
;; We specifically pass a bunch of fields instead of the whole multiaccount
;; as we want store some fields in multiaccount that are not here
(let [multiaccount (first (sort-by :timestamp > (vals multiaccounts)))]
(multiaccounts.login/open-login cofx multiaccount)))))
(multiaccounts.login/open-login cofx
(select-keys
multiaccount
[:key-uid :name :public-key :identicon :images]))))))
(fx/defn initialize-multiaccounts
{:events [::initialize-multiaccounts]}

View File

@ -342,11 +342,22 @@
;; FIXME(Ferossgp): We should not copy keys as we denormalize the database,
;; this create desync between actual accounts and the one on login causing broken state
;; UPDATE(cammellos): This code is copying over some fields explicitly as some values
;; are alreayd in `multiaccounts/login` and should not be overriden, as they come from
;; the keychain (save-password), this is not very explicit and we should probably
;; make it clearer
(fx/defn open-login
[{:keys [db] :as cofx} {:keys [key-uid] :as multiaccount}]
[{:keys [db] :as cofx} override-multiaccount]
(fx/merge cofx
{:db (assoc db :multiaccounts/login multiaccount)}
(keychain/get-auth-method key-uid)))
{:db (-> db
(update :multiaccounts/login
merge
override-multiaccount)
(update :multiaccounts/login
dissoc
:error
:password))}
(keychain/get-auth-method (:key-uid override-multiaccount))))
(fx/defn open-login-callback
{:events [:multiaccounts.login.callback/get-user-password-success]}