uberf-10255: migrate accounts in saved filters (#8846)

This commit is contained in:
Alexey Zinoviev 2025-05-06 06:12:41 +04:00 committed by GitHub
parent 6ffb641b91
commit 70dc3f4387
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 84 additions and 4 deletions

4
.vscode/launch.json vendored
View File

@ -459,14 +459,14 @@
"MINIO_ENDPOINT": "localhost:9000",
"TRANSACTOR_URL": "ws://localhost:3332",
"ACCOUNTS_URL": "http://localhost:3000",
"ACCOUNT_DB_URL": "mongodb://localhost:27017",
"ACCOUNT_DB_URL": "postgresql://root@huly.local:26257/defaultdb?sslmode=disable",
// "ACCOUNT_DB_URL": "postgresql://postgres:example@localhost:5433",
// "DB_URL": "postgresql://postgres:example@localhost:5433",
"DB_URL": "postgresql://root@huly.local:26257/defaultdb?sslmode=disable",
"MONGO_URL": "mongodb://localhost:27017",
"TELEGRAM_DATABASE": "telegram-service",
"REKONI_URL": "http://localhost:4004",
"MODEL_VERSION": "0.7.1"
"MODEL_VERSION": "0.7.75"
},
"runtimeArgs": ["--nolazy", "-r", "ts-node/register"],
"sourceMaps": true,

View File

@ -23,8 +23,8 @@ import {
} from '@hcengineering/model'
import { DOMAIN_PREFERENCE } from '@hcengineering/preference'
import view, { type Filter, type FilteredView, type ViewletPreference, viewId } from '@hcengineering/view'
import { getSocialKeyByOldAccount, getUniqueAccounts } from '@hcengineering/model-core'
import { type AccountUuid, MeasureMetricsContext } from '@hcengineering/core'
import { getSocialIdFromOldAccount, getSocialKeyByOldAccount, getUniqueAccounts } from '@hcengineering/model-core'
import core, { type AccountUuid, MeasureMetricsContext, type PersonId } from '@hcengineering/core'
import { DOMAIN_VIEW } from '.'
@ -171,6 +171,81 @@ async function migrateSocialIdsToGlobalAccounts (client: MigrationClient): Promi
ctx.info('finished processing view filtered view users ', {})
}
async function migrateAccsInSavedFilters (client: MigrationClient): Promise<void> {
const ctx = new MeasureMetricsContext('view migrateAccsInSavedFilters', {})
const hierarchy = client.hierarchy
const socialKeyByAccount = await getSocialKeyByOldAccount(client)
const socialIdBySocialKey = new Map<string, PersonId | null>()
const socialIdByOldAccount = new Map<string, PersonId | null>()
ctx.info('processing view filtered view accounts in filters ', {})
const affectedViews = await client.find<FilteredView>(DOMAIN_VIEW, {
_class: view.class.FilteredView,
filters: { $regex: '%core:class:Account%' }
})
for (const view of affectedViews) {
const filters = JSON.parse(view.filters)
const newFilters = []
let needUpdate = false
for (const filter of filters) {
const key = filter?.key
if (key == null) {
newFilters.push(filter)
continue
}
const type = key.attribute?.type
const objClass = key._class
const objKey = key.key
if (type == null || objClass == null || objKey == null) {
newFilters.push(filter)
continue
}
if (type._class !== 'core:class:RefTo' || type.to !== 'core:class:Account') {
newFilters.push(filter)
continue
}
const newAttrType = hierarchy.getAttribute(objClass, objKey)
if (newAttrType.type._class !== core.class.TypePersonId) {
newFilters.push(filter)
continue
}
const newFilter = { ...filter }
newFilter.key.attribute.type = {
_class: newAttrType.type._class,
label: newAttrType.type.label
}
const oldValue = newFilter.value
newFilter.value = []
for (const accId of oldValue) {
const socialId = await getSocialIdFromOldAccount(
client,
accId,
socialKeyByAccount,
socialIdBySocialKey,
socialIdByOldAccount
)
newFilter.value.push(socialId ?? accId)
}
newFilters.push(newFilter)
needUpdate = true
}
if (needUpdate) {
await client.update(DOMAIN_VIEW, { _id: view._id }, { filters: JSON.stringify(newFilters) })
}
}
ctx.info('finished processing view filtered view accounts in filters ', {})
}
export const viewOperation: MigrateOperation = {
async migrate (client: MigrationClient, mode): Promise<void> {
await tryMigrate(mode, client, viewId, [
@ -193,6 +268,11 @@ export const viewOperation: MigrateOperation = {
state: 'social-ids-to-global-accounts',
mode: 'upgrade',
func: migrateSocialIdsToGlobalAccounts
},
{
state: 'accs-in-saved-filters',
mode: 'upgrade',
func: migrateAccsInSavedFilters
}
])
},