diff --git a/apps/web/actions/organizations/add-videos.ts b/apps/web/actions/organizations/add-videos.ts index a811dcd623..1146bb6e31 100644 --- a/apps/web/actions/organizations/add-videos.ts +++ b/apps/web/actions/organizations/add-videos.ts @@ -10,7 +10,7 @@ import { videos, } from "@cap/database/schema"; import type { Organisation, Video } from "@cap/web-domain"; -import { and, eq, inArray } from "drizzle-orm"; +import { and, eq, inArray, isNull } from "drizzle-orm"; import { revalidatePath } from "next/cache"; export async function addVideosToOrganization( @@ -31,7 +31,12 @@ export async function addVideosToOrganization( const [organization] = await db() .select() .from(organizations) - .where(eq(organizations.id, organizationId)); + .where( + and( + eq(organizations.id, organizationId), + isNull(organizations.tombstoneAt), + ), + ); if (!organization) { throw new Error("Organization not found"); diff --git a/apps/web/actions/spaces/get-user-videos.ts b/apps/web/actions/spaces/get-user-videos.ts index 201eb8647a..937d19d74d 100644 --- a/apps/web/actions/spaces/get-user-videos.ts +++ b/apps/web/actions/spaces/get-user-videos.ts @@ -5,6 +5,7 @@ import { getCurrentUser } from "@cap/database/auth/session"; import { comments, folders, + organizations, sharedVideos, spaces, spaceVideos, @@ -13,7 +14,7 @@ import { videoUploads, } from "@cap/database/schema"; import type { Space } from "@cap/web-domain"; -import { and, desc, eq, sql } from "drizzle-orm"; +import { and, desc, eq, isNull, sql } from "drizzle-orm"; export async function getUserVideos(spaceId: Space.SpaceIdOrOrganisationId) { try { @@ -64,7 +65,10 @@ export async function getUserVideos(spaceId: Space.SpaceIdOrOrganisationId) { ) .leftJoin(folders, eq(sharedVideos.folderId, folders.id)) .leftJoin(spaces, eq(folders.spaceId, spaces.id)) - .where(eq(videos.ownerId, userId)) + .leftJoin(organizations, eq(videos.orgId, organizations.id)) + .where( + and(eq(videos.ownerId, userId), isNull(organizations.tombstoneAt)), + ) .groupBy( videos.id, videos.ownerId, @@ -98,7 +102,10 @@ export async function getUserVideos(spaceId: Space.SpaceIdOrOrganisationId) { ) .leftJoin(folders, eq(spaceVideos.folderId, folders.id)) .leftJoin(spaces, eq(folders.spaceId, spaces.id)) - .where(eq(videos.ownerId, userId)) + .leftJoin(organizations, eq(videos.orgId, organizations.id)) + .where( + and(eq(videos.ownerId, userId), isNull(organizations.tombstoneAt)), + ) .groupBy( videos.id, videos.ownerId, diff --git a/apps/web/app/(org)/dashboard/caps/page.tsx b/apps/web/app/(org)/dashboard/caps/page.tsx index a4da232f39..f31fb1e2d8 100644 --- a/apps/web/app/(org)/dashboard/caps/page.tsx +++ b/apps/web/app/(org)/dashboard/caps/page.tsx @@ -128,6 +128,7 @@ export default async function CapsPage(props: PageProps<"/dashboard/caps">) { and( eq(videos.ownerId, userId), eq(organizations.id, user.activeOrganizationId), + isNull(organizations.tombstoneAt), ), ); @@ -185,6 +186,7 @@ export default async function CapsPage(props: PageProps<"/dashboard/caps">) { eq(videos.ownerId, userId), eq(videos.orgId, user.activeOrganizationId), isNull(videos.folderId), + isNull(organizations.tombstoneAt), ), ) .groupBy( diff --git a/apps/web/app/(org)/dashboard/spaces/[spaceId]/page.tsx b/apps/web/app/(org)/dashboard/spaces/[spaceId]/page.tsx index f90bd86501..079ce13d8a 100644 --- a/apps/web/app/(org)/dashboard/spaces/[spaceId]/page.tsx +++ b/apps/web/app/(org)/dashboard/spaces/[spaceId]/page.tsx @@ -4,6 +4,7 @@ import { comments, folders, organizationMembers, + organizations, sharedVideos, spaceMembers, spaceVideos, @@ -201,8 +202,13 @@ export default async function SharedCapsPage(props: { .leftJoin(comments, eq(videos.id, comments.videoId)) .leftJoin(users, eq(videos.ownerId, users.id)) .leftJoin(videoUploads, eq(videos.id, videoUploads.videoId)) + .leftJoin(organizations, eq(videos.orgId, organizations.id)) .where( - and(eq(spaceVideos.spaceId, spaceId), isNull(spaceVideos.folderId)), + and( + eq(spaceVideos.spaceId, spaceId), + isNull(spaceVideos.folderId), + isNull(organizations.tombstoneAt), + ), ) .groupBy( videos.id, diff --git a/apps/web/lib/folder.ts b/apps/web/lib/folder.ts index f7222e4468..18e8a44c6f 100644 --- a/apps/web/lib/folder.ts +++ b/apps/web/lib/folder.ts @@ -14,10 +14,9 @@ import { import { Database, ImageUploads } from "@cap/web-backend"; import type { ImageUpload, Organisation, Space, Video } from "@cap/web-domain"; import { CurrentUser, Folder } from "@cap/web-domain"; -import { and, desc, eq } from "drizzle-orm"; +import { and, desc, eq, isNull } from "drizzle-orm"; import { sql } from "drizzle-orm/sql"; import { Effect } from "effect"; -import { runPromise } from "./server"; export const getFolderById = Effect.fn(function* (folderId: string) { if (!folderId) throw new Error("Folder ID is required"); @@ -221,9 +220,15 @@ export const getVideosByFolderId = Effect.fn(function* ( .leftJoin(videoUploads, eq(videos.id, videoUploads.videoId)) .where( root.variant === "space" - ? eq(spaceVideos.folderId, folderId) + ? and( + eq(spaceVideos.folderId, folderId), + isNull(organizations.tombstoneAt), + ) : root.variant === "org" - ? eq(sharedVideos.folderId, folderId) + ? and( + eq(sharedVideos.folderId, folderId), + isNull(organizations.tombstoneAt), + ) : eq(videos.folderId, folderId), ) .groupBy(