Skip to content

Commit

Permalink
Mirrored column in the Entries table (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
bt4R9 authored Dec 1, 2023
1 parent cc481fd commit b50ae3e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
13 changes: 13 additions & 0 deletions src/db/migrations/20231201120709_add_mirrored_column.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {Knex} from 'knex';

export async function up(knex: Knex): Promise<void> {
return knex.raw(`
ALTER TABLE entries ADD COLUMN mirrored BOOLEAN DEFAULT false;
`);
}

export async function down(knex: Knex): Promise<void> {
return knex.raw(`
ALTER TABLE entries DROP COLUMN mirrored;
`);
}
20 changes: 15 additions & 5 deletions src/services/new/entry/get-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -92,6 +92,10 @@ export const getEntry = async (
if (onlyPublic) {
builder.andWhere({public: true});
}

if (onlyMirrored) {
builder.andWhere({mirrored: true});
}
},
joinRevisionArgs: {
revId,
Expand All @@ -113,7 +117,8 @@ export const getEntry = async (
let iamPermissions: Optional<EntryPermissions>;

if (joinedEntryRevisionFavorite.workbookId) {
const checkWorkbookEnabled = !isPrivateRoute && !onlyPublic && !isEmbedding;
const checkWorkbookEnabled =
!isPrivateRoute && !onlyPublic && !onlyMirrored && !isEmbedding;

if (checkWorkbookEnabled) {
const workbook = await getWorkbook(
Expand All @@ -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(
Expand Down
1 change: 1 addition & 0 deletions src/types/ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type CtxInfo = {
isPrivateRoute: boolean;
dlContext: string;
onlyPublic: boolean;
onlyMirrored?: boolean;
privatePermissions: PrivatePermissions;
projectId: string | null;
embeddingInfo?: EmbeddingInfo;
Expand Down

0 comments on commit b50ae3e

Please sign in to comment.