From cbbb5fd4c8d582b641301937daa162d0112d6993 Mon Sep 17 00:00:00 2001 From: Evgenij Shangin Date: Thu, 10 Oct 2024 17:01:39 +0300 Subject: [PATCH] Delete, simplify DLS types (#194) --- api/registry.ts | 1 - api/registry/index.ts | 1 + api/registry/types.ts | 1 + src/db/models/entry/index.ts | 8 ++--- src/registry/common/components/dls/dls.ts | 28 ----------------- src/registry/common/components/dls/types.ts | 33 --------------------- src/types/models/dls.ts | 32 +++++--------------- 7 files changed, 11 insertions(+), 93 deletions(-) delete mode 100644 api/registry.ts create mode 100644 api/registry/index.ts create mode 100644 api/registry/types.ts diff --git a/api/registry.ts b/api/registry.ts deleted file mode 100644 index 8a3a31e2..00000000 --- a/api/registry.ts +++ /dev/null @@ -1 +0,0 @@ -export {registry} from '../src/registry'; diff --git a/api/registry/index.ts b/api/registry/index.ts new file mode 100644 index 00000000..715c2e7c --- /dev/null +++ b/api/registry/index.ts @@ -0,0 +1 @@ +export {registry} from '../../src/registry'; diff --git a/api/registry/types.ts b/api/registry/types.ts new file mode 100644 index 00000000..6bf62be0 --- /dev/null +++ b/api/registry/types.ts @@ -0,0 +1 @@ +export type {DLSConstructor} from '../../src/registry/common/components/dls/types'; diff --git a/src/db/models/entry/index.ts b/src/db/models/entry/index.ts index ff1af01d..3538d3e5 100644 --- a/src/db/models/entry/index.ts +++ b/src/db/models/entry/index.ts @@ -377,9 +377,7 @@ class Entry extends Model { initialParentId, scope: 'folder', parentFolderKey: existedParentFolderKey, - parentFolder: { - entryId: folderKeysMap[existedParentFolderKey], - }, + parentFolderId: folderKeysMap[existedParentFolderKey], }, ); } @@ -484,9 +482,7 @@ class Entry extends Model { initialPermissions, initialParentId, parentFolderKey, - parentFolder: { - entryId: parentFolderKey === '/' ? {} : parentFolder.entryId, - }, + parentFolderId: parentFolderKey === '/' ? undefined : parentFolder.entryId, }, ); } diff --git a/src/registry/common/components/dls/dls.ts b/src/registry/common/components/dls/dls.ts index 5c627f74..96f67356 100644 --- a/src/registry/common/components/dls/dls.ts +++ b/src/registry/common/components/dls/dls.ts @@ -1,22 +1,6 @@ import {DLSConstructor} from './types'; export const DLS: DLSConstructor = class { - static fillPredefinedPermissions() { - return [] as [] | {[key: string]: object[]}; - } - - static async checkIamManagePermission() { - return true; - } - - static async checkEntriesInTenant() { - return; - } - - static prepareHeaders() { - return {}; - } - static async checkPermission() { return {}; } @@ -29,19 +13,7 @@ export const DLS: DLSConstructor = class { return {}; } - static async getPermissions() { - return {}; - } - static async modifyPermissions() { return {}; } - - static async batchPermissions() { - return []; - } - - static async suggest() { - return []; - } }; diff --git a/src/registry/common/components/dls/types.ts b/src/registry/common/components/dls/types.ts index 93809c64..c0da7315 100644 --- a/src/registry/common/components/dls/types.ts +++ b/src/registry/common/components/dls/types.ts @@ -5,25 +5,6 @@ import * as MT from '../../../../types/models'; export interface DLSConstructor { new (): {}; - fillPredefinedPermissions: ( - userIdDLS: string, - initialPermissions: [], - ctx: AppContext, - ) => [] | {[key: string]: object[]}; - - checkIamManagePermission: (ctx: AppContext) => Promise; - - checkEntriesInTenant: ( - {ctx, trx}: {ctx: AppContext; trx?: TransactionOrKnex}, - entryIds: string[], - ) => Promise; - - prepareHeaders: ( - ctx: AppContext, - requestId: string, - hasIamManagePermission: boolean, - ) => Record; - checkPermission: ( {ctx, trx}: {ctx: AppContext; trx?: TransactionOrKnex}, checkPermissionsArgs: MT.CheckPermissionDlsConfig, @@ -32,7 +13,6 @@ export interface DLSConstructor { checkBulkPermission( {ctx, trx}: {ctx: AppContext; trx?: TransactionOrKnex}, checkBulkPermissionArgs: MT.CheckBulkPermissionsDlsConfig, - skipEntriesInTenantCheck?: boolean, ): Promise; addEntity( @@ -40,21 +20,8 @@ export interface DLSConstructor { addEntityArgs: MT.CreationDlsEntityConfig, ): Promise; - getPermissions( - {ctx, trx}: {ctx: AppContext; trx?: TransactionOrKnex}, - getPermissionsArgs: MT.GetPermissionDlsConfig, - ): Promise; - modifyPermissions( {ctx, trx}: {ctx: AppContext; trx?: TransactionOrKnex}, modifyPermissionsArgs: MT.ModifyPermissionDlsConfig, - preparedHasIamManagePermission?: boolean, - ): Promise; - - batchPermissions( - {ctx, trx}: {ctx: AppContext; trx?: TransactionOrKnex}, - batchPermissionsArgs: MT.BatchPermissionDlsConfig, ): Promise; - - suggest(cx: AppContext, suggestArgs: MT.GetSuggestDlsConfig): Promise; } diff --git a/src/types/models/dls.ts b/src/types/models/dls.ts index 6627ef83..c3acca7d 100644 --- a/src/types/models/dls.ts +++ b/src/types/models/dls.ts @@ -1,5 +1,4 @@ /* eslint-disable camelcase */ -import {EntryScope} from './entry'; import {UsPermission} from './permission'; export enum DlsActions { @@ -23,22 +22,18 @@ export interface DlsPermission { export type DlsPermissionsMode = 'explicit' | 'parent_and_owner' | 'owner_only'; export interface CreationDlsEntityConfig { entryId: string; - scope: EntryScope; + scope: string; permissionsMode?: DlsPermissionsMode; initialPermissions?: any; initialParentId?: string; parentFolderKey?: string; - parentFolder?: any; + parentFolderId?: string; } export interface CheckPermissionDlsConfig { entryId: string; action: string; - bypassEmitErrorEnabled?: boolean; includePermissionsInfo?: boolean; } -export interface GetPermissionDlsConfig { - entryId: string; -} export interface DlsPermissionSubject { subject: string; @@ -53,14 +48,14 @@ interface DlsModifyPermissionSubject extends DlsPermissionSubject { } export type DlsPermissionDiff = { - [permission in DlsPermissions]?: DlsPermissionSubject[]; + [permission in `${DlsPermissions}`]?: DlsPermissionSubject[]; }; export type DlsModifyPermissionDiff = { - [permission in DlsPermissions]?: DlsModifyPermissionSubject[]; + [permission in `${DlsPermissions}`]?: DlsModifyPermissionSubject[]; }; -interface DlsModifyBody { +export interface DlsModifyBody { diff: { added?: DlsPermissionDiff; removed?: DlsPermissionDiff; @@ -68,22 +63,9 @@ interface DlsModifyBody { }; } export interface ModifyPermissionDlsConfig { - entryId?: any; + entryId: string; body: DlsModifyBody; } -export interface BatchPermissionDlsConfig { - body: { - nodes: { - node: string; - body: DlsModifyBody; - }[]; - }; -} -export interface GetSuggestDlsConfig { - searchText?: string; - limit?: string; - lang?: string; -} export interface DlsEntity { entryId?: string; isLocked?: boolean; @@ -91,6 +73,6 @@ export interface DlsEntity { } export interface CheckBulkPermissionsDlsConfig { entities?: DlsEntity[]; - action: DlsActions; + action: string; includePermissionsInfo?: boolean; }