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

Add tenantId param to checkCreateEntryAvailability and checkUpdateEntryAvailability #225

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/registry/common/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {Workbook} from './entities/workbook/workbook';
import {colorPalettesAdminValidator} from './utils/color-palettes/utils';
import {checkEmbedding} from './utils/embedding/utils';
import {
checkCreateEntryAvailability,
checkUpdateEntryAvailability,
getEntryAddFormattedFieldsHook,
getEntryBeforeDbRequestHook,
isNeedBypassEntryByKey,
Expand All @@ -33,5 +35,7 @@ export const registerCommonPlugins = () => {
getEntryBeforeDbRequestHook,
getEntryAddFormattedFieldsHook,
checkEmbedding,
checkCreateEntryAvailability,
checkUpdateEntryAvailability,
});
};
2 changes: 2 additions & 0 deletions src/registry/common/utils/entry/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ export type GetEntryAddFormattedFieldsHook = (args: {

export type CheckCreateEntryAvailability = (args: {
ctx: AppContext;
tenantId: string;
scope: EntryScope;
type: string | undefined;
}) => Promise<void>;

export type CheckUpdateEntryAvailability = (args: {
ctx: AppContext;
tenantId: string;
scope: EntryScope;
type: string | undefined;
}) => Promise<void>;
6 changes: 6 additions & 0 deletions src/registry/common/utils/entry/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type {
CheckCreateEntryAvailability,
CheckUpdateEntryAvailability,
GetEntryAddFormattedFieldsHook,
GetEntryBeforeDbRequestHook,
IsNeedBypassEntryByKey,
Expand All @@ -10,3 +12,7 @@ export const getEntryBeforeDbRequestHook: GetEntryBeforeDbRequestHook = () => Pr

export const getEntryAddFormattedFieldsHook: GetEntryAddFormattedFieldsHook = () =>
Promise.resolve({});

export const checkCreateEntryAvailability: CheckCreateEntryAvailability = () => Promise.resolve();

export const checkUpdateEntryAvailability: CheckUpdateEntryAvailability = () => Promise.resolve();
21 changes: 11 additions & 10 deletions src/services/entry.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ export default class EntryService {
initialParentId,
ctx,
}: ST.CreateEntry) {
const {requestId, tenantId, user, dlContext, isPrivateRoute} = ctx.get('info');

const registry = ctx.get('registry');
const {checkCreateEntryAvailability} = registry.common.functions.get();

await checkCreateEntryAvailability({ctx, scope, type});
await checkCreateEntryAvailability({ctx, tenantId, scope, type});

if (workbookId) {
return await createEntryInWorkbook(ctx, {
Expand All @@ -63,8 +65,6 @@ export default class EntryService {
});
}

const {requestId, tenantId, user, dlContext, isPrivateRoute} = ctx.get('info');

return await Entry.create(
{
requestId,
Expand Down Expand Up @@ -111,10 +111,17 @@ export default class EntryService {
initialParentId,
ctx,
}: ST.CreateEntry) {
const {
requestId,
tenantId,
dlContext,
// TODO: Send isPrivateRoute. The issue is that the backend takes dl_config from the public and private APIs.
} = ctx.get('info');

const registry = ctx.get('registry');
const {checkCreateEntryAvailability} = registry.common.functions.get();

await checkCreateEntryAvailability({ctx, scope, type});
await checkCreateEntryAvailability({ctx, tenantId, scope, type});

if (workbookId) {
return await createEntryInWorkbook(ctx, {
Expand All @@ -133,12 +140,6 @@ export default class EntryService {
});
}

const {
requestId,
tenantId,
dlContext,
// TODO: Send isPrivateRoute. The issue is that the backend takes dl_config from the public and private APIs.
} = ctx.get('info');
const requestedBy = {
userId: SYSTEM_USER.ID,
login: SYSTEM_USER.LOGIN,
Expand Down
7 changes: 6 additions & 1 deletion src/services/entry/actions/update-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,12 @@ export async function updateEntry(ctx: CTX, updateData: UpdateEntryData) {
await Promise.all([
checkEntryPromise,
Lock.checkLock({entryId, lockToken}, ctx),
checkUpdateEntryAvailability({ctx, scope: entry.scope, type: entry.type}),
checkUpdateEntryAvailability({
ctx,
tenantId: entry.tenantId,
scope: entry.scope,
type: entry.type,
}),
]);
} else {
throw new AppError(US_ERRORS.NOT_EXIST_ENTRY, {
Expand Down
Loading