diff --git a/models/contact/src/migration.ts b/models/contact/src/migration.ts index 0da0a3d6ec..7c7b06d940 100644 --- a/models/contact/src/migration.ts +++ b/models/contact/src/migration.ts @@ -101,6 +101,37 @@ async function setCreate (client: MigrationClient): Promise { } } +async function createEmployeeEmail (client: TxOperations): Promise { + const employees = await client.findAll(contact.class.Employee, {}) + const channels = await client.findAll(contact.class.Channel, { + provider: contact.channelProvider.Email, + attachedTo: { $in: employees.map((p) => p._id) } + }) + const channelsMap = new Map(channels.map((p) => [p.attachedTo, p])) + for (const employee of employees) { + const acc = await client.findOne(contact.class.EmployeeAccount, { employee: employee._id }) + if (acc === undefined) continue + const current = channelsMap.get(employee._id) + if (current === undefined) { + await client.addCollection( + contact.class.Channel, + contact.space.Contacts, + employee._id, + contact.class.Employee, + 'channels', + { + provider: contact.channelProvider.Email, + value: acc.email.trim() + }, + undefined, + employee.modifiedOn + ) + } else if (current.value !== acc.email.trim()) { + await client.update(current, { value: acc.email.trim() }, false, current.modifiedOn) + } + } +} + export const contactOperation: MigrateOperation = { async migrate (client: MigrationClient): Promise { await setCreate(client) @@ -108,5 +139,6 @@ export const contactOperation: MigrateOperation = { async upgrade (client: MigrationUpgradeClient): Promise { const tx = new TxOperations(client, core.account.System) await createSpace(tx) + await createEmployeeEmail(tx) } } diff --git a/plugins/bitrix/src/sync.ts b/plugins/bitrix/src/sync.ts index b267890c23..b70200afed 100644 --- a/plugins/bitrix/src/sync.ts +++ b/plugins/bitrix/src/sync.ts @@ -856,6 +856,19 @@ async function synchronizeUsers ( employee: employeeId, role: AccountRole.User }) + if (u.EMAIL !== undefined && u.EMAIL !== null) { + await ops.client.addCollection( + contact.class.Channel, + contact.space.Contacts, + employeeId, + contact.class.Employee, + 'channels', + { + provider: contact.channelProvider.Email, + value: u.EMAIL.trim() + } + ) + } await ops.client.createMixin( employeeId, contact.class.Employee, diff --git a/plugins/contact-resources/src/components/ChannelsDropdown.svelte b/plugins/contact-resources/src/components/ChannelsDropdown.svelte index e8f22e3372..d7451441b9 100644 --- a/plugins/contact-resources/src/components/ChannelsDropdown.svelte +++ b/plugins/contact-resources/src/components/ChannelsDropdown.svelte @@ -47,6 +47,7 @@ export let shape: 'circle' | undefined = undefined export let integrations: Set> = new Set>() export let focusIndex = -1 + export let restricted: Ref[] = [] const notificationClient = NotificationClientImpl.getClient() const lastViews = notificationClient.getLastViews() @@ -263,7 +264,7 @@ {shape} highlight={item.integration || item.notification} on:click={(ev) => { - if (editable) { + if (editable && !restricted.includes(item.provider)) { closeTooltip() editChannel(eventToHTMLElement(ev), i, item) } else { diff --git a/plugins/contact-resources/src/components/ChannelsEditor.svelte b/plugins/contact-resources/src/components/ChannelsEditor.svelte index 2e998d5364..dddefee1c7 100644 --- a/plugins/contact-resources/src/components/ChannelsEditor.svelte +++ b/plugins/contact-resources/src/components/ChannelsEditor.svelte @@ -34,6 +34,7 @@ export let size: ButtonSize = 'small' export let length: 'short' | 'full' = 'full' export let shape: 'circle' | undefined = 'circle' + export let restricted: Ref[] = [] let channels: Channel[] = [] @@ -123,6 +124,7 @@ {length} {integrations} {editable} + {restricted} {shape} {focusIndex} on:change={(e) => { diff --git a/plugins/contact-resources/src/components/CreateEmployee.svelte b/plugins/contact-resources/src/components/CreateEmployee.svelte index 8c3a439d6f..85903a78e6 100644 --- a/plugins/contact-resources/src/components/CreateEmployee.svelte +++ b/plugins/contact-resources/src/components/CreateEmployee.svelte @@ -40,6 +40,7 @@ const client = getClient() async function createPerson () { + changeEmail() const name = combineName(firstName, lastName) const person: Data = { createOn: Date.now(), @@ -68,7 +69,12 @@ dispatch('close') } - let channels: AttachedData[] = [] + let channels: AttachedData[] = [ + { + provider: contact.channelProvider.Email, + value: '' + } + ] let matches: Person[] = [] $: findPerson(client, { ...object, name: combineName(firstName, lastName) }, channels).then((p) => { @@ -76,6 +82,19 @@ }) const manager = createFocusManager() + + function changeEmail () { + const index = channels.findIndex((p) => p.provider === contact.channelProvider.Email) + if (index !== -1) { + channels[index].value = email.trim() + } else { + channels.push({ + provider: contact.channelProvider.Email, + value: email.trim() + }) + } + channels = channels + } @@ -115,7 +134,13 @@ focusIndex={2} />
- +
@@ -123,6 +148,12 @@
- + diff --git a/plugins/setting-resources/src/components/Profile.svelte b/plugins/setting-resources/src/components/Profile.svelte index a444d82e41..272a8bcf8e 100644 --- a/plugins/setting-resources/src/components/Profile.svelte +++ b/plugins/setting-resources/src/components/Profile.svelte @@ -128,7 +128,13 @@ />
- +
{/if} diff --git a/server/account/src/index.ts b/server/account/src/index.ts index 15083b6c9b..0dee5bebf7 100644 --- a/server/account/src/index.ts +++ b/server/account/src/index.ts @@ -583,12 +583,16 @@ async function createEmployee (ops: TxOperations, name: string, email: string): avatar: `${AvatarType.COLOR}://${getAvatarColorForId(id)}` }) } + await ops.addCollection(contact.class.Channel, contact.space.Contacts, id, contact.class.Employee, 'channels', { + provider: contact.channelProvider.Email, + value: email.trim() + }) return id } async function createEmployeeAccount (account: Account, productId: string, workspace: string): Promise { - const connection = await connect(getTransactor(), getWorkspaceId(workspace, productId), account.email) + const connection = await connect(getTransactor(), getWorkspaceId(workspace, productId)) try { const ops = new TxOperations(connection, core.account.System) diff --git a/server/middleware/src/modified.ts b/server/middleware/src/modified.ts index afc8d5aeb9..add0efcba5 100644 --- a/server/middleware/src/modified.ts +++ b/server/middleware/src/modified.ts @@ -39,24 +39,26 @@ export class ModifiedMiddleware extends BaseMiddleware implements Middleware { } async tx (ctx: SessionContext, tx: Tx): Promise { - tx.modifiedOn = Date.now() - if (this.storage.hierarchy.isDerived(tx._class, core.class.TxCreateDoc)) { - const createTx = tx as TxCreateDoc - const hasCreateOn = this.storage.hierarchy.findAttribute(createTx.objectClass, 'createOn') - if (hasCreateOn !== undefined) { - createTx.attributes.createOn = tx.modifiedOn - } - } - if (this.storage.hierarchy.isDerived(tx._class, core.class.TxCollectionCUD)) { - const coltx = tx as TxCollectionCUD - coltx.tx.modifiedOn = tx.modifiedOn - if (this.storage.hierarchy.isDerived(coltx.tx._class, core.class.TxCreateDoc)) { - const createTx = coltx.tx as TxCreateDoc + if (tx.modifiedBy !== core.account.System) { + tx.modifiedOn = Date.now() + if (this.storage.hierarchy.isDerived(tx._class, core.class.TxCreateDoc)) { + const createTx = tx as TxCreateDoc const hasCreateOn = this.storage.hierarchy.findAttribute(createTx.objectClass, 'createOn') if (hasCreateOn !== undefined) { createTx.attributes.createOn = tx.modifiedOn } } + if (this.storage.hierarchy.isDerived(tx._class, core.class.TxCollectionCUD)) { + const coltx = tx as TxCollectionCUD + coltx.tx.modifiedOn = tx.modifiedOn + if (this.storage.hierarchy.isDerived(coltx.tx._class, core.class.TxCreateDoc)) { + const createTx = coltx.tx as TxCreateDoc + const hasCreateOn = this.storage.hierarchy.findAttribute(createTx.objectClass, 'createOn') + if (hasCreateOn !== undefined) { + createTx.attributes.createOn = tx.modifiedOn + } + } + } } return await this.provideTx(ctx, tx) } diff --git a/tests/sanity/tests/settings.spec.ts b/tests/sanity/tests/settings.spec.ts index 25f42601fb..40b9f04cf0 100644 --- a/tests/sanity/tests/settings.spec.ts +++ b/tests/sanity/tests/settings.spec.ts @@ -25,14 +25,13 @@ test.describe('contact tests', () => { await page.fill('[placeholder="Location"]', 'LoPlaza') // Click .flex-center.icon-button - if ((await page.locator('[id="gmail:string:Email"]').count()) === 0) { + if ((await page.locator('[id="contact:string:Phone"]').count()) === 0) { await page.click('[id="presentation:string:AddSocialLinks"]') - await page.click('.popup button:has-text("Email")') + await page.click('.popup button:has-text("Phone")') } else { - await page.click('id=gmail:string:Email') + await page.click('id=contact:string:Phone') } - // await page.hover('[id="gmail:string:Email"]') - await page.fill('[placeholder="john\\.appleseed\\@apple\\.com"]', 'wer@qwe.com') + await page.fill('[placeholder="+1 555 333 7777"]', '+1 555 333 7777') // Click text=Apply await page.click('.editor-container button:nth-child(3)') })