Skip to content

Commit

Permalink
Fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey-weber committed Nov 21, 2024
2 parents 42dafcd + 65da9a5 commit 974bde7
Show file tree
Hide file tree
Showing 40 changed files with 61 additions and 37 deletions.
2 changes: 2 additions & 0 deletions api/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ export type {FeaturesConfig} from '../src/components/features/types';
export {isGatewayError} from '../src/components/gateway';

export {resolvePrivatePermissions} from '../src/components/private-permissions';

export {setRegistryToContext} from '../src/components/app-context';
6 changes: 6 additions & 0 deletions src/components/app-context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type {NodeKit} from '@gravity-ui/nodekit';
import type {Registry} from '../registry';

export function setRegistryToContext<R extends Registry>(nodekit: NodeKit, registry: R) {
nodekit.ctx.set('registry', registry as any);
}
7 changes: 6 additions & 1 deletion src/db/models/entry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {AppError} from '@gravity-ui/nodekit';
import * as MT from '../../../types/models';
import {validateCreateEntry, validateResolveTenantIdByEntryId} from './scheme';
import {RETURN_COLUMNS, BiTrackingLogs, US_ERRORS} from '../../../const';
import {registry} from '../../../registry';

interface Entry extends MT.EntryColumns {
revisions: any; // TODO: Figure out how to type a upsertGraph
Expand Down Expand Up @@ -188,6 +187,8 @@ class Entry extends Model {
dlContext,
});

const registry = ctx.get('registry');

const {DLS} = registry.common.classes.get();

const isDeleted = false;
Expand Down Expand Up @@ -578,6 +579,8 @@ class Entry extends Model {
isPrivateRoute,
});

const registry = ctx.get('registry');

const {DLS} = registry.common.classes.get();

const result = await transaction(this.primary, async (trx) => {
Expand Down Expand Up @@ -691,6 +694,8 @@ class Entry extends Model {
ctx,
trx,
}: MT.CheckExistenceEntriesWithInsufficientPermissions): Promise<boolean> {
const registry = ctx.get('registry');

const {DLS} = registry.common.classes.get();

const entriesWithPermissionsInfo = await DLS.checkBulkPermission(
Expand Down
2 changes: 1 addition & 1 deletion src/db/models/favorite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
validateRenameFavorite,
} from './scheme';
import {RETURN_FAVORITES_COLUMNS, US_ERRORS} from '../../../const';
import {registry} from '../../../registry';

import {getWorkbook} from '../../../services/new/workbook';
import {filterEntriesByPermission} from '../../../services/new/entry/utils';
Expand Down Expand Up @@ -174,6 +173,7 @@ class Favorite extends Model {
dlContext,
});

const registry = ctx.get('registry');
const {DLS} = registry.common.classes.get();

const {login} = requestedBy;
Expand Down
2 changes: 1 addition & 1 deletion src/db/models/lock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {AppContext, AppError} from '@gravity-ui/nodekit';
import * as MT from '../../../types/models';
import US_ERRORS from '../../../const/us-error-constants';
import {CURRENT_TIMESTAMP} from '../../../const';
import {registry} from '../../../registry';
import {Entry} from '../new/entry';
import {WorkbookPermission} from '../../../entities/workbook';
import {getWorkbook} from '../../../services/new/workbook';
Expand Down Expand Up @@ -82,6 +81,7 @@ class Lock extends Model {
tenantId: string;
permission: 'read' | 'edit';
}) {
const registry = ctx.get('registry');
const {accessServiceEnabled} = ctx.config;

const entry = await Entry.query(Entry.replica)
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import {
import {AppEnv} from './const';
import {registry} from './registry';
import {getRoutes} from './routes';
import {setRegistryToContext} from './components/app-context';

setRegistryToContext(nodekit, registry);
registerAppPlugins();

const beforeAuth: AppMiddleware[] = [];
Expand Down
2 changes: 2 additions & 0 deletions src/registry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@ export const registry = {
},
common: commonRegistry,
};

export type Registry = typeof registry;
2 changes: 1 addition & 1 deletion src/services/color-palettes/create-color-palette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {ServiceArgs} from '../../services/new/types';
import {makeSchemaValidator} from '../../components/validation-schema-compiler';
import {ColorPaletteModel, ColorPaletteModelColumn} from '../../db/models/new/color-palette';
import Utils from '../../utils';
import {registry} from '../../registry';
import {getColorPalettesCount} from './get-color-palettes-count';
import {US_ERRORS} from '../../const';

Expand Down Expand Up @@ -53,6 +52,7 @@ export const createColorPalette = async (
isDefault,
});

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

