diff --git a/plugins/setting-resources/src/components/MailboxEditorModal.svelte b/plugins/setting-resources/src/components/MailboxEditorModal.svelte index b00be1de53..fd8f803c4e 100644 --- a/plugins/setting-resources/src/components/MailboxEditorModal.svelte +++ b/plugins/setting-resources/src/components/MailboxEditorModal.svelte @@ -20,8 +20,8 @@ import { createEventDispatcher } from 'svelte' import { getAccountClient } from '../utils' import { IntlString, translateCB } from '@hcengineering/platform' - import contact, { getCurrentEmployee, SocialIdentity } from '@hcengineering/contact' - import { buildSocialIdString, Ref, SocialIdType } from '@hcengineering/core' + import contact, { getCurrentEmployee, SocialIdentityRef } from '@hcengineering/contact' + import { buildSocialIdString, SocialIdType } from '@hcengineering/core' export let mailboxOptions: MailboxOptions @@ -58,7 +58,7 @@ value: mailbox, verifiedOn: Date.now() }, - socialId as any as Ref + socialId as SocialIdentityRef ) await client.addCollection( contact.class.Channel, diff --git a/server/account/src/collections/postgres.ts b/server/account/src/collections/postgres.ts index c098a9d73b..f4109d8565 100644 --- a/server/account/src/collections/postgres.ts +++ b/server/account/src/collections/postgres.ts @@ -645,7 +645,8 @@ export class PostgresAccountDB implements AccountDB { this.getV2Migration3(), this.getV3Migration(), this.getV4Migration(), - this.getV4Migration1() + this.getV4Migration1(), + this.getV5Migration() ] } @@ -890,4 +891,14 @@ export class PostgresAccountDB implements AccountDB { ` ] } + + private getV5Migration (): [string, string] { + return [ + 'account_db_v5_social_id_is_deleted', + ` + ALTER TABLE ${this.ns}.social_id + ADD COLUMN IF NOT EXISTS is_deleted BOOL NOT NULL DEFAULT FALSE; + ` + ] + } } diff --git a/server/account/src/operations.ts b/server/account/src/operations.ts index 34c06b4adf..50f9b1e395 100644 --- a/server/account/src/operations.ts +++ b/server/account/src/operations.ts @@ -102,7 +102,8 @@ import { normalizeValue, isEmail, generatePassword, - addSocialId + addSocialId, + releaseSocialId } from './utils' // Move to config? @@ -2063,12 +2064,7 @@ async function createMailbox ( await db.mailbox.insertOne({ accountUuid: account, mailbox }) await db.mailboxSecret.insertOne({ mailbox, secret: generatePassword() }) - const socialId: PersonId = await db.socialId.insertOne({ - personUuid: account, - type: SocialIdType.EMAIL, - value: mailbox, - verifiedOn: Date.now() - }) + const socialId = await addSocialId(db, account, SocialIdType.EMAIL, mailbox, true) ctx.info('Mailbox created', { mailbox, account, socialId }) return { mailbox, socialId } } @@ -2123,18 +2119,6 @@ export async function addSocialIdToPerson ( return await addSocialId(db, person, type, value, confirmed) } -async function releaseSocialId ( - db: AccountDB, - personUuid: PersonUuid, - type: SocialIdType, - value: string -): Promise { - const socialIds = await db.socialId.find({ personUuid, type, value }) - for (const socialId of socialIds) { - await db.socialId.updateOne({ _id: socialId._id }, { value: `${socialId.value}#${socialId._id}` }) - } -} - export type AccountMethods = | 'login' | 'loginOtp' diff --git a/server/account/src/types.ts b/server/account/src/types.ts index 2823c8265d..7a28bbe42f 100644 --- a/server/account/src/types.ts +++ b/server/account/src/types.ts @@ -46,6 +46,7 @@ export interface SocialId extends SocialIdBase { personUuid: PersonUuid createdOn?: Timestamp verifiedOn?: Timestamp + isDeleted?: boolean } export interface Account { diff --git a/server/account/src/utils.ts b/server/account/src/utils.ts index fbcd0f3ae2..31e4664b7d 100644 --- a/server/account/src/utils.ts +++ b/server/account/src/utils.ts @@ -1310,6 +1310,18 @@ export async function addSocialId ( return await db.socialId.insertOne(newSocialId) } +export async function releaseSocialId ( + db: AccountDB, + personUuid: PersonUuid, + type: SocialIdType, + value: string +): Promise { + const socialIds = await db.socialId.find({ personUuid, type, value }) + for (const socialId of socialIds) { + await db.socialId.updateOne({ _id: socialId._id }, { value: `${socialId.value}#${socialId._id}`, isDeleted: true }) + } +} + export async function getWorkspaceRole ( db: AccountDB, account: PersonUuid, diff --git a/services/mail/pod-inbound-mail/src/person.ts b/services/mail/pod-inbound-mail/src/person.ts index 8399224ef6..0123df5a40 100644 --- a/services/mail/pod-inbound-mail/src/person.ts +++ b/services/mail/pod-inbound-mail/src/person.ts @@ -18,11 +18,10 @@ import { generateId, PersonId, PersonUuid, - Ref, SocialIdType, TxOperations } from '@hcengineering/core' -import contact, { AvatarType, combineName, SocialIdentity } from '@hcengineering/contact' +import contact, { AvatarType, combineName, SocialIdentityRef } from '@hcengineering/contact' import { AccountClient } from '@hcengineering/account-client' export async function ensureGlobalPerson ( @@ -100,7 +99,7 @@ export async function ensureLocalPerson ( type: SocialIdType.EMAIL, value: email }, - personId as any as Ref + personId as SocialIdentityRef ) ctx.info('Created local socialId', { mailId, personUuid, email }) }