Skip to content

Commit

Permalink
Delete, simplify DLS types (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoncool authored Oct 10, 2024
1 parent d5d08aa commit cbbb5fd
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 93 deletions.
1 change: 0 additions & 1 deletion api/registry.ts

This file was deleted.

1 change: 1 addition & 0 deletions api/registry/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {registry} from '../../src/registry';
1 change: 1 addition & 0 deletions api/registry/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type {DLSConstructor} from '../../src/registry/common/components/dls/types';
8 changes: 2 additions & 6 deletions src/db/models/entry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,7 @@ class Entry extends Model {
initialParentId,
scope: 'folder',
parentFolderKey: existedParentFolderKey,
parentFolder: {
entryId: folderKeysMap[existedParentFolderKey],
},
parentFolderId: folderKeysMap[existedParentFolderKey],
},
);
}
Expand Down Expand Up @@ -484,9 +482,7 @@ class Entry extends Model {
initialPermissions,
initialParentId,
parentFolderKey,
parentFolder: {
entryId: parentFolderKey === '/' ? {} : parentFolder.entryId,
},
parentFolderId: parentFolderKey === '/' ? undefined : parentFolder.entryId,
},
);
}
Expand Down
28 changes: 0 additions & 28 deletions src/registry/common/components/dls/dls.ts
Original file line number Diff line number Diff line change
@@ -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 {};
}
Expand All @@ -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 [];
}
};
33 changes: 0 additions & 33 deletions src/registry/common/components/dls/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>;

checkEntriesInTenant: (
{ctx, trx}: {ctx: AppContext; trx?: TransactionOrKnex},
entryIds: string[],
) => Promise<void>;

prepareHeaders: (
ctx: AppContext,
requestId: string,
hasIamManagePermission: boolean,
) => Record<string, string>;

checkPermission: (
{ctx, trx}: {ctx: AppContext; trx?: TransactionOrKnex},
checkPermissionsArgs: MT.CheckPermissionDlsConfig,
Expand All @@ -32,29 +13,15 @@ export interface DLSConstructor {
checkBulkPermission(
{ctx, trx}: {ctx: AppContext; trx?: TransactionOrKnex},
checkBulkPermissionArgs: MT.CheckBulkPermissionsDlsConfig,
skipEntriesInTenantCheck?: boolean,
): Promise<any[]>;

addEntity(
{ctx, trx}: {ctx: AppContext; trx?: TransactionOrKnex},
addEntityArgs: MT.CreationDlsEntityConfig,
): Promise<any>;

getPermissions(
{ctx, trx}: {ctx: AppContext; trx?: TransactionOrKnex},
getPermissionsArgs: MT.GetPermissionDlsConfig,
): Promise<any>;

modifyPermissions(
{ctx, trx}: {ctx: AppContext; trx?: TransactionOrKnex},
modifyPermissionsArgs: MT.ModifyPermissionDlsConfig,
preparedHasIamManagePermission?: boolean,
): Promise<any>;

batchPermissions(
{ctx, trx}: {ctx: AppContext; trx?: TransactionOrKnex},
batchPermissionsArgs: MT.BatchPermissionDlsConfig,
): Promise<any>;

suggest(cx: AppContext, suggestArgs: MT.GetSuggestDlsConfig): Promise<any>;
}
32 changes: 7 additions & 25 deletions src/types/models/dls.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable camelcase */
import {EntryScope} from './entry';
import {UsPermission} from './permission';

export enum DlsActions {
Expand All @@ -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;
Expand All @@ -53,44 +48,31 @@ 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;
modified?: DlsModifyPermissionDiff;
};
}
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;
permissions?: UsPermission;
}
export interface CheckBulkPermissionsDlsConfig {
entities?: DlsEntity[];
action: DlsActions;
action: string;
includePermissionsInfo?: boolean;
}

0 comments on commit cbbb5fd

Please sign in to comment.