uberf-10342: fix init script executor (#8702)

Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
Alexey Zinoviev 2025-04-25 12:07:11 +04:00 committed by GitHub
parent 17ac05f126
commit b09a09c820
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 42 deletions

View File

@ -33,14 +33,6 @@ export function createModel (builder: Builder): void {
presenter: serverCalendar.function.ReminderTextPresenter 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, { builder.createDoc(serverCore.class.Trigger, core.space.Model, {
trigger: serverCalendar.trigger.OnEmployee, trigger: serverCalendar.trigger.OnEmployee,
txMatch: { txMatch: {

View File

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
// //
import calendar, { Calendar, Event, ExternalCalendar } from '@hcengineering/calendar' 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, { import core, {
Class, Class,
concatLink, concatLink,
@ -117,25 +117,6 @@ export async function OnEmployee (txes: Tx[], control: TriggerControl): Promise<
return result return result
} }
export async function OnSocialIdentityCreate (txes: Tx[], control: TriggerControl): Promise<Tx[]> {
const result: Tx[] = []
for (const tx of txes) {
const ctx = tx as TxCUD<SocialIdentity>
if (ctx._class !== core.class.TxCreateDoc) continue
const socialId = TxProcessor.createDoc2Doc(ctx as TxCreateDoc<SocialIdentity>)
const employee = (
await control.findAll(control.ctx, contactPlugin.mixin.Employee, { _id: socialId.attachedTo as Ref<Employee> })
)[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<Person>): Promise<boolean> { async function checkCalendarsExist (control: TriggerControl, person: Ref<Person>): Promise<boolean> {
const socialStrings = await getSocialStrings(control, person) const socialStrings = await getSocialStrings(control, person)
const calendars = await control.findAll( const calendars = await control.findAll(
@ -445,7 +426,6 @@ export default async () => ({
FindReminders FindReminders
}, },
trigger: { trigger: {
OnSocialIdentityCreate,
OnEmployee, OnEmployee,
OnEvent OnEvent
} }

View File

@ -37,7 +37,6 @@ export default plugin(serverCalendarId, {
FindReminders: '' as Resource<ObjectDDParticipantFunc> FindReminders: '' as Resource<ObjectDDParticipantFunc>
}, },
trigger: { trigger: {
OnSocialIdentityCreate: '' as Resource<TriggerFunc>,
OnEmployee: '' as Resource<TriggerFunc>, OnEmployee: '' as Resource<TriggerFunc>,
OnEvent: '' as Resource<TriggerFunc> OnEvent: '' as Resource<TriggerFunc>
} }

View File

@ -8,7 +8,6 @@ import core, {
makeCollabId, makeCollabId,
MeasureContext, MeasureContext,
Mixin, Mixin,
parseSocialIdString,
Ref, Ref,
SocialIdType, SocialIdType,
Space, Space,
@ -16,7 +15,8 @@ import core, {
pickPrimarySocialId, pickPrimarySocialId,
type PersonId, type PersonId,
type PersonInfo, type PersonInfo,
type WorkspaceIds type WorkspaceIds,
buildSocialIdString
} from '@hcengineering/core' } from '@hcengineering/core'
import { ModelLogger } from '@hcengineering/model' import { ModelLogger } from '@hcengineering/model'
import { makeRank } from '@hcengineering/rank' import { makeRank } from '@hcengineering/rank'
@ -102,7 +102,8 @@ export class WorkspaceInitializer {
private readonly nextRank = '#nextRank' private readonly nextRank = '#nextRank'
private readonly now = '#now' private readonly now = '#now'
private readonly creatorPersonVar = 'creatorPerson' private readonly creatorPersonVar = 'creatorPerson'
private readonly socialKey: PersonId private readonly socialId: PersonId
private readonly socialKey: string
private readonly socialType: SocialIdType private readonly socialType: SocialIdType
private readonly socialValue: string private readonly socialValue: string
@ -114,10 +115,11 @@ export class WorkspaceInitializer {
private readonly initRepoDir: string, private readonly initRepoDir: string,
private readonly creator: PersonInfo private readonly creator: PersonInfo
) { ) {
this.socialKey = pickPrimarySocialId(creator.socialIds)._id const primarySocialId = pickPrimarySocialId(creator.socialIds)
const socialKeyObj = parseSocialIdString(this.socialKey) this.socialId = primarySocialId._id
this.socialType = socialKeyObj.type this.socialKey = buildSocialIdString(primarySocialId)
this.socialValue = socialKeyObj.value this.socialType = primarySocialId.type
this.socialValue = primarySocialId.value
} }
async processScript ( async processScript (
@ -128,6 +130,7 @@ export class WorkspaceInitializer {
const vars: Record<string, any> = { const vars: Record<string, any> = {
'${creatorName@global}': this.creator.name, // eslint-disable-line no-template-curly-in-string '${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 '${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 '${creatorSocialKey@global}': this.socialKey, // eslint-disable-line no-template-curly-in-string
'${creatorSocialType@global}': this.socialType, // 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 '${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) const initPath = path.resolve(this.initRepoDir, step.path)
// eslint-disable-next-line no-template-curly-in-string // eslint-disable-next-line no-template-curly-in-string
const initPerson = vars[`\${${this.creatorPersonVar}}`] 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) await importer.importFolder(initPath)
} catch (error) { } catch (error) {
logger.error('Import failed', error) logger.error('Import failed', error)
@ -234,16 +237,18 @@ export class WorkspaceInitializer {
vars: Record<string, any>, vars: Record<string, any>,
defaults: Map<Ref<Class<T>>, Props<T>> defaults: Map<Ref<Class<T>>, Props<T>>
): Promise<void> { ): Promise<void> {
const _id = generateId<T>()
if (step.resultVariable !== undefined) {
vars[`\${${step.resultVariable}}`] = _id
}
const data = await this.fillPropsWithMarkdown( const data = await this.fillPropsWithMarkdown(
{ ...(defaults.get(step._class) ?? {}), ...step.data }, { ...(defaults.get(step._class) ?? {}), ...step.data },
vars, vars,
step.markdownFields step.markdownFields
) )
const _id = (data._id as Ref<T>) ?? generateId<T>()
if (step.resultVariable !== undefined) {
vars[`\${${step.resultVariable}}`] = _id
}
if (step.collabFields !== undefined) { if (step.collabFields !== undefined) {
for (const field of step.collabFields) { for (const field of step.collabFields) {
if ((data as any)[field] !== undefined) { if ((data as any)[field] !== undefined) {