diff --git a/api/registry/types.ts b/api/registry/types.ts index 39bb967e..180a88ff 100644 --- a/api/registry/types.ts +++ b/api/registry/types.ts @@ -1,2 +1,6 @@ export type {DLSConstructor} from '../../src/registry/common/components/dls/types'; export type {GatewayApi} from '../../src/registry'; +export type { + CheckCreateEntryAvailability, + CheckUpdateEntryAvailability, +} from '../../src/registry/common/utils/entry/types'; diff --git a/src/registry/common/functions-map.ts b/src/registry/common/functions-map.ts index e5970ea6..3933f861 100644 --- a/src/registry/common/functions-map.ts +++ b/src/registry/common/functions-map.ts @@ -7,6 +7,8 @@ import type {BulkFetchWorkbooksAllPermissions} from './entities/workbook/types'; import type {ColorPalettesAdminValidator} from './utils/color-palettes/types'; import type {CheckEmbedding} from './utils/embedding/types'; import type { + CheckCreateEntryAvailability, + CheckUpdateEntryAvailability, GetEntryAddFormattedFieldsHook, GetEntryBeforeDbRequestHook, IsNeedBypassEntryByKey, @@ -23,4 +25,6 @@ export const commonFunctionsMap = { getEntryBeforeDbRequestHook: makeFunctionTemplate(), getEntryAddFormattedFieldsHook: makeFunctionTemplate(), checkEmbedding: makeFunctionTemplate(), + checkCreateEntryAvailability: makeFunctionTemplate(), + checkUpdateEntryAvailability: makeFunctionTemplate(), } as const; diff --git a/src/registry/common/utils/entry/types.ts b/src/registry/common/utils/entry/types.ts index befbfc16..3aca7eef 100644 --- a/src/registry/common/utils/entry/types.ts +++ b/src/registry/common/utils/entry/types.ts @@ -1,6 +1,7 @@ import type {AppContext} from '@gravity-ui/nodekit'; import type {GetEntryResult} from '../../../../services/new/entry/get-entry'; +import {EntryScope} from '../../../../types/models'; export type IsNeedBypassEntryByKey = (ctx: AppContext, key?: string) => boolean; @@ -13,3 +14,15 @@ export type GetEntryAddFormattedFieldsHook = (args: { ctx: AppContext; result: GetEntryResult; }) => Promise>; + +export type CheckCreateEntryAvailability = (args: { + ctx: AppContext; + scope: EntryScope; + type: string | undefined; +}) => Promise; + +export type CheckUpdateEntryAvailability = (args: { + ctx: AppContext; + scope: EntryScope; + type: string | undefined; +}) => Promise; diff --git a/src/services/entry.service.ts b/src/services/entry.service.ts index cb9aa9c6..52b1b82a 100644 --- a/src/services/entry.service.ts +++ b/src/services/entry.service.ts @@ -41,6 +41,11 @@ export default class EntryService { initialParentId, ctx, }: ST.CreateEntry) { + const registry = ctx.get('registry'); + const {checkCreateEntryAvailability} = registry.common.functions.get(); + + await checkCreateEntryAvailability({ctx, scope, type}); + if (workbookId) { return await createEntryInWorkbook(ctx, { workbookId, @@ -106,6 +111,11 @@ export default class EntryService { initialParentId, ctx, }: ST.CreateEntry) { + const registry = ctx.get('registry'); + const {checkCreateEntryAvailability} = registry.common.functions.get(); + + await checkCreateEntryAvailability({ctx, scope, type}); + if (workbookId) { return await createEntryInWorkbook(ctx, { workbookId, diff --git a/src/services/entry/actions/update-entry.ts b/src/services/entry/actions/update-entry.ts index 338381d7..ce3546ae 100644 --- a/src/services/entry/actions/update-entry.ts +++ b/src/services/entry/actions/update-entry.ts @@ -147,11 +147,19 @@ export async function updateEntry(ctx: CTX, updateData: UpdateEntryData) { .timeout(DEFAULT_QUERY_TIMEOUT); if (entry) { + let checkEntryPromise; + if (!isPrivateRoute && !entry.workbookId) { - await checkEntry(ctx, Entry.replica, {verifiableEntry: entry}); + checkEntryPromise = checkEntry(ctx, Entry.replica, {verifiableEntry: entry}); } - await Lock.checkLock({entryId, lockToken}, ctx); + const {checkUpdateEntryAvailability} = registry.common.functions.get(); + + await Promise.all([ + checkEntryPromise, + Lock.checkLock({entryId, lockToken}, ctx), + checkUpdateEntryAvailability({ctx, scope: entry.scope, type: entry.type}), + ]); } else { throw new AppError(US_ERRORS.NOT_EXIST_ENTRY, { code: US_ERRORS.NOT_EXIST_ENTRY,