From b50ae3eb60f8e71e6cfadef2c159b9f286ddf040 Mon Sep 17 00:00:00 2001 From: Alexandr Yushkov Date: Fri, 1 Dec 2023 14:58:33 +0100 Subject: [PATCH] Mirrored column in the Entries table (#32) --- .../20231201120709_add_mirrored_column.ts | 13 ++++++++++++ src/services/new/entry/get-entry.ts | 20 ++++++++++++++----- src/types/ctx.ts | 1 + 3 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 src/db/migrations/20231201120709_add_mirrored_column.ts diff --git a/src/db/migrations/20231201120709_add_mirrored_column.ts b/src/db/migrations/20231201120709_add_mirrored_column.ts new file mode 100644 index 00000000..ca2cfa29 --- /dev/null +++ b/src/db/migrations/20231201120709_add_mirrored_column.ts @@ -0,0 +1,13 @@ +import {Knex} from 'knex'; + +export async function up(knex: Knex): Promise { + return knex.raw(` + ALTER TABLE entries ADD COLUMN mirrored BOOLEAN DEFAULT false; + `); +} + +export async function down(knex: Knex): Promise { + return knex.raw(` + ALTER TABLE entries DROP COLUMN mirrored; + `); +} diff --git a/src/services/new/entry/get-entry.ts b/src/services/new/entry/get-entry.ts index 9df44e1c..c1dccb97 100644 --- a/src/services/new/entry/get-entry.ts +++ b/src/services/new/entry/get-entry.ts @@ -62,7 +62,7 @@ export const getEntry = async ( const {DLS} = registry.common.classes.get(); - const {isPrivateRoute, user, onlyPublic, embeddingInfo} = ctx.get('info'); + const {isPrivateRoute, user, onlyPublic, onlyMirrored, embeddingInfo} = ctx.get('info'); if (!skipValidation) { validateArgs(args); @@ -92,6 +92,10 @@ export const getEntry = async ( if (onlyPublic) { builder.andWhere({public: true}); } + + if (onlyMirrored) { + builder.andWhere({mirrored: true}); + } }, joinRevisionArgs: { revId, @@ -113,7 +117,8 @@ export const getEntry = async ( let iamPermissions: Optional; if (joinedEntryRevisionFavorite.workbookId) { - const checkWorkbookEnabled = !isPrivateRoute && !onlyPublic && !isEmbedding; + const checkWorkbookEnabled = + !isPrivateRoute && !onlyPublic && !onlyMirrored && !isEmbedding; if (checkWorkbookEnabled) { const workbook = await getWorkbook( @@ -134,9 +139,14 @@ export const getEntry = async ( } } else { const checkPermissionEnabled = - !dlsBypassByKeyEnabled && !isPrivateRoute && ctx.config.dlsEnabled && !onlyPublic; - - const checkEntryEnabled = !isPrivateRoute && !onlyPublic && !isEmbedding; + !dlsBypassByKeyEnabled && + !isPrivateRoute && + ctx.config.dlsEnabled && + !onlyPublic && + !onlyMirrored; + + const checkEntryEnabled = + !isPrivateRoute && !onlyPublic && !onlyMirrored && !isEmbedding; if (checkPermissionEnabled) { dlsPermissions = await DLS.checkPermission( diff --git a/src/types/ctx.ts b/src/types/ctx.ts index 16380c28..734b9026 100644 --- a/src/types/ctx.ts +++ b/src/types/ctx.ts @@ -21,6 +21,7 @@ export type CtxInfo = { isPrivateRoute: boolean; dlContext: string; onlyPublic: boolean; + onlyMirrored?: boolean; privatePermissions: PrivatePermissions; projectId: string | null; embeddingInfo?: EmbeddingInfo;