From da1412c7857f98884a7cdf8fb0600867fb9c9818 Mon Sep 17 00:00:00 2001 From: ameer2468 <33054370+ameer2468@users.noreply.github.com> Date: Fri, 15 Aug 2025 17:05:32 +0300 Subject: [PATCH 01/21] even if video is private, and user is part of view, still see video --- apps/web/app/s/[videoId]/page.tsx | 14 +++++++-- apps/web/utils/auth.ts | 52 ++++++++++++++++++++++++++----- 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/apps/web/app/s/[videoId]/page.tsx b/apps/web/app/s/[videoId]/page.tsx index aa76037844a..5f85804e47c 100644 --- a/apps/web/app/s/[videoId]/page.tsx +++ b/apps/web/app/s/[videoId]/page.tsx @@ -5,6 +5,7 @@ import { organizationMembers, organizations, sharedVideos, + spaceMembers, spaces, spaceVideos, users, @@ -13,7 +14,7 @@ import { import type { VideoMetadata } from "@cap/database/types"; import { buildEnv } from "@cap/env"; import { Logo } from "@cap/ui"; -import { eq, type InferSelectModel, sql } from "drizzle-orm"; +import { and, eq, type InferSelectModel, sql } from "drizzle-orm"; import type { Metadata } from "next"; import { headers } from "next/headers"; import Link from "next/link"; @@ -301,10 +302,16 @@ export default async function ShareVideoPage(props: Props) { sharedOrganization: { organizationId: sharedVideos.organizationId, }, + spaceId: spaceVideos.spaceId, + isSpaceMember: spaceMembers.userId, }) .from(videos) .leftJoin(sharedVideos, eq(videos.id, sharedVideos.videoId)) - .where(eq(videos.id, videoId)); + .leftJoin(spaceVideos, eq(videos.id, spaceVideos.videoId)) + .leftJoin(spaceMembers, eq(spaceVideos.spaceId, spaceMembers.spaceId)) + .where( + and(eq(videos.id, videoId), eq(spaceMembers.userId, user?.id ?? "")), + ); if (user && video && user.id !== video.ownerId) { try { @@ -324,7 +331,8 @@ export default async function ShareVideoPage(props: Props) { if (userAccess === "private") { return (
If you own this video, please sign in to
manage sharing.
diff --git a/apps/web/utils/auth.ts b/apps/web/utils/auth.ts
index cf317941abc..c5153f7337f 100644
--- a/apps/web/utils/auth.ts
+++ b/apps/web/utils/auth.ts
@@ -12,20 +12,58 @@ async function verifyPasswordCookie(videoPassword: string) {
}
export async function userHasAccessToVideo(
- user: MaybePromise<{ id: string } | undefined | null>,
+ user: MaybePromise<
+ { id: string; activeOrganizationId: string } | undefined | null
+ >,
video: Pick<
InferSelectModel No video found No video found No video found
- If you own this video, please sign in to
- manage sharing.
-
+ If you own this video, please sign in{" "}
+ to manage sharing.
+ No video found
- If you own this video, please sign in to
- manage sharing.
-
+ If you own this video, please sign in{" "}
+ to manage sharing.
+ No video foundThis video is private
- This video is private
+ This video is private
-
+ This video is private
+
+