From 29d4089f6765d8528a13d83d858f369d417a83f0 Mon Sep 17 00:00:00 2001 From: Aleksandar Toplek Date: Mon, 11 Dec 2023 00:11:43 +0100 Subject: [PATCH] fix(doprocess): Don't show public processes, runs and documents in users list Closes #4063 --- web/apps/doprocess/src/lib/repo/documentsRepository.ts | 9 ++++++--- web/apps/doprocess/src/lib/repo/processesRepository.ts | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/web/apps/doprocess/src/lib/repo/documentsRepository.ts b/web/apps/doprocess/src/lib/repo/documentsRepository.ts index 9a6b085b09..aa6dd20fc2 100644 --- a/web/apps/doprocess/src/lib/repo/documentsRepository.ts +++ b/web/apps/doprocess/src/lib/repo/documentsRepository.ts @@ -4,10 +4,13 @@ import { document } from '../db/schema'; import { db } from '../db'; import { publicIdNext } from './shared'; -function documentSharedWithUser(userId: string | null) { - if (!userId) +function documentSharedWithUser(userId: string | null, includePublic = true) { + if (!userId && includePublic) return sql`"public" MEMBER OF(${document.sharedWithUsers})`; + if (userId && includePublic) + return sql`${userId} MEMBER OF(${document.sharedWithUsers})`; + return or( sql`${userId} MEMBER OF(${document.sharedWithUsers})`, sql`"public" MEMBER OF(${document.sharedWithUsers})`); @@ -44,7 +47,7 @@ export async function documentCreate(userId: string, name: string, basedOn?: str } export async function documentsGet(userId: string) { - return await db.select().from(document).where(documentSharedWithUser(userId)); + return await db.select().from(document).where(documentSharedWithUser(userId, false)); } export async function documentGet(userId: string | null, id: number) { diff --git a/web/apps/doprocess/src/lib/repo/processesRepository.ts b/web/apps/doprocess/src/lib/repo/processesRepository.ts index 784f5f301a..f6d0379969 100644 --- a/web/apps/doprocess/src/lib/repo/processesRepository.ts +++ b/web/apps/doprocess/src/lib/repo/processesRepository.ts @@ -5,10 +5,13 @@ import { TaskState, process, processRun, task, taskDefinition } from '../db/sche import { db } from '../db'; import { publicIdNext } from './shared'; -function processSharedWithUser(userId: string | null) { - if (userId == null) +function processSharedWithUser(userId: string | null, includePublic = true) { + if (userId == null && includePublic) return sql`"public" MEMBER OF(${process.sharedWithUsers})` + if (userId && !includePublic) + return sql`${userId} MEMBER OF(${process.sharedWithUsers})`; + return or( sql`${userId} MEMBER OF(${process.sharedWithUsers})`, sql`"public" MEMBER OF(${process.sharedWithUsers})` @@ -51,7 +54,7 @@ export async function getProcessRunTaskIdByPublicId(processPublicId: string, pro } export async function getProcesses(userId: string) { - return await db.select().from(process).where(processSharedWithUser(userId)); + return await db.select().from(process).where(processSharedWithUser(userId, false)); } export async function getProcess(userId: string | null, processId: number) {