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

UBERF-8425: Global accounts #7573

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 4 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
// "FULLTEXT_URL": "http://localhost:4700",
"FULLTEXT_URL": "http://host.docker.internal:4702",
// "MONGO_URL": "mongodb://localhost:27017",
// "DB_URL": "mongodb://localhost:27017",
"DB_URL": "mongodb://localhost:27017",
// "DB_URL": "postgresql://postgres:example@localhost:5432",
"DB_URL": "postgresql://[email protected]:26257/defaultdb?sslmode=disable",
"SERVER_PORT": "3332",
// "DB_URL": "postgresql://[email protected]:26257/defaultdb?sslmode=disable",
"SERVER_PORT": "3333",
"APM_SERVER_URL2": "http://localhost:8200",
"METRICS_CONSOLE": "false",
"METRICS_FILE": "${workspaceRoot}/metrics.txt", // Show metrics in console evert 30 seconds.,
Expand Down Expand Up @@ -323,6 +323,7 @@
"MONGO_URL": "mongodb://localhost:27017",
"DB_URL": "mongodb://localhost:27017",
"ACCOUNTS_URL": "http://localhost:3000",
"ACCOUNT_DB_URL": "mongodb://localhost:27017",
"TELEGRAM_DATABASE": "telegram-service",
"REKONI_URL": "http://localhost:4004",
"MODEL_VERSION": "0.6.287"
Expand Down
152 changes: 126 additions & 26 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions desktop/src/main/backup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import client, { clientId } from '@hcengineering/client'
import { getWorkspaceId, MeasureMetricsContext, type BackupClient, type Client } from '@hcengineering/core'
import { MeasureMetricsContext, type BackupClient, type Client } from '@hcengineering/core'
import { addLocation, getResource, setMetadata } from '@hcengineering/platform'
import WebSocket from 'ws'

