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
})
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: {

View File

@ -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<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> {
const socialStrings = await getSocialStrings(control, person)
const calendars = await control.findAll(
@ -445,7 +426,6 @@ export default async () => ({
FindReminders
},
trigger: {
OnSocialIdentityCreate,
OnEmployee,
OnEvent
}

View File

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

View File

@ -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<string, any> = {
'${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<string, any>,
defaults: Map<Ref<Class<T>>, Props<T>>
): Promise<void> {
const _id = generateId<T>()
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<T>) ?? generateId<T>()
if (step.resultVariable !== undefined) {
vars[`\${${step.resultVariable}}`] = _id
}
if (step.collabFields !== undefined) {
for (const field of step.collabFields) {
if ((data as any)[field] !== undefined) {