Skip to content

Commit

Permalink
Merge pull request #4075 from signalco-io/fix/doprocess/public-items-…
Browse files Browse the repository at this point in the history
…in-list

fix(doprocess): Don't show public processes, runs and documents in us…
  • Loading branch information
AleksandarDev authored Dec 10, 2023
2 parents 337f92b + 29d4089 commit 8827096
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 6 additions & 3 deletions web/apps/doprocess/src/lib/repo/documentsRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})`);
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 6 additions & 3 deletions web/apps/doprocess/src/lib/repo/processesRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})`
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 8827096

Please sign in to comment.