mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-22 19:11:33 +03:00
Fix account presenter (#2829)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
parent
a004c6dfbb
commit
df7bb05d0d
@ -1,6 +1,6 @@
|
|||||||
import client from '@hcengineering/client'
|
import client from '@hcengineering/client'
|
||||||
import clientResources from '@hcengineering/client-resources'
|
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 { setMetadata } from '@hcengineering/platform'
|
||||||
import { generateToken } from '@hcengineering/server-token'
|
import { generateToken } from '@hcengineering/server-token'
|
||||||
|
|
||||||
@ -9,7 +9,7 @@ const WebSocket = require('ws')
|
|||||||
|
|
||||||
export async function connect (transactorUrl: string, workspace: WorkspaceId): Promise<Client> {
|
export async function connect (transactorUrl: string, workspace: WorkspaceId): Promise<Client> {
|
||||||
console.log('connecting to transactor...')
|
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.
|
// We need to override default factory with 'ws' one.
|
||||||
setMetadata(client.metadata.ClientSocketFactory, (url) => new WebSocket(url))
|
setMetadata(client.metadata.ClientSocketFactory, (url) => new WebSocket(url))
|
||||||
|
@ -13,7 +13,15 @@
|
|||||||
// limitations under the License.
|
// 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 { Builder } from '@hcengineering/model'
|
||||||
import core from './component'
|
import core from './component'
|
||||||
import {
|
import {
|
||||||
@ -113,7 +121,7 @@ export function createModel (builder: Builder): void {
|
|||||||
core.class.Account,
|
core.class.Account,
|
||||||
core.space.Model,
|
core.space.Model,
|
||||||
{
|
{
|
||||||
email: 'anticrm@hc.engineering',
|
email: systemAccountEmail,
|
||||||
role: AccountRole.Owner
|
role: AccountRole.Owner
|
||||||
},
|
},
|
||||||
core.account.System
|
core.account.System
|
||||||
|
@ -62,6 +62,11 @@ import type {
|
|||||||
*/
|
*/
|
||||||
export const coreId = 'core' as Plugin
|
export const coreId = 'core' as Plugin
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export const systemAccountEmail = 'anticrm@hc.engineering'
|
||||||
|
|
||||||
export default plugin(coreId, {
|
export default plugin(coreId, {
|
||||||
class: {
|
class: {
|
||||||
Obj: '' as Ref<Class<Obj>>,
|
Obj: '' as Ref<Class<Obj>>,
|
||||||
@ -155,6 +160,7 @@ export default plugin(coreId, {
|
|||||||
Hyperlink: '' as IntlString,
|
Hyperlink: '' as IntlString,
|
||||||
Private: '' as IntlString,
|
Private: '' as IntlString,
|
||||||
Object: '' as IntlString,
|
Object: '' as IntlString,
|
||||||
|
System: '' as IntlString,
|
||||||
CreatedBy: '' as IntlString
|
CreatedBy: '' as IntlString
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -18,7 +18,7 @@ import { coreId } from './component'
|
|||||||
//
|
//
|
||||||
export * from './classes'
|
export * from './classes'
|
||||||
export * from './client'
|
export * from './client'
|
||||||
export { coreId, default } from './component'
|
export { coreId, systemAccountEmail, default } from './component'
|
||||||
export * from './hierarchy'
|
export * from './hierarchy'
|
||||||
export * from './measurements'
|
export * from './measurements'
|
||||||
export * from './memdb'
|
export * from './memdb'
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
"Members": "Members",
|
"Members": "Members",
|
||||||
"Hyperlink": "URL",
|
"Hyperlink": "URL",
|
||||||
"Object": "Object",
|
"Object": "Object",
|
||||||
|
"System": "System",
|
||||||
"CreatedBy": "Reporter"
|
"CreatedBy": "Reporter"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
"Members": "Участники",
|
"Members": "Участники",
|
||||||
"Hyperlink": "URL",
|
"Hyperlink": "URL",
|
||||||
"Object": "Объект",
|
"Object": "Объект",
|
||||||
|
"System": "Система",
|
||||||
"CreatedBy": "Автор"
|
"CreatedBy": "Автор"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
"Changed": "changed",
|
"Changed": "changed",
|
||||||
"To": "to",
|
"To": "to",
|
||||||
"Unset": "unset",
|
"Unset": "unset",
|
||||||
"System": "System",
|
|
||||||
"CollectionUpdated": "Update {collection}",
|
"CollectionUpdated": "Update {collection}",
|
||||||
"Added": "added",
|
"Added": "added",
|
||||||
"Removed": "removed",
|
"Removed": "removed",
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
"Changed": "изменил(а)",
|
"Changed": "изменил(а)",
|
||||||
"To": "на",
|
"To": "на",
|
||||||
"Unset": "сбросил",
|
"Unset": "сбросил",
|
||||||
"System": "Система",
|
|
||||||
"CollectionUpdated": "Обновлена {collection}",
|
"CollectionUpdated": "Обновлена {collection}",
|
||||||
"Added": "добавила(а)",
|
"Added": "добавила(а)",
|
||||||
"Removed": "удалил(а)",
|
"Removed": "удалил(а)",
|
||||||
|
@ -173,7 +173,7 @@
|
|||||||
{#if employee}
|
{#if employee}
|
||||||
{getName(employee)}
|
{getName(employee)}
|
||||||
{:else}
|
{:else}
|
||||||
<Label label={activity.string.System} />
|
<Label label={core.string.System} />
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{#if viewlet && viewlet?.editable}
|
{#if viewlet && viewlet?.editable}
|
||||||
|
@ -25,7 +25,6 @@ export default mergeIds(activityId, activity, {
|
|||||||
Changed: '' as IntlString,
|
Changed: '' as IntlString,
|
||||||
To: '' as IntlString,
|
To: '' as IntlString,
|
||||||
Unset: '' as IntlString,
|
Unset: '' as IntlString,
|
||||||
System: '' as IntlString,
|
|
||||||
Added: '' as IntlString,
|
Added: '' as IntlString,
|
||||||
Removed: '' as IntlString,
|
Removed: '' as IntlString,
|
||||||
From: '' as IntlString,
|
From: '' as IntlString,
|
||||||
|
@ -14,43 +14,38 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { EmployeeAccount, getName } from '@hcengineering/contact'
|
import { EmployeeAccount } from '@hcengineering/contact'
|
||||||
import { Account } from '@hcengineering/core'
|
import core, { Account, systemAccountEmail } from '@hcengineering/core'
|
||||||
import { getEmbeddedLabel } from '@hcengineering/platform'
|
import { getEmbeddedLabel } from '@hcengineering/platform'
|
||||||
import { showPopup, tooltip } from '@hcengineering/ui'
|
import { Label, tooltip } from '@hcengineering/ui'
|
||||||
import { EditDoc } from '@hcengineering/view-resources'
|
|
||||||
import DocNavLink from '@hcengineering/view-resources/src/components/DocNavLink.svelte'
|
|
||||||
import { employeeByIdStore } from '../utils'
|
import { employeeByIdStore } from '../utils'
|
||||||
import Avatar from './Avatar.svelte'
|
import Avatar from './Avatar.svelte'
|
||||||
|
import EmployeePresenter from './EmployeePresenter.svelte'
|
||||||
|
|
||||||
export let value: Account
|
export let value: Account
|
||||||
export let disabled = false
|
export let disabled = false
|
||||||
|
export let inline = false
|
||||||
|
|
||||||
$: employee = $employeeByIdStore.get((value as EmployeeAccount).employee)
|
$: employee = $employeeByIdStore.get((value as EmployeeAccount).employee)
|
||||||
|
|
||||||
async function onClick () {
|
const valueLabel = value.email === systemAccountEmail ? core.string.System : getEmbeddedLabel(value.email)
|
||||||
if (employee !== undefined) {
|
|
||||||
showPopup(EditDoc, { _id: employee._id, _class: employee._class }, 'content')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if value}
|
{#if value}
|
||||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||||
<DocNavLink object={value} disableClick={disabled} noUnderline={disabled} {onClick}>
|
{#if employee}
|
||||||
<span class="flex-row-center" use:tooltip={{ label: getEmbeddedLabel(employee ? getName(employee) : value.email) }}>
|
<EmployeePresenter value={employee} disableClick={disabled} {inline} />
|
||||||
{#if employee}
|
{:else}
|
||||||
<Avatar size={'x-small'} avatar={employee.avatar} />
|
<div class="flex-row-center">
|
||||||
<span class="overflow-label user">{getName(employee)}</span>
|
<Avatar size="x-small" />
|
||||||
{:else}
|
<span class="overflow-label user" use:tooltip={{ label: valueLabel }}><Label label={valueLabel} /></span>
|
||||||
<span class="overflow-label user">{value.email}</span>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</span>
|
|
||||||
</DocNavLink>
|
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
.user {
|
.user {
|
||||||
|
color: var(--accent-color);
|
||||||
margin-left: 0.5rem;
|
margin-left: 0.5rem;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
|
@ -27,6 +27,7 @@ import core, {
|
|||||||
Data,
|
Data,
|
||||||
getWorkspaceId,
|
getWorkspaceId,
|
||||||
Ref,
|
Ref,
|
||||||
|
systemAccountEmail,
|
||||||
Tx,
|
Tx,
|
||||||
TxOperations,
|
TxOperations,
|
||||||
Version,
|
Version,
|
||||||
@ -352,7 +353,7 @@ export async function createAccount (
|
|||||||
const salt = randomBytes(32)
|
const salt = randomBytes(32)
|
||||||
const hash = hashWithSalt(password, salt)
|
const hash = hashWithSalt(password, salt)
|
||||||
|
|
||||||
const systemEmails = ['anticrm@hc.engineering']
|
const systemEmails = [systemAccountEmail]
|
||||||
if (systemEmails.includes(email)) {
|
if (systemEmails.includes(email)) {
|
||||||
throw new PlatformError(new Status(Severity.ERROR, accountPlugin.status.AccountAlreadyExists, { account: email }))
|
throw new PlatformError(new Status(Severity.ERROR, accountPlugin.status.AccountAlreadyExists, { account: email }))
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
// limitations under the License.
|
// 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 platform, { PlatformError, Severity, Status } from '@hcengineering/platform'
|
||||||
import { SessionContext } from '@hcengineering/server-core'
|
import { SessionContext } from '@hcengineering/server-core'
|
||||||
|
|
||||||
@ -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]
|
const account = (await storage.modelDb.findAll(core.class.Account, { email: ctx.userEmail }))[0]
|
||||||
if (account === undefined) {
|
if (account === undefined) {
|
||||||
if (ctx.userEmail === 'anticrm@hc.engineering') {
|
if (ctx.userEmail === systemAccountEmail) {
|
||||||
return {
|
return {
|
||||||
_id: core.account.System,
|
_id: core.account.System,
|
||||||
_class: core.class.Account,
|
_class: core.class.Account,
|
||||||
role: AccountRole.Owner,
|
role: AccountRole.Owner,
|
||||||
email: 'anticrm@hc.engineering',
|
email: systemAccountEmail,
|
||||||
space: core.space.Model,
|
space: core.space.Model,
|
||||||
modifiedBy: core.account.System,
|
modifiedBy: core.account.System,
|
||||||
modifiedOn: 0
|
modifiedOn: 0
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import client, { clientId } from '@hcengineering/client'
|
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 { addLocation, getResource, setMetadata } from '@hcengineering/platform'
|
||||||
import { generateToken } from '@hcengineering/server-token'
|
import { generateToken } from '@hcengineering/server-token'
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ export async function connect (
|
|||||||
email?: string,
|
email?: string,
|
||||||
extra?: Record<string, string>
|
extra?: Record<string, string>
|
||||||
): Promise<Client> {
|
): 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.
|
// We need to override default factory with 'ws' one.
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
|
Loading…
Reference in New Issue
Block a user