diff --git a/models/server-calendar/src/index.ts b/models/server-calendar/src/index.ts index 814283bb25..e5b27f09e0 100644 --- a/models/server-calendar/src/index.ts +++ b/models/server-calendar/src/index.ts @@ -33,14 +33,6 @@ export function createModel (builder: Builder): void { presenter: serverCalendar.function.ReminderTextPresenter }) - builder.createDoc(serverCore.class.Trigger, core.space.Model, { - trigger: serverCalendar.trigger.OnSocialIdentityCreate, - txMatch: { - _class: core.class.TxCreateDoc, - objectClass: contact.class.SocialIdentity - } - }) - builder.createDoc(serverCore.class.Trigger, core.space.Model, { trigger: serverCalendar.trigger.OnEmployee, txMatch: { diff --git a/server-plugins/calendar-resources/src/index.ts b/server-plugins/calendar-resources/src/index.ts index 348ca15173..267b0edf61 100644 --- a/server-plugins/calendar-resources/src/index.ts +++ b/server-plugins/calendar-resources/src/index.ts @@ -13,7 +13,7 @@ // limitations under the License. // import calendar, { Calendar, Event, ExternalCalendar } from '@hcengineering/calendar' -import contactPlugin, { Employee, Person, SocialIdentity } from '@hcengineering/contact' +import contactPlugin, { Employee, Person } from '@hcengineering/contact' import core, { Class, concatLink, @@ -117,25 +117,6 @@ export async function OnEmployee (txes: Tx[], control: TriggerControl): Promise< return result } -export async function OnSocialIdentityCreate (txes: Tx[], control: TriggerControl): Promise { - const result: Tx[] = [] - for (const tx of txes) { - const ctx = tx as TxCUD - if (ctx._class !== core.class.TxCreateDoc) continue - - const socialId = TxProcessor.createDoc2Doc(ctx as TxCreateDoc) - const employee = ( - await control.findAll(control.ctx, contactPlugin.mixin.Employee, { _id: socialId.attachedTo as Ref }) - )[0] - if (employee === undefined || !employee.active || employee.personUuid === undefined) continue - - if (await checkCalendarsExist(control, employee._id)) continue - - result.push(...(await createCalendar(control, employee.personUuid, socialId._id, socialId.value))) - } - return result -} - async function checkCalendarsExist (control: TriggerControl, person: Ref): Promise { const socialStrings = await getSocialStrings(control, person) const calendars = await control.findAll( @@ -445,7 +426,6 @@ export default async () => ({ FindReminders }, trigger: { - OnSocialIdentityCreate, OnEmployee, OnEvent } diff --git a/server-plugins/calendar/src/index.ts b/server-plugins/calendar/src/index.ts index 2cfde15e6f..27567db021 100644 --- a/server-plugins/calendar/src/index.ts +++ b/server-plugins/calendar/src/index.ts @@ -37,7 +37,6 @@ export default plugin(serverCalendarId, { FindReminders: '' as Resource }, trigger: { - OnSocialIdentityCreate: '' as Resource, OnEmployee: '' as Resource, OnEvent: '' as Resource } diff --git a/server/tool/src/initializer.ts b/server/tool/src/initializer.ts index d566c44ea9..b3b6fc8381 100644 --- a/server/tool/src/initializer.ts +++ b/server/tool/src/initializer.ts @@ -8,7 +8,6 @@ import core, { makeCollabId, MeasureContext, Mixin, - parseSocialIdString, Ref, SocialIdType, Space, @@ -16,7 +15,8 @@ import core, { pickPrimarySocialId, type PersonId, type PersonInfo, - type WorkspaceIds + type WorkspaceIds, + buildSocialIdString } from '@hcengineering/core' import { ModelLogger } from '@hcengineering/model' import { makeRank } from '@hcengineering/rank' @@ -102,7 +102,8 @@ export class WorkspaceInitializer { private readonly nextRank = '#nextRank' private readonly now = '#now' private readonly creatorPersonVar = 'creatorPerson' - private readonly socialKey: PersonId + private readonly socialId: PersonId + private readonly socialKey: string private readonly socialType: SocialIdType private readonly socialValue: string @@ -114,10 +115,11 @@ export class WorkspaceInitializer { private readonly initRepoDir: string, private readonly creator: PersonInfo ) { - this.socialKey = pickPrimarySocialId(creator.socialIds)._id - const socialKeyObj = parseSocialIdString(this.socialKey) - this.socialType = socialKeyObj.type - this.socialValue = socialKeyObj.value + const primarySocialId = pickPrimarySocialId(creator.socialIds) + this.socialId = primarySocialId._id + this.socialKey = buildSocialIdString(primarySocialId) + this.socialType = primarySocialId.type + this.socialValue = primarySocialId.value } async processScript ( @@ -128,6 +130,7 @@ export class WorkspaceInitializer { const vars: Record = { '${creatorName@global}': this.creator.name, // eslint-disable-line no-template-curly-in-string '${creatorUuid@global}': this.creator.personUuid, // eslint-disable-line no-template-curly-in-string + '${creatorSocialId@global}': this.socialId, // eslint-disable-line no-template-curly-in-string '${creatorSocialKey@global}': this.socialKey, // eslint-disable-line no-template-curly-in-string '${creatorSocialType@global}': this.socialType, // eslint-disable-line no-template-curly-in-string '${creatorSocialValue@global}': this.socialValue // eslint-disable-line no-template-curly-in-string @@ -192,7 +195,7 @@ export class WorkspaceInitializer { const initPath = path.resolve(this.initRepoDir, step.path) // eslint-disable-next-line no-template-curly-in-string const initPerson = vars[`\${${this.creatorPersonVar}}`] - const importer = new HulyFormatImporter(this.client, uploader, logger, this.socialKey, initPerson) + const importer = new HulyFormatImporter(this.client, uploader, logger, this.socialId, initPerson) await importer.importFolder(initPath) } catch (error) { logger.error('Import failed', error) @@ -234,16 +237,18 @@ export class WorkspaceInitializer { vars: Record, defaults: Map>, Props> ): Promise { - const _id = generateId() - if (step.resultVariable !== undefined) { - vars[`\${${step.resultVariable}}`] = _id - } const data = await this.fillPropsWithMarkdown( { ...(defaults.get(step._class) ?? {}), ...step.data }, vars, step.markdownFields ) + const _id = (data._id as Ref) ?? generateId() + + if (step.resultVariable !== undefined) { + vars[`\${${step.resultVariable}}`] = _id + } + if (step.collabFields !== undefined) { for (const field of step.collabFields) { if ((data as any)[field] !== undefined) {