Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into staging
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
  • Loading branch information
haiodo committed Dec 25, 2024
2 parents f1d12e7 + d0af7a3 commit 17df8e1
Show file tree
Hide file tree
Showing 27 changed files with 130 additions and 86 deletions.
3 changes: 0 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,6 @@
"CLIENT_SECRET": "${env:POD_GITHUB_CLIENT_SECRET}",
"PRIVATE_KEY": "${env:POD_GITHUB_PRIVATE_KEY}",
"COLLABORATOR_URL": "ws://localhost:3078",
"SYSTEM_EMAIL": "anticrm@hc.engineering",
"MINIO_ENDPOINT": "localhost",
"MINIO_ACCESS_KEY": "minioadmin",
"MINIO_SECRET_KEY": "minioadmin",
Expand All @@ -463,7 +462,6 @@
"args": ["src/index.ts"],
"env": {
"ACCOUNTS_URL": "http://localhost:3000",
"SYSTEM_EMAIL": "anticrm@hc.engineering",
"SECRET": "secret",
"DOCS_RELEASE_INTERVAL": "10000",
"DOCS_IN_REVIEW_CHECK_INTERVAL": "10000",
Expand Down Expand Up @@ -523,7 +521,6 @@
"MINIO_ACCESS_KEY": "minioadmin",
"MINIO_SECRET_KEY": "minioadmin",
"SERVICE_ID": "sign-service",
"SYSTEM_EMAIL": "",
"ACCOUNTS_URL": "http://localhost:3000",
"BRANDING_PATH": "${workspaceRoot}/services/sign/pod-sign/debug/branding.json"
},
Expand Down
2 changes: 1 addition & 1 deletion dev/tool/src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async function moveWorkspace (
tables = tables.filter((t) => include.has(t))
}

