Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSK-947 Fix account presenter #2829

Merged
merged 1 commit into from
Mar 24, 2023
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
4 changes: 2 additions & 2 deletions dev/generator/src/connect.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import client from '@hcengineering/client'
import clientResources from '@hcengineering/client-resources'
import { Client, WorkspaceId } from '@hcengineering/core'
import { Client, systemAccountEmail, WorkspaceId } from '@hcengineering/core'
import { setMetadata } from '@hcengineering/platform'
import { generateToken } from '@hcengineering/server-token'

Expand All @@ -9,7 +9,7 @@ const WebSocket = require('ws')

export async function connect (transactorUrl: string, workspace: WorkspaceId): Promise<Client> {
console.log('connecting to transactor...')
const token = generateToken('anticrm@hc.engineering', workspace)
const token = generateToken(systemAccountEmail, workspace)

// We need to override default factory with 'ws' one.
setMetadata(client.metadata.ClientSocketFactory, (url) => new WebSocket(url))
Expand Down
12 changes: 10 additions & 2 deletions models/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@
// limitations under the License.
//

import { AccountRole, TxCollectionCUD, Doc, AttachedDoc, IndexingConfiguration, Class } from '@hcengineering/core'
import {
AccountRole,
TxCollectionCUD,
Doc,
AttachedDoc,
IndexingConfiguration,
Class,
systemAccountEmail
} from '@hcengineering/core'
import { Builder } from '@hcengineering/model'
import core from './component'
import {
Expand Down Expand Up @@ -113,7 +121,7 @@ export function createModel (builder: Builder): void {
core.class.Account,
core.space.Model,
{
email: 'anticrm@hc.engineering',
email: systemAccountEmail,
role: AccountRole.Owner
},
core.account.System
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ import type {
*/
export const coreId = 'core' as Plugin

/**
* @public
*/
export const systemAccountEmail = 'anticrm@hc.engineering'

export default plugin(coreId, {
class: {
Obj: '' as Ref<Class<Obj>>,
Expand Down Expand Up @@ -155,6 +160,7 @@ export default plugin(coreId, {
Hyperlink: '' as IntlString,
Private: '' as IntlString,
Object: '' as IntlString,
System: '' as IntlString,
CreatedBy: '' as IntlString
}
})
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { coreId } from './component'
//
export * from './classes'
export * from './client'
export { coreId, default } from './component'
export { coreId, systemAccountEmail, default } from './component'
export * from './hierarchy'
export * from './measurements'
export * from './memdb'
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"Members": "Members",
"Hyperlink": "URL",
"Object": "Object",
"System": "System",
"CreatedBy": "Reporter"
}
}
1 change: 1 addition & 0 deletions packages/core/src/lang/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"Members": "Участники",
"Hyperlink": "URL",
"Object": "Объект",
"System": "Система",
"CreatedBy": "Автор"
}
}
1 change: 0 additions & 1 deletion plugins/activity-assets/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"Changed": "changed",
"To": "to",
"Unset": "unset",
"System": "System",
"CollectionUpdated": "Update {collection}",
"Added": "added",
"Removed": "removed",
Expand Down
1 change: 0 additions & 1 deletion plugins/activity-assets/lang/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"Changed": "изменил(а)",
"To": "на",
"Unset": "сбросил",
"System": "Система",
"CollectionUpdated": "Обновлена {collection}",
"Added": "добавила(а)",
"Removed": "удалил(а)",
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 @@ -173,7 +173,7 @@
{#if employee}
{getName(employee)}
{:else}
<Label label={activity.string.System} />
<Label label={core.string.System} />
{/if}
</div>
{#if viewlet && viewlet?.editable}
Expand Down
1 change: 0 additions & 1 deletion plugins/activity-resources/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export default mergeIds(activityId, activity, {
Changed: '' as IntlString,
To: '' as IntlString,
Unset: '' as IntlString,
System: '' as IntlString,
Added: '' as IntlString,
Removed: '' as IntlString,
From: '' as IntlString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,38 @@
// limitations under the License.
-->
<script lang="ts">
import { EmployeeAccount, getName } from '@hcengineering/contact'
import { Account } from '@hcengineering/core'
import { EmployeeAccount } from '@hcengineering/contact'
import core, { Account, systemAccountEmail } from '@hcengineering/core'
import { getEmbeddedLabel } from '@hcengineering/platform'
import { showPopup, tooltip } from '@hcengineering/ui'
import { EditDoc } from '@hcengineering/view-resources'
import DocNavLink from '@hcengineering/view-resources/src/components/DocNavLink.svelte'
import { Label, tooltip } from '@hcengineering/ui'
import { employeeByIdStore } from '../utils'
import Avatar from './Avatar.svelte'
import EmployeePresenter from './EmployeePresenter.svelte'

export let value: Account
export let disabled = false
export let inline = false

$: employee = $employeeByIdStore.get((value as EmployeeAccount).employee)

async function onClick () {
if (employee !== undefined) {
showPopup(EditDoc, { _id: employee._id, _class: employee._class }, 'content')
}
}
const valueLabel = value.email === systemAccountEmail ? core.string.System : getEmbeddedLabel(value.email)
</script>

{#if value}
<!-- svelte-ignore a11y-click-events-have-key-events -->
<DocNavLink object={value} disableClick={disabled} noUnderline={disabled} {onClick}>
<span class="flex-row-center" use:tooltip={{ label: getEmbeddedLabel(employee ? getName(employee) : value.email) }}>
{#if employee}
<Avatar size={'x-small'} avatar={employee.avatar} />
<span class="overflow-label user">{getName(employee)}</span>
{:else}
<span class="overflow-label user">{value.email}</span>
{/if}
</span>
</DocNavLink>
{#if employee}
<EmployeePresenter value={employee} disableClick={disabled} {inline} />
{:else}
<div class="flex-row-center">
<Avatar size="x-small" />
<span class="overflow-label user" use:tooltip={{ label: valueLabel }}><Label label={valueLabel} /></span>
</div>
{/if}
{/if}

<style lang="scss">
.user {
color: var(--accent-color);
margin-left: 0.5rem;
font-weight: 500;
text-align: left;
Expand Down
3 changes: 2 additions & 1 deletion server/account/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import core, {
Data,
getWorkspaceId,
Ref,
systemAccountEmail,
Tx,
TxOperations,
Version,
Expand Down Expand Up @@ -352,7 +353,7 @@ export async function createAccount (
const salt = randomBytes(32)
const hash = hashWithSalt(password, salt)

const systemEmails = ['anticrm@hc.engineering']
const systemEmails = [systemAccountEmail]
if (systemEmails.includes(email)) {
throw new PlatformError(new Status(Severity.ERROR, accountPlugin.status.AccountAlreadyExists, { account: email }))
}
Expand Down
6 changes: 3 additions & 3 deletions server/middleware/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.
//

import core, { Account, AccountRole, ServerStorage } from '@hcengineering/core'
import core, { Account, AccountRole, ServerStorage, systemAccountEmail } from '@hcengineering/core'
import platform, { PlatformError, Severity, Status } from '@hcengineering/platform'
import { SessionContext } from '@hcengineering/server-core'

Expand All @@ -35,12 +35,12 @@ export async function getUser (storage: ServerStorage, ctx: SessionContext): Pro
}
const account = (await storage.modelDb.findAll(core.class.Account, { email: ctx.userEmail }))[0]
if (account === undefined) {
if (ctx.userEmail === 'anticrm@hc.engineering') {
if (ctx.userEmail === systemAccountEmail) {
return {
_id: core.account.System,
_class: core.class.Account,
role: AccountRole.Owner,
email: 'anticrm@hc.engineering',
email: systemAccountEmail,
space: core.space.Model,
modifiedBy: core.account.System,
modifiedOn: 0
Expand Down
4 changes: 2 additions & 2 deletions server/tool/src/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//

import client, { clientId } from '@hcengineering/client'
import { Client, WorkspaceId } from '@hcengineering/core'
import { Client, systemAccountEmail, WorkspaceId } from '@hcengineering/core'
import { addLocation, getResource, setMetadata } from '@hcengineering/platform'
import { generateToken } from '@hcengineering/server-token'

Expand All @@ -28,7 +28,7 @@ export async function connect (
email?: string,
extra?: Record<string, string>
): Promise<Client> {
const token = generateToken(email ?? 'anticrm@hc.engineering', workspace, extra)
const token = generateToken(email ?? systemAccountEmail, workspace, extra)

// We need to override default factory with 'ws' one.
// eslint-disable-next-line
Expand Down