if (!skipValidation) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/color-palettes/delete-color-palette.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {ServiceArgs} from '../../services/new/types';
import {makeSchemaValidator} from '../../components/validation-schema-compiler';
import {ColorPaletteModel, ColorPaletteModelColumn} from '../../db/models/new/color-palette';
import {registry} from '../../registry';

const validateArgs = makeSchemaValidator({
type: 'object',
Expand All @@ -27,6 +26,7 @@ export const deleteColorPalette = async (
colorPaletteId,
});

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

if (!skipValidation) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/entry/actions/copy-to-workbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {WorkbookModel} from '../../../db/models/new/workbook';
import {CTX} from '../../../types/models';
import {US_ERRORS, BiTrackingLogs} from '../../../const';
import Utils, {makeUserId} from '../../../utils';
import {registry} from '../../../registry';
import {WorkbookPermission} from '../../../entities/workbook';
import {getParentIds} from '../../new/collection/utils/get-parents';

Expand Down Expand Up @@ -78,6 +77,7 @@ export const copyToWorkbook = async (ctx: CTX, params: Params) => {
validateParams(params);

const {tenantId, user} = ctx.get('info');
const registry = ctx.get('registry');
const createdBy = makeUserId(user.userId);

const targetTenantId = tenantIdOverride ?? tenantId;
Expand Down
2 changes: 1 addition & 1 deletion src/services/entry/actions/delete-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {checkWorkbookPermission} from '../../new/workbook/utils';
import {markEntryAsDeleted} from '../crud';
import {checkEntry} from './check-entry';
import {ServiceArgs} from '../../new/types';
import {registry} from '../../../registry';

const validateArgs = makeSchemaValidator({
type: 'object',
Expand Down Expand Up @@ -47,6 +46,7 @@ export async function deleteEntry(
lockToken,
});

const registry = ctx.get('registry');
const {DLS} = registry.common.classes.get();

if (!skipValidation) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/entry/actions/get-entry-by-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {RETURN_COLUMNS, DEFAULT_QUERY_TIMEOUT, US_ERRORS} from '../../../const';
import Utils from '../../../utils';
import {makeSchemaValidator} from '../../../components/validation-schema-compiler';
import {checkEntry} from './check-entry';
import {registry} from '../../../registry';

const validateGetEntryByKey = makeSchemaValidator({
type: 'object',
Expand Down Expand Up @@ -53,6 +52,7 @@ export async function getEntryByKey(
customErrorBypassEnabled = false,
}: GetEntryByKeyData,
) {
const registry = ctx.get('registry');
const {tenantId, isPrivateRoute: infoIsPrivateRoute} = ctx.get('info');
const isPrivateRoute = customIsPrivateRoute || infoIsPrivateRoute;

Expand Down
6 changes: 3 additions & 3 deletions src/services/entry/actions/get-entry-relations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {makeSchemaValidator} from '../../../components/validation-schema-compile
import {getWorkbook} from '../../new/workbook/get-workbook';
import {getEntryPermissionsByWorkbook} from '../../new/workbook/utils';
import {getRelatedEntries, RelationDirection} from './get-related-entries';
import {registry} from '../../../registry';
import {getReplica} from '../../new/utils';
import {EntryScope} from '../../../db/models/new/entry/types';

Expand Down Expand Up @@ -55,10 +54,11 @@ export async function getEntryRelations(
{ctx, trx, skipValidation = false}: ServiceArgs,
args: GetEntryRelationsArgs,
) {
const {DLS} = registry.common.classes.get();

const registry = ctx.get('registry');
const {tenantId, isPrivateRoute} = ctx.get('info');

const {DLS} = registry.common.classes.get();

const {
entryId,
scope,
Expand Down
2 changes: 1 addition & 1 deletion src/services/entry/actions/get-entry-revisions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import Utils from '../../../utils';
import {checkEntry} from './check-entry';
import {getWorkbook} from '../../new/workbook';
import {ServiceArgs} from '../../new/types';
import {registry} from '../../../registry';

const validateArgs = makeSchemaValidator({
type: 'object',
Expand Down Expand Up @@ -67,6 +66,7 @@ export async function getEntryRevisions(
pageSize,
});

const registry = ctx.get('registry');
const {DLS} = registry.common.classes.get();

if (!skipValidation) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/entry/actions/rename-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {getWorkbook} from '../../new/workbook/get-workbook';
import {checkWorkbookPermission} from '../../new/workbook/utils';
import {WorkbookPermission} from '../../../entities/workbook';
import {checkEntry} from './check-entry';
import {registry} from '../../../registry';

const validateRenameEntry = makeSchemaValidator({
type: 'object',
Expand Down Expand Up @@ -40,6 +39,7 @@ export const renameEntry = async (ctx: CTX, renameEntryData: RenameEntryData) =>
name,
});

const registry = ctx.get('registry');
const {DLS} = registry.common.classes.get();

const {accessServiceEnabled} = ctx.config;
Expand Down
2 changes: 1 addition & 1 deletion src/services/entry/actions/update-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {checkWorkbookPermission} from '../../new/workbook/utils';
import {WorkbookPermission} from '../../../entities/workbook';
import {Optional} from 'utility-types';
import {checkEntry} from './check-entry';
import {registry} from '../../../registry';
import {EntryScope} from '../../../db/models/new/entry/types';
import {EntryColumn} from '../../../db/models/new/entry';

Expand Down Expand Up @@ -132,6 +131,7 @@ export async function updateEntry(ctx: CTX, updateData: UpdateEntryData) {
updateRevision,
});

const registry = ctx.get('registry');
const {DLS} = registry.common.classes.get();

const {accessServiceEnabled} = ctx.config;
Expand Down
3 changes: 2 additions & 1 deletion src/services/new/collection/create-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {transaction} from 'objection';
import {US_ERRORS} from '../../../const';
import {CollectionModel, CollectionModelColumn} from '../../../db/models/new/collection';
import Utils from '../../../utils';
import {registry} from '../../../registry';

const validateArgs = makeSchemaValidator({
type: 'object',
Expand Down Expand Up @@ -38,6 +37,8 @@ export const createCollection = async (
) => {
const {title, description, parentId} = args;

const registry = ctx.get('registry');

ctx.log('CREATE_COLLECTION_START', {
title,
description,
Expand Down
3 changes: 2 additions & 1 deletion src/services/new/collection/get-collection-breadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {US_ERRORS} from '../../../const';
import {makeSchemaValidator} from '../../../components/validation-schema-compiler';
import Utils from '../../../utils';
import {CollectionPermission} from '../../../entities/collection';
import {registry} from '../../../registry';
import {Feature, isEnabledFeature} from '../../../components/features';

const validateArgs = makeSchemaValidator({
Expand All @@ -30,6 +29,8 @@ export const getCollectionBreadcrumbs = async (
) => {
const {collectionId, includePermissionsInfo} = args;

const registry = ctx.get('registry');

const {accessServiceEnabled} = ctx.config;

ctx.log('GET_COLLECTION_BREADCRUMBS_START', {
Expand Down
2 changes: 1 addition & 1 deletion src/services/new/collection/get-collection-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {CollectionModel, CollectionModelColumn} from '../../../db/models/new/col
import Utils from '../../../utils';
import {getWorkbooksList} from '../workbook';
import {getCollection} from './get-collection';
import {registry} from '../../../registry';
import {Feature, isEnabledFeature} from '../../../components/features';

const validateArgs = makeSchemaValidator({
Expand Down Expand Up @@ -99,6 +98,7 @@ export const getCollectionContent = async (
validateArgs(args);
}

const registry = ctx.get('registry');
const {accessServiceEnabled} = ctx.config;
const {Workbook, Collection} = registry.common.classes.get();
const {bulkFetchCollectionsAllPermissions} = registry.common.functions.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {AppError, AppContext} from '@gravity-ui/nodekit';
import {ServiceArgs} from '../types';
import {US_ERRORS} from '../../../const';
import {OrganizationPermission, ProjectPermission} from '../../../components/iam';
import {registry} from '../../../registry';
import {Feature, isEnabledFeature} from '../../../components/features';

export const getRootCollectionPermissions = async ({ctx}: ServiceArgs) => {
Expand Down Expand Up @@ -31,6 +30,7 @@ export const getRootCollectionPermissions = async ({ctx}: ServiceArgs) => {
};

async function checkCreateCollectionInRoot(ctx: AppContext) {
const registry = ctx.get('registry');
const {checkOrganizationPermission, checkProjectPermission} = registry.common.functions.get();
try {
if (isEnabledFeature(ctx, Feature.ProjectsEnabled)) {
Expand All @@ -56,6 +56,7 @@ async function checkCreateCollectionInRoot(ctx: AppContext) {
}

async function checkCreateWorkbookInRoot(ctx: AppContext) {
const registry = ctx.get('registry');
const {checkOrganizationPermission, checkProjectPermission} = registry.common.functions.get();
try {
if (isEnabledFeature(ctx, Feature.ProjectsEnabled)) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/new/collection/get-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {US_ERRORS} from '../../../const';
import {CollectionModel, CollectionModelColumn} from '../../../db/models/new/collection';
import {CollectionPermission} from '../../../entities/collection';
import Utils from '../../../utils';
import {registry} from '../../../registry';

import type {CollectionInstance} from '../../../registry/common/entities/collection/types';
import {checkAndSetCollectionPermission} from './utils';
Expand Down Expand Up @@ -73,6 +72,7 @@ export const getCollection = async <T extends CollectionInstance = CollectionIns
});
}

const registry = ctx.get('registry');
const {Collection} = registry.common.classes.get();

const collectionInstance = new Collection({
Expand Down
2 changes: 1 addition & 1 deletion src/services/new/collection/get-collections-list-by-ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {makeSchemaValidator} from '../../../components/validation-schema-compile
import {CollectionModel, CollectionModelColumn} from '../../../db/models/new/collection';
import Utils from '../../../utils';
import {makeCollectionsWithParentsMap} from './utils';
import {registry} from '../../../registry';
import {Feature, isEnabledFeature} from '../../../components/features';
import {CollectionPermission} from '../../../entities/collection';
import {CollectionInstance} from '../../../registry/common/entities/collection/types';
Expand Down Expand Up @@ -47,6 +46,7 @@ export const getCollectionsListByIds = async (
}

const {tenantId, projectId} = ctx.get('info');
const registry = ctx.get('registry');

const models = await CollectionModel.query(getReplica(trx))
.where({
Expand Down
2 changes: 1 addition & 1 deletion src/services/new/collection/move-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {raw} from 'objection';
import {CollectionModel, CollectionModelColumn} from '../../../db/models/new/collection';
import Utils from '../../../utils';
import {CollectionPermission} from '../../../entities/collection';
import {registry} from '../../../registry';
import {Feature, isEnabledFeature} from '../../../components/features';

const validateArgs = makeSchemaValidator({
Expand Down Expand Up @@ -47,6 +46,7 @@ export const moveCollection = async (
const {
user: {userId},
} = ctx.get('info');
const registry = ctx.get('registry');

ctx.log('MOVE_COLLECTION_START', {
collectionId: Utils.encodeId(collectionId),
Expand Down
3 changes: 2 additions & 1 deletion src/services/new/collection/utils/get-parents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {CollectionModel, CollectionModelColumn} from '../../../../db/models/new/
import {WorkbookInstance} from '../../../../registry/common/entities/workbook/types';
import {CollectionInstance} from '../../../../registry/common/entities/collection/types';
import {ServiceArgs} from '../../types';
import {registry} from '../../../../registry';
import {WorkbookModel} from '../../../../db/models/new/workbook';

interface Ctx {
Expand Down Expand Up @@ -128,6 +127,7 @@ export const makeWorkbooksWithParentsMap = async (

const parentsMap = makeParentsMap(parents);

const registry = ctx.get('registry');
const {Workbook} = registry.common.classes.get();

models.forEach((model) => {
Expand Down Expand Up @@ -162,6 +162,7 @@ export const makeCollectionsWithParentsMap = async (

const parentsMap = makeParentsMap(parents);

const registry = ctx.get('registry');
const {Collection} = registry.common.classes.get();

models.forEach((model) => {
Expand Down
Loading

0 comments on commit 974bde7

Please sign in to comment.