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

UBER-62: Maintenance warnings #3210

Merged
merged 1 commit into from
May 19, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions dev/client-resources/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
//

import core, {
Account,
Class,
ClientConnection,
Doc,
Expand Down Expand Up @@ -65,6 +66,10 @@ class ServerStorageWrapper implements ClientConnection {
})
}

async getAccount (): Promise<Account> {
return (await this.storage.findAll(this.measureCtx, core.class.Account, {}))[0]
}

async tx (tx: Tx): Promise<TxResult> {
const _tx = protoDeserialize(protoSerialize(tx, false), false)
const [result, derived] = await this.storage.tx(this.measureCtx, _tx)
Expand Down
10 changes: 5 additions & 5 deletions dev/client-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
// limitations under the License.
//

import { createClient, Client } from '@hcengineering/core'
import { getMetadata, getResource } from '@hcengineering/platform'
import clientPlugin from '@hcengineering/client'
import { AccountClient, createClient } from '@hcengineering/core'
import { migrateOperations } from '@hcengineering/model-all'
import { getMetadata, getResource } from '@hcengineering/platform'
import { connect } from './connection'
import clientPlugin from '@hcengineering/client'

let client: Client
let client: AccountClient
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export default async () => {
return {
function: {
GetClient: async (): Promise<Client> => {
GetClient: async (): Promise<AccountClient> => {
if (client === undefined) {
client = await createClient(connect)
for (const op of migrateOperations) {
Expand Down
12 changes: 12 additions & 0 deletions dev/tool/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
listAccounts,
listWorkspaces,
replacePassword,
setAccountAdmin,
setRole,
upgradeWorkspace
} from '@hcengineering/account'
Expand Down Expand Up @@ -195,6 +196,17 @@ export function devTool (
await setRole(email, workspace, productId, role)
})

program
.command('set-user-admin <email> <role>')
.description('set user role')
.action(async (email: string, role: string) => {
const { mongodbUri } = prepareTools()
console.log(`set user ${email} admin...`)
return await withDatabase(mongodbUri, async (db) => {
await setAccountAdmin(db, email, role === 'true')
})
})

program
.command('upgrade-workspace <name>')
.description('upgrade workspace')
Expand Down
2 changes: 1 addition & 1 deletion models/chunter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ export function createModel (builder: Builder, options = { addApplication: true
},
templates: {
textTemplate: '{sender} mentioned you in {doc} {data}',
htmlTemplate: '<p><b>{sender}</b> mentioned you in {doc}</p> {data}',
htmlTemplate: '<p>{sender}</b> mentioned you in {doc}</p> {data}',
subjectTemplate: 'You were mentioned in {doc}'
}
},
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/__tests__/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// limitations under the License.
//
import { Plugin, IntlString } from '@hcengineering/platform'
import type { Class, Data, Doc, Domain, PluginConfiguration, Ref, Timestamp } from '../classes'
import type { Account, Class, Data, Doc, Domain, PluginConfiguration, Ref, Timestamp } from '../classes'
import { Space, ClassifierKind, DOMAIN_MODEL } from '../classes'
import { createClient, ClientConnection } from '../client'
import core from '../component'
Expand Down Expand Up @@ -113,7 +113,8 @@ describe('client', () => {
loadDocs: async (domain: Domain, docs: Ref<Doc>[]) => [],
upload: async (domain: Domain, docs: Doc[]) => {},
clean: async (domain: Domain, docs: Ref<Doc>[]) => {},
loadModel: async (last: Timestamp) => txes
loadModel: async (last: Timestamp) => txes,
getAccount: async () => null as unknown as Account
}
}
const spyCreate = jest.spyOn(TxProcessor, 'createDoc2Doc')
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/__tests__/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.
//

import type { Class, Doc, Domain, Ref, Timestamp } from '../classes'
import type { Account, Class, Doc, Domain, Ref, Timestamp } from '../classes'
import { ClientConnection } from '../client'
import core from '../component'
import { Hierarchy } from '../hierarchy'
Expand Down Expand Up @@ -65,6 +65,7 @@ export async function connect (handler: (tx: Tx) => void): Promise<ClientConnect
loadDocs: async (domain: Domain, docs: Ref<Doc>[]) => [],
upload: async (domain: Domain, docs: Doc[]) => {},
clean: async (domain: Domain, docs: Ref<Doc>[]) => {},
loadModel: async (last: Timestamp) => txes
loadModel: async (last: Timestamp) => txes,
getAccount: async () => null as unknown as Account
}
}
18 changes: 15 additions & 3 deletions packages/core/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import { Plugin } from '@hcengineering/platform'
import { BackupClient, DocChunk } from './backup'
import { AttachedDoc, Class, DOMAIN_MODEL, Doc, Domain, PluginConfiguration, Ref, Timestamp } from './classes'
import { Account, AttachedDoc, Class, DOMAIN_MODEL, Doc, Domain, PluginConfiguration, Ref, Timestamp } from './classes'
import core from './component'
import { Hierarchy } from './hierarchy'
import { ModelDb } from './memdb'
Expand Down Expand Up @@ -47,16 +47,24 @@ export interface Client extends Storage {
close: () => Promise<void>
}

/**
* @public
*/
export interface AccountClient extends Client {
getAccount: () => Promise<Account>
}

/**
* @public
*/
export interface ClientConnection extends Storage, BackupClient {
close: () => Promise<void>
onConnect?: (apply: boolean) => Promise<void>
loadModel: (last: Timestamp) => Promise<Tx[]>
getAccount: () => Promise<Account>
}

class ClientImpl implements Client, BackupClient {
class ClientImpl implements AccountClient, BackupClient {
notify?: (tx: Tx) => void

constructor (
Expand Down Expand Up @@ -144,6 +152,10 @@ class ClientImpl implements Client, BackupClient {
async clean (domain: Domain, docs: Ref<Doc>[]): Promise<void> {
return await this.conn.clean(domain, docs)
}

async getAccount (): Promise<Account> {
return await this.conn.getAccount()
}
}

/**
Expand All @@ -153,7 +165,7 @@ export async function createClient (
connect: (txHandler: TxHandler) => Promise<ClientConnection>,
// If set will build model with only allowed plugins.
allowedPlugins?: Plugin[]
): Promise<Client> {
): Promise<AccountClient> {
let client: ClientImpl | null = null

// Temporal buffer, while we apply model
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export enum WorkspaceEvent {
UpgradeScheduled,
Upgrade,
IndexingUpdate,
SecurityChange
SecurityChange,
MaintenanceNotification
}

/**
Expand Down
3 changes: 3 additions & 0 deletions packages/panel/src/components/Panel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
const startScrollHeightCheck = () => {
clearTimeout(timer)
timer = setTimeout(() => {
if (scroll == null) {
return
}
if (lastScrollHeight <= scroll.scrollHeight && count <= waitCount) {
count = lastScrollHeight < scroll.scrollHeight ? 0 : count + 1
lastScrollHeight = scroll.scrollHeight
Expand Down
11 changes: 6 additions & 5 deletions packages/platform/src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
// limitations under the License.
//

import type { Plugin, IntlString } from './platform'
import { Status, Severity, unknownError } from './status'
import { _IdInfo, _parseId } from './ident'
import { setPlatformStatus } from './event'
import { IntlMessageFormat } from 'intl-messageformat'
import { setPlatformStatus } from './event'
import { _IdInfo, _parseId } from './ident'
import type { IntlString, Plugin } from './platform'
import { Severity, Status, unknownError } from './status'

import platform from './platform'
import { getMetadata } from './metadata'
import platform from './platform'

/**
* @public
Expand Down Expand Up @@ -103,6 +103,7 @@ async function getTranslation (id: _IdInfo, locale: string): Promise<IntlString
export async function translate<P extends Record<string, any>> (message: IntlString<P>, params: P): Promise<string> {
const locale = getMetadata(platform.metadata.locale) ?? 'en'
const compiled = cache.get(message)

if (compiled !== undefined) {
if (compiled instanceof Status) {
return message
Expand Down
11 changes: 5 additions & 6 deletions packages/platform/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
//

import { addStringsLoader } from './i18n'
import { platformId } from './platform'
import type { Metadata } from './metadata'
import { platformId } from './platform'

export * from './platform'
export * from './status'
export * from './event'
export * from './resource'
export * from './i18n'
export * from './metadata'
export * from './platform'
export { default } from './platform'
export * from './resource'
export * from './status'
export * from './testUtils'

addStringsLoader(platformId, async (lang: string) => {
Expand All @@ -39,5 +40,3 @@ export type URL = string
* @public
*/
export type Asset = Metadata<URL>

export { default } from './platform'
5 changes: 3 additions & 2 deletions packages/platform/src/lang/en.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"status": {
"LoadingPlugin": "Loading plugin '<b>'{plugin}'</b>'...",
"LoadingPlugin": "Loading plugin {plugin}...",
"UnknownError": "Unknown error: {message}",
"InvalidId": "Invalid Id: {id}",
"BadRequest": "Bad request",
"Forbidden": "Forbidden",
"ExpiredLink": "This invite link is expired",
"Unauthorized": "Unauthorized",
"UnknownMethod": "Unknown method: {method}",
"InternalServerError": "Internal server error"
"InternalServerError": "Internal server error",
"MaintenanceWarning": "Maintenance Scheduled in {time, plural, =1 {less a minute} other {# minutes}}"
}
}
5 changes: 3 additions & 2 deletions packages/platform/src/lang/ru.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"status": {
"LoadingPlugin": "Загрузка плагина '<b>'{plugin}'</b>'...",
"LoadingPlugin": "Загрузка плагина {plugin}...",
"UnknownError": "Неизвестная ошибка: {message}",
"InvalidId": "Некорректный Id: {id}",
"BadRequest": "Некорректный запрос",
"Forbidden": "Запрещено",
"ExpiredLink": "Ссылка истекла",
"Unauthorized": "Неавторизован",
"UnknownMethod": "Неизвестный метод: {method}",
"InternalServerError": "Внутренняя ошибка сервера"
"InternalServerError": "Внутренняя ошибка сервера",
"MaintenanceWarning": "Серверные работы запланированы через {time} минут"
}
}
3 changes: 2 additions & 1 deletion packages/platform/src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ export default plugin(platformId, {
Unauthorized: '' as StatusCode,
ExpiredLink: '' as StatusCode,
UnknownMethod: '' as StatusCode<{ method: string }>,
InternalServerError: '' as StatusCode
InternalServerError: '' as StatusCode,
MaintenanceWarning: '' as StatusCode<{ time: number }>
},
metadata: {
locale: '' as Metadata<string>
Expand Down
5 changes: 3 additions & 2 deletions packages/query/src/__tests__/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
//

import type {
AccountClient,
BackupClient,
Class,
Client,
Doc,
DocumentQuery,
Domain,
Expand All @@ -31,7 +31,7 @@ import core, { DOMAIN_TX, Hierarchy, ModelDb, TxDb } from '@hcengineering/core'
import { genMinModel } from './minmodel'

export async function connect (handler: (tx: Tx) => void): Promise<
Client &
AccountClient &
BackupClient & {
loadModel: (lastTxTime: Timestamp) => Promise<Tx[]>
}
Expand Down Expand Up @@ -63,6 +63,7 @@ BackupClient & {
findOne: async (_class, query, options) => (await findAll(_class, query, { ...options, limit: 1 })).shift(),
getHierarchy: () => hierarchy,
getModel: () => model,
getAccount: async () => ({} as unknown as any),
tx: async (tx: Tx): Promise<TxResult> => {
if (tx.objectSpace === core.space.Model) {
hierarchy.tx(tx)
Expand Down
10 changes: 7 additions & 3 deletions packages/ui/src/components/Label.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@
let _value: string | undefined = undefined

$: if (label !== undefined) {
translate(label, params ?? {}).then((r) => {
_value = r
})
translate(label, params ?? {})
.then((r) => {
_value = r
})
.catch((err) => {
console.error(err)
})
} else {
_value = label
}
Expand Down