Expand Down Expand Up @@ -36,7 +36,7 @@ async function doBackup (dirName: string, token: string, endpoint: string, works
const ctx = new MeasureMetricsContext('backup', {})

const storage = await createFileBackupStorage(dirName)
const wsid = getWorkspaceId(workspace)
const wsid = workspace
const client = await createClient(endpoint, token)
try {
ctx.info('do backup', { workspace, endpoint })
Expand Down
14 changes: 7 additions & 7 deletions desktop/src/ui/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import login, { loginId } from '@hcengineering/login'
import { getEmbeddedLabel, getMetadata, setMetadata } from '@hcengineering/platform'
import presentation, { closeClient, MessageBox, setDownloadProgress } from '@hcengineering/presentation'
import { settingId } from '@hcengineering/setting'
import settings, { settingId } from '@hcengineering/setting'
import {
closePanel,
closePopup,
Expand All @@ -24,7 +24,6 @@ import { isOwnerOrMaintainer } from '@hcengineering/core'
import { configurePlatform } from './platform'
import { defineScreenShare } from './screenShare'
import { IPCMainExposed } from './types'
import settings from '@hcengineering/setting'

defineScreenShare()

Expand Down Expand Up @@ -62,13 +61,14 @@ window.addEventListener('DOMContentLoaded', () => {
const tokens = fetchMetadataLocalStorage(login.metadata.LoginTokens)
if (tokens !== null) {
const loc = getCurrentLocation()
loc.path.splice(1, 1)
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete tokens[loc.path[1]]
setMetadataLocalStorage(login.metadata.LoginTokens, tokens)
}
setMetadata(presentation.metadata.Token, null)
setMetadataLocalStorage(login.metadata.LastToken, null)
setMetadataLocalStorage(login.metadata.LoginEndpoint, null)
setMetadataLocalStorage(login.metadata.LoginEmail, null)
setMetadataLocalStorage(login.metadata.LoginAccount, null)
void closeClient().then(() => {
navigate({ path: [loginId] })
})
Expand Down Expand Up @@ -105,10 +105,10 @@ window.addEventListener('DOMContentLoaded', () => {
// We need to obtain current token and endpoint and trigger backup
const token = getMetadata(presentation.metadata.Token)
const endpoint = getMetadata(presentation.metadata.Endpoint)
const workspace = getMetadata(presentation.metadata.WorkspaceId)
const workspaceUuid = getMetadata(presentation.metadata.WorkspaceUuid)
if (isOwnerOrMaintainer()) {
if (token != null && endpoint != null && workspace != null) {
ipcMain.startBackup(token, endpoint, workspace)
if (token != null && endpoint != null && workspaceUuid != null) {
ipcMain.startBackup(token, endpoint, workspaceUuid)
}
} else {
showPopup(MessageBox, {
Expand Down
13 changes: 3 additions & 10 deletions desktop/src/ui/notifications.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import contact, { PersonAccount, formatName } from '@hcengineering/contact'
import { getPersonBySocialId, formatName } from '@hcengineering/contact'
import { Ref, TxOperations } from '@hcengineering/core'
import notification, { DocNotifyContext, CommonInboxNotification, ActivityInboxNotification, InboxNotification } from '@hcengineering/notification'
import { IntlString, addEventListener, translate } from '@hcengineering/platform'
Expand Down Expand Up @@ -67,14 +67,7 @@ async function hydrateNotificationAsYouCan (lastNotification: InboxNotification)
body: ''
}

const account = await client.getModel().findOne(contact.class.PersonAccount, { _id: lastNotification.modifiedBy as Ref<PersonAccount> })

if (account == null) {
return noPersonData
}

const person = await client.findOne(contact.class.Person, { _id: account.person })

const person = await getPersonBySocialId(client, lastNotification.modifiedBy)
if (person == null) {
return noPersonData
}
Expand Down Expand Up @@ -122,7 +115,7 @@ export function configureNotifications (): void {
let initTimestamp = 0
const notificationHistory = new Map<string, number>()

addEventListener(workbench.event.NotifyConnection, async (event, account: PersonAccount) => {
addEventListener(workbench.event.NotifyConnection, async () => {
client = getClient()
const electronAPI: IPCMainExposed = (window as any).electron

Expand Down
6 changes: 3 additions & 3 deletions desktop/src/ui/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { taskId } from '@hcengineering/task'
import telegram, { telegramId } from '@hcengineering/telegram'
import { templatesId } from '@hcengineering/templates'
import tracker, { trackerId } from '@hcengineering/tracker'
import uiPlugin, { getCurrentLocation, locationStorageKeyId, locationToUrl, navigate, parseLocation, setLocationStorageKey } from '@hcengineering/ui'
import uiPlugin, { getCurrentLocation, locationStorageKeyId, navigate, setLocationStorageKey } from '@hcengineering/ui'
import { uploaderId } from '@hcengineering/uploader'
import { viewId } from '@hcengineering/view'
import workbench, { workbenchId } from '@hcengineering/workbench'
Expand Down Expand Up @@ -238,7 +238,7 @@ export async function configurePlatform (): Promise<void> {
setMetadata(notification.metadata.PushPublicKey, config.PUSH_PUBLIC_KEY)

setMetadata(rekoni.metadata.RekoniUrl, config.REKONI_URL)
setMetadata(contactPlugin.metadata.LastNameFirst, myBranding.lastNameFirst === 'true' ?? false)
setMetadata(contactPlugin.metadata.LastNameFirst, myBranding.lastNameFirst === 'true')
setMetadata(love.metadata.ServiceEnpdoint, config.LOVE_ENDPOINT)
setMetadata(love.metadata.WebSocketURL, config.LIVEKIT_WS)
setMetadata(print.metadata.PrintURL, config.PRINT_URL)
Expand Down Expand Up @@ -335,7 +335,7 @@ export async function configurePlatform (): Promise<void> {

initThemeStore()

addEventListener(workbench.event.NotifyConnection, async (evt) => {
addEventListener(workbench.event.NotifyConnection, async () => {
await ipcMain.setFrontCookie(
config.FRONT_URL,
presentation.metadata.Token.replaceAll(':', '-'),
Expand Down
4 changes: 2 additions & 2 deletions dev/doc-import-tool/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Employee } from '@hcengineering/contact'
import { Ref, WorkspaceId } from '@hcengineering/core'
import { Ref, WorkspaceUuid } from '@hcengineering/core'
import { DocumentSpace } from '@hcengineering/controlled-documents'
import { StorageAdapter } from '@hcengineering/server-core'

Expand All @@ -11,7 +11,7 @@ export interface Config {
collaborator?: string
collaboratorURL: string
uploadURL: string
workspaceId: WorkspaceId
workspaceId: WorkspaceUuid
owner: Ref<Employee>
backend: HtmlConversionBackend
space: Ref<DocumentSpace>
Expand Down
6 changes: 3 additions & 3 deletions dev/doc-import-tool/src/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import core, {
TxOperations,
generateId,
makeDocCollabId,
systemAccountEmail,
systemAccountUuid,
type Blob
} from '@hcengineering/core'
import { createClient, getTransactorEndpoint } from '@hcengineering/server-client'
Expand All @@ -40,9 +40,9 @@ export default async function importExtractedFile (
extractedFile: ExtractedFile
): Promise<void> {
const { workspaceId } = config
const token = generateToken(systemAccountEmail, workspaceId)
const token = generateToken(systemAccountUuid, workspaceId)
const transactorUrl = await getTransactorEndpoint(token, 'external')
console.log(`Connecting to transactor: ${transactorUrl} (ws: '${workspaceId.name}')`)
console.log(`Connecting to transactor: ${transactorUrl} (ws: '${workspaceId}')`)
const connection = (await createClient(transactorUrl, token)) as CoreClient & BackupClient

try {
Expand Down
6 changes: 3 additions & 3 deletions dev/doc-import-tool/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//
import { Employee } from '@hcengineering/contact'
import documents, { DocumentSpace } from '@hcengineering/controlled-documents'
import { MeasureMetricsContext, Ref, getWorkspaceId, systemAccountEmail } from '@hcengineering/core'
import { MeasureMetricsContext, Ref, systemAccountUuid } from '@hcengineering/core'
import { setMetadata } from '@hcengineering/platform'
import serverClientPlugin from '@hcengineering/server-client'
import { type StorageAdapter } from '@hcengineering/server-core'
Expand Down Expand Up @@ -89,7 +89,7 @@ export function docImportTool (): void {
)

await withStorage(async (storageAdapter) => {
const workspaceId = getWorkspaceId(workspace)
const workspaceId = workspace

const config: Config = {
doc,
Expand All @@ -102,7 +102,7 @@ export function docImportTool (): void {
storageAdapter,
collaboratorURL: collaboratorUrl,
collaborator,
token: generateToken(systemAccountEmail, workspaceId)
token: generateToken(systemAccountUuid, workspaceId, { service: 'import-tool' })
}

await importDoc(ctx, config)
Expand Down
19 changes: 7 additions & 12 deletions dev/import-tool/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,32 +72,27 @@ export function importTool (): void {
console.log('Setting up Accounts URL: ', config.ACCOUNTS_URL)
setMetadata(serverClientPlugin.metadata.Endpoint, config.ACCOUNTS_URL)
console.log('Trying to login user: ', user)
const userToken = await login(user, password, workspaceUrl)
if (userToken === undefined) {
const { account, token } = await login(user, password, workspaceUrl)
if (token === undefined || account === undefined) {
console.log('Login failed for user: ', user)
return
}

console.log('Looking for workspace: ', workspaceUrl)
const allWorkspaces = await getUserWorkspaces(userToken)
const workspaces = allWorkspaces.filter((ws) => ws.workspaceUrl === workspaceUrl)
const allWorkspaces = await getUserWorkspaces(token)
const workspaces = allWorkspaces.filter((ws) => ws.url === workspaceUrl)
if (workspaces.length < 1) {
console.log('Workspace not found: ', workspaceUrl)
return
}
console.log('Workspace found')
const selectedWs = await selectWorkspace(userToken, workspaces[0].workspace)
const selectedWs = await selectWorkspace(token, workspaces[0].url)
console.log(selectedWs)

console.log('Connecting to Transactor URL: ', selectedWs.endpoint)
const connection = await createClient(selectedWs.endpoint, selectedWs.token)
const acc = connection.getModel().getAccountByEmail(user)
if (acc === undefined) {
console.log('Account not found for email: ', user)
return
}
const client = new TxOperations(connection, acc._id)
const fileUploader = new FrontFileUploader(getFrontUrl(), selectedWs.workspaceId, selectedWs.token)
const client = new TxOperations(connection, account)
const fileUploader = new FrontFileUploader(getFrontUrl(), selectedWs.workspace, selectedWs.token)
try {
await f(client, fileUploader)
} catch (err: any) {
Expand Down
2 changes: 1 addition & 1 deletion dev/prod/src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ export async function configurePlatform() {
setMetadata(rekoni.metadata.RekoniUrl, config.REKONI_URL)

setMetadata(uiPlugin.metadata.DefaultApplication, login.component.LoginApp)
setMetadata(contactPlugin.metadata.LastNameFirst, myBranding.lastNameFirst === 'true' ?? false)
setMetadata(contactPlugin.metadata.LastNameFirst, myBranding.lastNameFirst === 'true')
setMetadata(love.metadata.ServiceEnpdoint, config.LOVE_ENDPOINT)
setMetadata(love.metadata.WebSocketURL, config.LIVEKIT_WS)
setMetadata(print.metadata.PrintURL, config.PRINT_URL)
Expand Down
Loading
Loading