diff --git a/models/contact/src/index.ts b/models/contact/src/index.ts index 67f7645d35..5348e1b5cd 100644 --- a/models/contact/src/index.ts +++ b/models/contact/src/index.ts @@ -690,6 +690,17 @@ export function createModel (builder: Builder): void { contact.templateField.ContactName ) + builder.createDoc( + templates.class.TemplateField, + core.space.Model, + { + label: contact.string.Position, + category: contact.templateFieldCategory.CurrentEmployee, + func: contact.function.GetCurrentEmployeePosition + }, + contact.templateField.CurrentEmployeePosition + ) + builder.createDoc( templates.class.TemplateField, core.space.Model, diff --git a/models/contact/src/plugin.ts b/models/contact/src/plugin.ts index af074472b5..652ab40754 100644 --- a/models/contact/src/plugin.ts +++ b/models/contact/src/plugin.ts @@ -103,6 +103,7 @@ export default mergeIds(contactId, contact, { function: { GetCurrentEmployeeName: '' as Resource, GetCurrentEmployeeEmail: '' as Resource, + GetCurrentEmployeePosition: '' as Resource, GetContactName: '' as Resource, GetContactFirstName: '' as Resource, GetContactLastName: '' as Resource diff --git a/models/setting/package.json b/models/setting/package.json index 67eb513c2e..c03734527a 100644 --- a/models/setting/package.json +++ b/models/setting/package.json @@ -30,6 +30,7 @@ "@hcengineering/ui": "^0.6.3", "@hcengineering/view": "^0.6.2", "@hcengineering/setting": "^0.6.3", + "@hcengineering/contact": "^0.6.11", "@hcengineering/setting-resources": "^0.6.0", "@hcengineering/platform": "^0.6.8", "@hcengineering/model-core": "^0.6.0", diff --git a/models/setting/src/index.ts b/models/setting/src/index.ts index 582f38973f..f0797c212d 100644 --- a/models/setting/src/index.ts +++ b/models/setting/src/index.ts @@ -32,6 +32,7 @@ import { import task from '@hcengineering/task' import setting from './plugin' import templates from '@hcengineering/templates' +import contact from '@hcengineering/contact' import workbench from '@hcengineering/model-workbench' import { AnyComponent } from '@hcengineering/ui' @@ -445,6 +446,17 @@ export function createModel (builder: Builder): void { }, setting.templateField.OwnerName ) + + builder.createDoc( + templates.class.TemplateField, + core.space.Model, + { + label: contact.string.Position, + category: setting.templateFieldCategory.Integration, + func: setting.function.GetOwnerPosition + }, + setting.templateField.OwnerPosition + ) } export { settingOperation } from './migration' diff --git a/models/setting/src/plugin.ts b/models/setting/src/plugin.ts index 242b5808c4..a13f7383bb 100644 --- a/models/setting/src/plugin.ts +++ b/models/setting/src/plugin.ts @@ -59,6 +59,7 @@ export default mergeIds(settingId, setting, { }, function: { GetValue: '' as Resource, - GetOwnerName: '' as Resource + GetOwnerName: '' as Resource, + GetOwnerPosition: '' as Resource } }) diff --git a/plugins/contact-resources/src/index.ts b/plugins/contact-resources/src/index.ts index 320d3a2d72..34f884bf6d 100644 --- a/plugins/contact-resources/src/index.ts +++ b/plugins/contact-resources/src/index.ts @@ -81,6 +81,7 @@ import { getContactName, getCurrentEmployeeEmail, getCurrentEmployeeName, + getCurrentEmployeePosition, resolveLocation } from './utils' @@ -282,6 +283,7 @@ export default async (): Promise => ({ FilterChannelNinResult: filterChannelNinResult, GetCurrentEmployeeName: getCurrentEmployeeName, GetCurrentEmployeeEmail: getCurrentEmployeeEmail, + GetCurrentEmployeePosition: getCurrentEmployeePosition, GetContactName: getContactName, GetContactFirstName: getContactFirstName, GetContactLastName: getContactLastName, diff --git a/plugins/contact-resources/src/utils.ts b/plugins/contact-resources/src/utils.ts index 8d915fc02f..347c3962b6 100644 --- a/plugins/contact-resources/src/utils.ts +++ b/plugins/contact-resources/src/utils.ts @@ -125,6 +125,15 @@ export async function getCurrentEmployeeEmail (): Promise { return me.email } +export async function getCurrentEmployeePosition (): Promise { + const me = getCurrentAccount() as EmployeeAccount + const client = getClient() + const employee = await client.findOne(contact.class.Employee, { _id: me.employee }) + if (employee !== undefined) { + return employee.position ?? '' + } +} + export async function getContactName (provider: TemplateDataProvider): Promise { const value = provider.get(contact.class.Contact) as Contact if (value === undefined) return diff --git a/plugins/contact/src/index.ts b/plugins/contact/src/index.ts index 2a6546bc1d..d61c35a1e7 100644 --- a/plugins/contact/src/index.ts +++ b/plugins/contact/src/index.ts @@ -265,6 +265,7 @@ export const contactPlugin = plugin(contactId, { }, templateField: { CurrentEmployeeName: '' as Ref, + CurrentEmployeePosition: '' as Ref, CurrentEmployeeEmail: '' as Ref, ContactName: '' as Ref, ContactFirstName: '' as Ref, diff --git a/plugins/setting-resources/src/index.ts b/plugins/setting-resources/src/index.ts index 86ece8a52c..816437a699 100644 --- a/plugins/setting-resources/src/index.ts +++ b/plugins/setting-resources/src/index.ts @@ -44,7 +44,7 @@ import StringTypeEditor from './components/typeEditors/StringTypeEditor.svelte' import WorkspaceSettings from './components/WorkspaceSettings.svelte' import InviteSetting from './components/InviteSetting.svelte' import setting from './plugin' -import { getOwnerName, getValue } from './utils' +import { getOwnerName, getOwnerPosition, getValue } from './utils' export { ClassSetting } @@ -105,6 +105,7 @@ export default async (): Promise => ({ }, function: { GetOwnerName: getOwnerName, + GetOwnerPosition: getOwnerPosition, GetValue: getValue } }) diff --git a/plugins/setting-resources/src/utils.ts b/plugins/setting-resources/src/utils.ts index aa9d864a0f..624df2c68f 100644 --- a/plugins/setting-resources/src/utils.ts +++ b/plugins/setting-resources/src/utils.ts @@ -69,3 +69,16 @@ export async function getOwnerName (provider: TemplateDataProvider): Promise { + const value = provider.get(setting.class.Integration) + if (value === undefined) return + const client = getClient() + const employeeAccount = await client.findOne(contact.class.EmployeeAccount, { + _id: value.modifiedBy as Ref + }) + if (employeeAccount !== undefined) { + const employee = get(employeeByIdStore).get(employeeAccount.employee) + return employee != null ? employee.position ?? '' : undefined + } +} diff --git a/plugins/setting/src/index.ts b/plugins/setting/src/index.ts index a8fc526d4b..be3504ece8 100644 --- a/plugins/setting/src/index.ts +++ b/plugins/setting/src/index.ts @@ -182,6 +182,7 @@ export default plugin(settingId, { }, templateField: { OwnerName: '' as Ref, + OwnerPosition: '' as Ref, Value: '' as Ref } })