A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
core: move user profile to settings collection
Abdullah Attad32db74ccc94
diff --git a/packages/core/src/api/user-manager.ts b/packages/core/src/api/user-manager.tsindex 528c9a283..effeb544c 100644--- a/packages/core/src/api/user-manager.ts+++ b/packages/core/src/api/user-manager.ts@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public Licensealong with this program. If not, see <http://www.gnu.org/licenses/>.*/-import { User, Profile } from "../types";+import { User } from "../types";import http from "../utils/http";import constants from "../utils/constants";import TokenManager from "./token-manager";@@ -275,38 +275,18 @@ class UserManager {return true;}- private async updateUser(user: User) {+ private async updateUser(partial: Partial<User>) {+ const user = await this.getUser();+ if (!user) return;+const token = await this.tokenManager.getAccessToken();await http.patch.json(`${constants.API_HOST}${ENDPOINTS.user}`,- user,+ partial,token);- await this.setUser(user);- }-- async setProfile(profile: Partial<Profile>) {- const user = await this.getUser();- const key = await this.getEncryptionKey();- const userProfile = await this.getProfile();- if (!user || !key) return;-- user.profile = await this.db- .storage()- .encrypt(key, JSON.stringify({ ...userProfile, ...profile }));- await this.updateUser(user);- }-- async getProfile() {- const user = await this.getUser();- const key = await this.getEncryptionKey();- if (!user || !key || !user.profile) return;-- const profile = JSON.parse(- await this.db.storage().decrypt(key, user.profile)- );- return profile as Profile;+ await this.setUser({ ...user, ...partial });}async deleteUser(password: string) {@@ -410,7 +390,7 @@ class UserManager {.storage().encrypt(userEncryptionKey, JSON.stringify(key));- await this.updateUser(user);+ await this.updateUser({ attachmentsKey: user.attachmentsKey });return key;}@@ -527,7 +507,7 @@ class UserManager {user.attachmentsKey = await this.db.storage().encrypt(userEncryptionKey, JSON.stringify(attachmentsKey));- await this.updateUser(user);+ await this.updateUser({ attachmentsKey: user.attachmentsKey });}if (old_password)diff --git a/packages/core/src/collections/settings.ts b/packages/core/src/collections/settings.tsindex 136e83407..9131d4a44 100644--- a/packages/core/src/collections/settings.ts+++ b/packages/core/src/collections/settings.ts@@ -22,6 +22,7 @@ import Database from "../api";import {GroupOptions,GroupingKey,+ Profile,SettingItem,SettingItemMap,SideBarHideableSection,@@ -54,6 +55,7 @@ const defaultSettings: SettingItemMap = {titleFormat: "Note $date$ $time$",defaultNotebook: undefined,trashCleanupInterval: 7,+ profile: undefined,"groupOptions:trash": DEFAULT_GROUP_OPTIONS("trash"),"groupOptions:tags": DEFAULT_GROUP_OPTIONS("tags"),@@ -195,4 +197,16 @@ export class Settings implements ICollection {setSideBarHiddenItems(section: SideBarHideableSection, ids: string[]) {return this.set(`sideBarHiddenItems:${section}`, ids);}++ getProfile() {+ return this.get("profile");+ }++ setProfile(partial: Partial<Profile> | undefined) {+ const profile =+ partial === undefined || (!partial.fullName && !partial.profilePicture)+ ? undefined+ : { ...this.getProfile(), ...partial };+ return this.set("profile", profile);+ }}diff --git a/packages/core/src/database/index.ts b/packages/core/src/database/index.tsindex 62df0ad48..13b33a461 100644--- a/packages/core/src/database/index.ts+++ b/packages/core/src/database/index.ts@@ -235,7 +235,8 @@ const DataMappers: Partial<Record<ItemType, (row: any) => void>> = {(row.key.startsWith("groupOptions") ||row.key.startsWith("toolbarConfig") ||row.key.startsWith("sideBarOrder") ||- row.key.startsWith("sideBarHiddenItems"))+ row.key.startsWith("sideBarHiddenItems") ||+ row.key.startsWith("profile")))row.value = JSON.parse(row.value);},diff --git a/packages/core/src/types.ts b/packages/core/src/types.tsindex 9ab215cce..b2e0d4d15 100644--- a/packages/core/src/types.ts+++ b/packages/core/src/types.ts@@ -456,6 +456,7 @@ export type SettingItemMap = {timeFormat: TimeFormat;dateFormat: string;defaultNotebook: string | undefined;+ profile: Profile | undefined;} & Record<`groupOptions:${GroupingKey}`, GroupOptions> &Record<`toolbarConfig:${ToolbarConfigPlatforms}`, ToolbarConfig | undefined> &Record<`sideBarOrder:${SideBarSection}`, string[]> &@@ -515,7 +516,6 @@ export type User = {isEmailConfirmed: boolean;salt: string;attachmentsKey?: Cipher<"base64">;- profile?: Cipher<"base64">;marketingConsent?: boolean;mfa: {isEnabled: boolean;