await createTables(new MeasureMetricsContext('', {}), pgClient, tables)
await createTables(new MeasureMetricsContext('', {}), pgClient, '', tables)
const token = generateToken(systemAccountEmail, wsId)
const endpoint = await getTransactorEndpoint(token, 'external')
const connection = (await connect(endpoint, wsId, undefined, {
Expand Down
12 changes: 8 additions & 4 deletions models/recruit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,8 @@ export function createModel (builder: Builder): void {
viewOptions: {
groupBy: [],
orderBy: [],
other: [vacancyHideArchivedOption]
other: [vacancyHideArchivedOption],
storageKey: 'vacancyViewOptions'
}
},
recruit.viewlet.TableVacancy
Expand Down Expand Up @@ -502,7 +503,8 @@ export function createModel (builder: Builder): void {
viewOptions: {
groupBy: [],
orderBy: [],
other: [applicationDoneOption, hideApplicantsFromArchivedVacanciesOption]
other: [applicationDoneOption, hideApplicantsFromArchivedVacanciesOption],
storageKey: 'applicantViewOptions'
}
},
recruit.viewlet.ApplicantTable
Expand Down Expand Up @@ -559,7 +561,8 @@ export function createModel (builder: Builder): void {
action: view.function.ShowEmptyGroups,
label: view.string.ShowEmptyGroups
}
]
],
storageKey: 'applicantViewOptions'
}
if (colors) {
model.other.push(showColorsViewOption)
Expand Down Expand Up @@ -784,7 +787,8 @@ export function createModel (builder: Builder): void {
['modifiedOn', SortingOrder.Descending],
['createdOn', SortingOrder.Descending]
],
other: [vacancyHideArchivedOption]
other: [vacancyHideArchivedOption],
storageKey: 'vacancyViewOptions'
}
},
recruit.viewlet.ListVacancy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
-->
<script lang="ts">
import { Attachment } from '@hcengineering/attachment'
import { Account, Class, Doc, IdMap, Markup, Ref, Space, generateId, toIdMap } from '@hcengineering/core'
import { RateLimiter, Account, Class, Doc, IdMap, Markup, Ref, Space, generateId, toIdMap } from '@hcengineering/core'
import { Asset, IntlString, setPlatformStatus, unknownError } from '@hcengineering/platform'
import {
DraftController,
Expand Down Expand Up @@ -183,26 +183,31 @@
await tick()
const list = inputFile.files
if (list === null || list.length === 0) return
const limiter = new RateLimiter(10)
for (let index = 0; index < list.length; index++) {
const file = list.item(index)
if (file !== null) {
await createAttachment(file)
await limiter.add(() => createAttachment(file))
}
}
await limiter.waitProcessing()
inputFile.value = ''
progress = false
}
async function fileDrop (e: DragEvent): Promise<void> {
progress = true
const list = e.dataTransfer?.files
const limiter = new RateLimiter(10)
if (list === undefined || list.length === 0) return
for (let index = 0; index < list.length; index++) {
const file = list.item(index)
if (file !== null) {
await createAttachment(file)
await limiter.add(() => createAttachment(file))
}
}
await limiter.waitProcessing()
progress = false
}
Expand Down Expand Up @@ -257,17 +262,17 @@
return
}
saved = true
const promises: Promise<any>[] = []
const limiter = new RateLimiter(10)
newAttachments.forEach((p) => {
const attachment = attachments.get(p)
if (attachment !== undefined) {
promises.push(saveAttachment(attachment))
void limiter.add(() => saveAttachment(attachment))
}
})
removedAttachments.forEach((p) => {
promises.push(deleteAttachment(p))
void limiter.add(() => deleteAttachment(p))
})
await Promise.all(promises)
await limiter.waitProcessing()
newAttachments.clear()
removedAttachments.clear()
saveDraft()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export function adjustSelectionIndent (
let insertionOffset = 0

for (const range of ranges) {
if (direction > 0 ? range.text === '' : range.indent === 0) {
if (direction > 0 ? range.text === '' && ranges.length > 1 : range.indent === 0) {
continue
}
const indentOffset = indentLevelOffset(range.indent, direction)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ export const MermaidExtension = CodeBlockLowlight.extend<MermaidOptions>({
},

addProseMirrorPlugins () {
return [...(this.parent?.() ?? []), MermaidDecorator(this.options)]
const parent = (this.parent?.() ?? []).filter((p) => p.props.handlePaste === undefined)
return [...parent, MermaidDecorator(this.options)]
},

addNodeView () {
Expand Down
21 changes: 15 additions & 6 deletions plugins/view-resources/src/viewOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@ export function isDropdownType (viewOption: ViewOptionModel): viewOption is Drop
return viewOption.type === 'dropdown'
}

export function makeViewOptionsKey (viewlet: Ref<Viewlet>, variant?: string): string {
const prefix = viewlet + (variant !== undefined ? `-${variant}` : '')
function makeViewOptionsKey (viewlet: Viewlet, variant?: string, ignoreViewletKey = false): string {
const prefix =
viewlet.viewOptions?.storageKey !== undefined && !ignoreViewletKey
? viewlet.viewOptions.storageKey
: viewlet._id + (variant !== undefined ? `-${variant}` : '')
const loc = getCurrentResolvedLocation()
loc.fragment = undefined
loc.query = undefined
return `viewOptions:${prefix}:${locationToUrl(loc)}`
}

export function setViewOptions (viewlet: Viewlet, options: ViewOptions): void {
const key = makeViewOptionsKey(viewlet._id, viewlet.variant)
const key = makeViewOptionsKey(viewlet, viewlet.variant)
localStorage.setItem(key, JSON.stringify(options))
setStore(key, options)
}
Expand All @@ -52,13 +55,19 @@ function setStore (key: string, options: ViewOptions): void {
}

function _getViewOptions (viewlet: Viewlet, viewOptionStore: Map<string, ViewOptions>): ViewOptions | null {
const key = makeViewOptionsKey(viewlet._id, viewlet.variant)
const key = makeViewOptionsKey(viewlet, viewlet.variant)
const store = viewOptionStore.get(key)
if (store !== undefined) {
return store
}
const options = localStorage.getItem(key)
if (options === null) return null
let options = localStorage.getItem(key)
if (options === null) {
const key = makeViewOptionsKey(viewlet, viewlet.variant, true)
options = localStorage.getItem(key)
if (options === null) {
return null
}
}
const res = JSON.parse(options)
setStore(key, res)
return res
Expand Down
1 change: 1 addition & 0 deletions plugins/view/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ export interface ViewOptionsModel {
orderBy: OrderOption[]
other: ViewOptionModel[]
groupDepth?: number
storageKey?: string
}

/**
Expand Down
33 changes: 26 additions & 7 deletions server-plugins/love-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,10 @@ export async function OnUserStatus (txes: Tx[], control: TriggerControl): Promis
async function roomJoinHandler (info: ParticipantInfo, control: TriggerControl): Promise<Tx[]> {
const roomInfos = await control.queryFind(control.ctx, love.class.RoomInfo, {})
const roomInfo = roomInfos.find((ri) => ri.room === info.room)
if (roomInfo !== undefined) {
roomInfo.persons.push(info.person)
if (roomInfo !== undefined && !roomInfo.persons.includes(info.person)) {
return [
control.txFactory.createTxUpdateDoc(love.class.RoomInfo, core.space.Workspace, roomInfo._id, {
persons: Array.from(new Set([...roomInfo.persons, info.person]))
$push: { persons: info.person }
})
]
} else {
Expand Down Expand Up @@ -221,7 +220,6 @@ async function setDefaultRoomAccess (info: ParticipantInfo, control: TriggerCont
const roomInfos = await control.queryFind(control.ctx, love.class.RoomInfo, {})
const oldRoomInfo = roomInfos.find((ri) => ri.persons.includes(info.person))
if (oldRoomInfo !== undefined) {
oldRoomInfo.persons = oldRoomInfo.persons.filter((p) => p !== info.person)
if (oldRoomInfo.persons.length === 0) {
res.push(control.txFactory.createTxRemoveDoc(oldRoomInfo._class, oldRoomInfo.space, oldRoomInfo._id))

Expand All @@ -237,7 +235,7 @@ async function setDefaultRoomAccess (info: ParticipantInfo, control: TriggerCont
} else {
res.push(
control.txFactory.createTxUpdateDoc(love.class.RoomInfo, core.space.Workspace, oldRoomInfo._id, {
persons: oldRoomInfo.persons
$pull: { persons: info.person }
})
)
}
Expand Down Expand Up @@ -433,23 +431,44 @@ async function isRoomEmpty (
return false
}

function combineAttributes (attributes: any[], key: string, operator: string, arrayKey: string): any[] {
return Array.from(
new Set(
attributes.flatMap((attr) =>
Array.isArray(attr[operator]?.[key]?.[arrayKey]) ? attr[operator]?.[key]?.[arrayKey] : attr[operator]?.[key]
)
)
).filter((v) => v != null)
}

async function OnRoomInfo (txes: TxCUD<RoomInfo>[], control: TriggerControl): Promise<Tx[]> {
const result: Tx[] = []
const personsByRoom = new Map<Ref<RoomInfo>, Ref<Person>[]>()
for (const tx of txes) {
if (tx._class === core.class.TxRemoveDoc) {
const roomInfo = control.removedMap.get(tx.objectId) as RoomInfo
if (roomInfo === undefined) continue
if (roomInfo.room === love.ids.Reception) continue
personsByRoom.delete(tx.objectId)
result.push(...(await finishRoomMeetings(roomInfo.room, tx.modifiedOn, control)))
continue
}
if (tx._class === core.class.TxUpdateDoc) {
const newPersons = (tx as TxUpdateDoc<RoomInfo>).operations.persons
if (newPersons === undefined) continue
const updateTx = tx as TxUpdateDoc<RoomInfo>
const pulled = combineAttributes([updateTx.operations], 'persons', '$pull', '$in')
const pushed = combineAttributes([updateTx.operations], 'persons', '$push', '$each')

if (pulled.length === 0 && pushed.length === 0) continue
const roomInfos = await control.queryFind(control.ctx, love.class.RoomInfo, {})
const roomInfo = roomInfos.find((r) => r._id === tx.objectId)
if (roomInfo === undefined) continue
if (roomInfo.room === love.ids.Reception) continue

const currentPersons = personsByRoom.get(tx.objectId) ?? roomInfo.persons
const newPersons = currentPersons.filter((p) => !pulled.includes(p)).concat(pushed)

personsByRoom.set(tx.objectId, newPersons)

if (await isRoomEmpty(roomInfo.room, roomInfo.isOffice, newPersons, control)) {
result.push(...(await finishRoomMeetings(roomInfo.room, tx.modifiedOn, control)))
}
Expand Down
3 changes: 1 addition & 2 deletions server/account/src/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,7 @@ export async function createAcc (
const salt = randomBytes(32)
const hash = password !== null ? hashWithSalt(password, salt) : null

const systemEmails = [systemAccountEmail]
if (systemEmails.includes(email)) {
if (systemAccountEmail === email) {
ctx.error('system email used for account', { email })
throw new PlatformError(new Status(Severity.ERROR, platform.status.AccountAlreadyExists, { account: email }))
}
Expand Down
13 changes: 11 additions & 2 deletions server/postgres/src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import core, {
type ModelDb,
type ObjQueryType,
type Projection,
RateLimiter,
type Ref,
type ReverseLookups,
type SessionData,
Expand Down Expand Up @@ -1506,13 +1507,18 @@ interface OperationBulk {
mixins: TxMixin<Doc, Doc>[]
}

const initRateLimit = new RateLimiter(1)

class PostgresAdapter extends PostgresAdapterBase {
async init (ctx: MeasureContext, domains?: string[], excludeDomains?: string[]): Promise<void> {
let resultDomains = domains ?? this.hierarchy.domains()
if (excludeDomains !== undefined) {
resultDomains = resultDomains.filter((it) => !excludeDomains.includes(it))
}
await createTables(ctx, this.client, resultDomains)
const url = this.refClient.url()
await initRateLimit.exec(async () => {
await createTables(ctx, this.client, url, resultDomains)
})
this._helper.domains = new Set(resultDomains as Domain[])
}

Expand Down Expand Up @@ -1789,7 +1795,10 @@ class PostgresAdapter extends PostgresAdapterBase {
class PostgresTxAdapter extends PostgresAdapterBase implements TxAdapter {
async init (ctx: MeasureContext, domains?: string[], excludeDomains?: string[]): Promise<void> {
const resultDomains = domains ?? [DOMAIN_TX, DOMAIN_MODEL_TX]
await createTables(ctx, this.client, resultDomains)
await initRateLimit.exec(async () => {
const url = this.refClient.url()
await createTables(ctx, this.client, url, resultDomains)
})
this._helper.domains = new Set(resultDomains as Domain[])
}

Expand Down
Loading

0 comments on commit 17df8e1

Please sign in to comment.