Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions dev/tool/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,11 @@ export function devTool (
.command('create-account <email>')
.description('create user and corresponding account in master database')
.requiredOption('-p, --password <password>', 'user password')
.requiredOption('-f, --first <first>', 'first name')
.requiredOption('-l, --last <last>', 'last name')
.action(async (email: string, cmd) => {
const { mongodbUri } = prepareTools()
return await withDatabase(mongodbUri, async (db) => {
console.log(`creating account ${cmd.first as string} ${cmd.last as string} (${email})...`)
await createAcc(db, productId, email, cmd.password, cmd.first, cmd.last, true)
await createAcc(db, productId, email, cmd.password, true)
})
})

Expand All @@ -139,11 +137,13 @@ export function devTool (
program
.command('assign-workspace <email> <workspace>')
.description('assign workspace')
.requiredOption('-f, --first <first>', 'first name')
.requiredOption('-l, --last <last>', 'last name')
.action(async (email: string, workspace: string, cmd) => {
const { mongodbUri } = prepareTools()
return await withDatabase(mongodbUri, async (db, client) => {
console.log(`assigning user ${email} to ${workspace}...`)
await assignWorkspace(db, productId, email, workspace)
await assignWorkspace(db, productId, email, workspace, cmd.first, cmd.last)
})
})

Expand Down
14 changes: 9 additions & 5 deletions models/contact/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ export class TChannelProvider extends TDoc implements ChannelProvider {
export class TContact extends TDoc implements Contact {
@Prop(TypeString(), contact.string.Name)
@Index(IndexKind.FullText)
@Hidden()
name!: string

avatar?: string | null
Expand Down Expand Up @@ -168,10 +167,6 @@ export class TEmployee extends TPerson implements Employee {
@Hidden()
statuses?: number

@Prop(TypeString(), contact.string.DisplayName)
@Hidden()
displayName?: string | null

@Prop(TypeString(), contact.string.Position)
@Hidden()
position?: string | null
Expand Down Expand Up @@ -293,6 +288,15 @@ export function createModel (builder: Builder): void {
index: 100
})

builder.createDoc(activity.class.TxViewlet, core.space.Model, {
objectClass: contact.class.Person,
icon: contact.icon.Person,
txClass: core.class.TxUpdateDoc,
labelComponent: contact.activity.TxNameChange,
display: 'inline',
match: { 'operations.name': { $exists: true } }
})

builder.createDoc<Viewlet>(
view.class.Viewlet,
core.space.Model,
Expand Down
3 changes: 3 additions & 0 deletions models/contact/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import type { AnyComponent } from '@hcengineering/ui'
import { Action, ActionCategory, ViewAction } from '@hcengineering/view'

export default mergeIds(contactId, contact, {
activity: {
TxNameChange: '' as AnyComponent
},
component: {
PersonPresenter: '' as AnyComponent,
ContactRefPresenter: '' as AnyComponent,
Expand Down
1 change: 0 additions & 1 deletion models/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ export function createModel (builder: Builder): void {
core.space.Model,
{
email: systemAccountEmail,
name: systemAccountEmail,
role: AccountRole.Owner
},
core.account.System
Expand Down
1 change: 0 additions & 1 deletion models/core/src/security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,5 @@ export class TSpace extends TDoc implements Space {
@UX(core.string.Account, undefined, undefined, 'name')
export class TAccount extends TDoc implements Account {
email!: string
name!: string
role!: AccountRole
}
1 change: 0 additions & 1 deletion packages/core/src/__tests__/memdb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ describe('memdb', () => {
})
const account = await model.createDoc(core.class.Account, core.space.Model, {
email: 'email',
name: 'test',
role: 0
})
await model.updateDoc(core.class.Space, core.space.Model, space, { $push: { members: account } })
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ export interface Space extends Doc {
* @public
*/
export interface Account extends Doc {
name: string
email: string
role: AccountRole
}
Expand Down
4 changes: 2 additions & 2 deletions packages/query/src/__tests__/minmodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ export function genMinModel (): TxCUD<Doc>[] {
const u1 = 'User1' as Ref<Account>
const u2 = 'User2' as Ref<Account>
txes.push(
createDoc(core.class.Account, { email: 'user1@site.com', name: 'user1', role: 0 }, u1),
createDoc(core.class.Account, { email: 'user2@site.com', name: 'user2', role: 0 }, u2),
createDoc(core.class.Account, { email: 'user1@site.com', role: 0 }, u1),
createDoc(core.class.Account, { email: 'user2@site.com', role: 0 }, u2),
createDoc(core.class.Space, {
name: 'Sp1',
description: '',
Expand Down
1 change: 0 additions & 1 deletion packages/query/src/__tests__/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ describe('query', () => {

await factory.createDoc(core.class.Account, core.space.Model, {
email: 'user1@site.com',
name: 'user1',
role: 0
})
await factory.createDoc<Channel>(core.class.Space, core.space.Model, {
Expand Down
15 changes: 13 additions & 2 deletions plugins/activity-resources/src/components/Activity.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

const activityQuery = newActivity(client, attrs)

let viewlets: Map<ActivityKey, TxViewlet>
let viewlets: Map<ActivityKey, TxViewlet[]> = new Map()

let allViewlets: TxViewlet[] = []
let editableMap: Map<Ref<Class<Doc>>, boolean> | undefined = undefined
Expand All @@ -61,7 +61,18 @@
)
})

$: viewlets = new Map(allViewlets.map((r) => [activityKey(r.objectClass, r.txClass), r]))
$: viewlets = buildViewletsMap(allViewlets)

function buildViewletsMap (allViewlets: TxViewlet[]): Map<ActivityKey, TxViewlet[]> {
const viewlets = new Map()
for (const res of allViewlets) {
const key = activityKey(res.objectClass, res.txClass)
const arr = viewlets.get(key) ?? []
arr.push(res)
viewlets.set(key, arr)
}
return viewlets
}

let loading = false

Expand Down
2 changes: 1 addition & 1 deletion plugins/activity-resources/src/components/TxView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import TxViewTx from './TxViewTx.svelte'

export let tx: DisplayTx
export let viewlets: Map<ActivityKey, TxViewlet>
export let viewlets: Map<ActivityKey, TxViewlet[]>
export let showIcon: boolean = true
export let isNew: boolean = false
export let isNextNew: boolean = false
Expand Down
24 changes: 19 additions & 5 deletions plugins/activity-resources/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import core, {
Client,
Collection,
Doc,
Hierarchy,
Obj,
Ref,
TxCUD,
Expand All @@ -14,7 +15,8 @@ import core, {
TxOperations,
TxProcessor,
TxUpdateDoc,
getObjectValue
getObjectValue,
matchQuery
} from '@hcengineering/core'
import { Asset, IntlString, getResource, translate } from '@hcengineering/platform'
import { getAttributePresenterClass } from '@hcengineering/presentation'
Expand Down Expand Up @@ -82,7 +84,11 @@ export function getDTxProps (dtx: DisplayTx): any {
return { tx: dtx.tx, value: dtx.doc, isOwnTx: dtx.isOwnTx, prevValue: dtx.prevDoc }
}

function getViewlet (viewlets: Map<ActivityKey, TxViewlet>, dtx: DisplayTx): TxDisplayViewlet | undefined {
function getViewlet (
viewlets: Map<ActivityKey, TxViewlet[]>,
dtx: DisplayTx,
hierarchy: Hierarchy
): TxDisplayViewlet | undefined {
let key: string
if (dtx.mixinTx?.mixin !== undefined && dtx.tx._id === dtx.mixinTx._id) {
key = activityKey(dtx.mixinTx.mixin, dtx.tx._class)
Expand All @@ -91,13 +97,21 @@ function getViewlet (viewlets: Map<ActivityKey, TxViewlet>, dtx: DisplayTx): TxD
}
const vl = viewlets.get(key)
if (vl !== undefined) {
return { ...vl, pseudo: false }
for (const viewlet of vl) {
if (viewlet.match === undefined) {
return { ...viewlet, pseudo: false }
}
const res = matchQuery([dtx.tx], viewlet.match, dtx.tx._class, hierarchy)
if (res.length > 0) {
return { ...viewlet, pseudo: false }
}
}
}
}

export async function updateViewlet (
client: TxOperations,
viewlets: Map<ActivityKey, TxViewlet>,
viewlets: Map<ActivityKey, TxViewlet[]>,
dtx: DisplayTx
): Promise<{
viewlet: TxDisplayViewlet
Expand All @@ -107,7 +121,7 @@ export async function updateViewlet (
modelIcon: Asset | undefined
iconComponent: AnyComponent | undefined
}> {
let viewlet = getViewlet(viewlets, dtx)
let viewlet = getViewlet(viewlets, dtx, client.getHierarchy())

const props = getDTxProps(dtx)
let model: AttributeModel[] = []
Expand Down
1 change: 0 additions & 1 deletion plugins/bitrix/src/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,6 @@ async function synchronizeUsers (
})
accountId = await ops.client.createDoc(contact.class.PersonAccount, core.space.Model, {
email: u.EMAIL,
name: combineName(u.NAME, u.LAST_NAME),
person: employeeId,
role: AccountRole.User
})
Expand Down
1 change: 0 additions & 1 deletion plugins/contact-assets/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
"MergePersons": "Merge contacts",
"MergePersonsFrom": "Source contact",
"MergePersonsTo": "Final contact",
"DisplayName": "Display name",
"SelectAvatar": "Select avatar",
"AvatarProvider": "Avatar provider",
"GravatarsManaged": "Gravatars are managed",
Expand Down
1 change: 0 additions & 1 deletion plugins/contact-assets/lang/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
"MergePersons": "Объеденить контакта",
"MergePersonsFrom": "Исходный контакт",
"MergePersonsTo": "Финальный контакт",
"DisplayName": "Отображаемое имя",
"SelectAvatar": "Выбрать аватар",
"GravatarsManaged": "Граватары управляются",
"Through": "через",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@

await client.createDoc(contact.class.PersonAccount, core.space.Model, {
email: email.trim(),
name,
person: id,
role: AccountRole.User
})
Expand Down
28 changes: 18 additions & 10 deletions plugins/contact-resources/src/components/EditEmployee.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@
// limitations under the License.
-->
<script lang="ts">
import { Channel, Employee, PersonAccount, getFirstName, getLastName, Person } from '@hcengineering/contact'
import { AccountRole, getCurrentAccount, Ref } from '@hcengineering/core'
import login from '@hcengineering/login'
import { getResource } from '@hcengineering/platform'
import {
Channel,
Employee,
Person,
PersonAccount,
combineName,
getFirstName,
getLastName
} from '@hcengineering/contact'
import { AccountRole, Ref, getCurrentAccount } from '@hcengineering/core'
import { AttributeEditor, createQuery, getClient } from '@hcengineering/presentation'
import setting, { IntegrationType } from '@hcengineering/setting'
import { createFocusManager, EditBox, FocusHandler, Scroller } from '@hcengineering/ui'
import { EditBox, FocusHandler, Scroller, createFocusManager } from '@hcengineering/ui'
import { createEventDispatcher, onMount } from 'svelte'
import { ChannelsDropdown } from '..'
import contact from '../plugin'
Expand Down Expand Up @@ -61,13 +67,15 @@
const dispatch = createEventDispatcher()

async function firstNameChange () {
const changeName = await getResource(login.function.ChangeName)
await changeName(firstName, getLastName(object.name))
await client.update(object, {
name: combineName(firstName, getLastName(object.name))
})
}

async function lastNameChange () {
const changeName = await getResource(login.function.ChangeName)
await changeName(getFirstName(object.name), lastName)
await client.update(object, {
name: combineName(getFirstName(object.name), lastName)
})
}

let integrations: Set<Ref<IntegrationType>> = new Set<Ref<IntegrationType>>()
Expand All @@ -76,7 +84,7 @@
integrations = new Set(res.map((p) => p.type))
})

const sendOpen = () => dispatch('open', { ignoreKeys: ['comments', 'name', 'channels', 'city', 'displayName'] })
const sendOpen = () => dispatch('open', { ignoreKeys: ['comments', 'name', 'channels', 'city'] })
onMount(sendOpen)

async function onAvatarDone () {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!--
// Copyright © 2023 Hardcore Engineering Inc.
//
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
-->
<script lang="ts">
import { Person, formatName } from '@hcengineering/contact'
import { TxUpdateDoc } from '@hcengineering/core'
import contact from '../../plugin'
import { Label } from '@hcengineering/ui'
import activity from '@hcengineering/activity'

export let tx: TxUpdateDoc<Person>

const val = tx.operations.name
</script>

{#if val}
<span class="lower"><Label label={activity.string.Changed} /></span>
<span class="lower"><Label label={contact.string.Name} /></span>
<span class="lower"><Label label={activity.string.To} /></span>
<span class="strong overflow-label">
{formatName(val)}
</span>
{/if}
4 changes: 4 additions & 0 deletions plugins/contact-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ import ActivityChannelMessage from './components/activity/ActivityChannelMessage
import ActivityChannelPresenter from './components/activity/ActivityChannelPresenter.svelte'
import ExpandRightDouble from './components/icons/ExpandRightDouble.svelte'
import IconMembers from './components/icons/Members.svelte'
import TxNameChange from './components/activity/TxNameChange.svelte'

import contact from './plugin'
import {
Expand Down Expand Up @@ -274,6 +275,9 @@ export default async (): Promise<Resources> => ({
KickEmployee: kickEmployee,
OpenChannel: openChannelURL
},
activity: {
TxNameChange
},
component: {
ContactArrayEditor,
PersonEditor,
Expand Down
4 changes: 3 additions & 1 deletion plugins/contact-resources/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ export async function getRefs (

export async function getCurrentEmployeeName (): Promise<string> {
const me = getCurrentAccount() as PersonAccount
return formatName(me.name)
const client = getClient()
const employee = await client.findOne(contact.class.Person, { _id: me.person })
return employee !== undefined ? formatName(employee.name) : ''
}

export async function getCurrentEmployeeEmail (): Promise<string> {
Expand Down
2 changes: 0 additions & 2 deletions plugins/contact/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ export interface Status extends AttachedDoc {
export interface Employee extends Person {
active: boolean
statuses?: number
displayName?: string | null
position?: string | null
}

Expand Down Expand Up @@ -263,7 +262,6 @@ export const contactPlugin = plugin(contactId, {
UseColor: '' as IntlString,
PersonFirstNamePlaceholder: '' as IntlString,
PersonLastNamePlaceholder: '' as IntlString,
DisplayName: '' as IntlString,
NumberMembers: '' as IntlString,
Position: '' as IntlString
},
Expand Down
Loading