Skip to content

Commit d881697

Browse files
committed
feat(settings): migrate local storage preferences to database
1 parent 10eb873 commit d881697

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

apps/settings/src/main-apps-users-management.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ sync(store, router)
3030

3131
const pinia = createPinia()
3232

33+
// Migrate legacy local storage settings to the database
34+
store.dispatch('migrateLocalStorage')
35+
36+
3337
export default new Vue({
3438
router,
3539
store,

apps/settings/src/store/users.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,42 @@ const actions = {
797797
.catch((error) => { throw error })
798798
}).catch((error) => context.commit('API_FAILURE', { userid, error }))
799799
},
800+
/**
801+
* Migrate local storage keys to database
802+
*
803+
* @param {object} context store context
804+
*/
805+
migrateLocalStorage({ commit }) {
806+
const preferences = {
807+
showStoragePath: 'user_list_show_storage_path',
808+
showUserBackend: 'user_list_show_user_backend',
809+
showFirstLogin: 'user_list_show_first_login',
810+
showLastLogin: 'user_list_show_last_login',
811+
showNewUserForm: 'user_list_show_new_user_form',
812+
showLanguages: 'user_list_show_languages',
813+
}
814+
815+
for (const [key, dbKey] of Object.entries(preferences)) {
816+
const localKey = `account_settings__${key}`
817+
const localValue = window.localStorage.getItem(localKey)
818+
if (localValue === null) {
819+
continue
820+
}
821+
822+
const value = localValue === 'true'
823+
commit('setShowConfig', { key, value })
824+
825+
axios.post(generateUrl(`/settings/users/preferences/${dbKey}`), {
826+
value: value ? 'true' : 'false',
827+
}).then(() => {
828+
window.localStorage.removeItem(localKey)
829+
}).catch((error) => {
830+
logger.error(`Failed to migrate preference ${key}`, { error })
831+
})
832+
}
833+
},
834+
835+
800836
/**
801837
* Set show config
802838
*

0 commit comments

Comments
 (0)