Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(web): gate space membership video actions behind manage access

Richie McIlroya90954640ff8
diff --git a/apps/web/actions/spaces/add-videos.ts b/apps/web/actions/spaces/add-videos.ts
index 55cbf8d5f..84bb043ff 100644
--- a/apps/web/actions/spaces/add-videos.ts
+++ b/apps/web/actions/spaces/add-videos.ts
@@ -7,6 +7,8 @@ import { sharedVideos, spaceVideos, videos } from "@cap/database/schema";
import type { Space, Video } from "@cap/web-domain";
import { and, eq, inArray } from "drizzle-orm";
import { revalidatePath } from "next/cache";
+import { requireOrganizationSettingsManager } from "@/actions/organization/authorization";
+import { getSpaceAccess } from "@/actions/organization/space-authorization";
export async function addVideosToSpace(
spaceId: Space.SpaceIdOrOrganisationId,
@@ -25,6 +27,17 @@ export async function addVideosToSpace(
const isAllSpacesEntry = user.activeOrganizationId === spaceId;
+ if (isAllSpacesEntry) {
+ await requireOrganizationSettingsManager(user.id, spaceId);
+ } else {
+ const access = await getSpaceAccess(user.id, spaceId);
+ if (!access?.canManage) {
+ throw new Error(
+ "You don't have permission to add videos to this space",
+ );
+ }
+ }
+
const userVideos = await db()
.select({ id: videos.id })
.from(videos)
@@ -64,7 +77,6 @@ export async function addVideosToSpace(
);
}
- // Insert new videos
if (newVideoIds.length > 0) {
const sharedVideoEntries = newVideoIds.map((videoId) => ({
id: nanoId(),
@@ -75,7 +87,6 @@ export async function addVideosToSpace(
await db().insert(sharedVideos).values(sharedVideoEntries);
}
} else {
- // Check which videos already exist in spaceVideos
const existingSpaceVideos = await db()
.select({ videoId: spaceVideos.videoId })
.from(spaceVideos)
diff --git a/apps/web/actions/spaces/remove-videos.ts b/apps/web/actions/spaces/remove-videos.ts
index fb732ad87..bc4397be8 100644
--- a/apps/web/actions/spaces/remove-videos.ts
+++ b/apps/web/actions/spaces/remove-videos.ts
@@ -6,6 +6,8 @@ import { sharedVideos, spaceVideos, videos } from "@cap/database/schema";
import type { Space, Video } from "@cap/web-domain";
import { and, eq, inArray } from "drizzle-orm";
import { revalidatePath } from "next/cache";
+import { requireOrganizationSettingsManager } from "@/actions/organization/authorization";
+import { getSpaceAccess } from "@/actions/organization/space-authorization";
export async function removeVideosFromSpace(
spaceId: Space.SpaceIdOrOrganisationId,
@@ -22,7 +24,19 @@ export async function removeVideosFromSpace(
throw new Error("Missing required data");
}
- // Only allow removing videos the user owns
+ const isAllSpacesEntry = user.activeOrganizationId === spaceId;
+
+ if (isAllSpacesEntry) {
+ await requireOrganizationSettingsManager(user.id, spaceId);
+ } else {
+ const access = await getSpaceAccess(user.id, spaceId);
+ if (!access?.canManage) {
+ throw new Error(
+ "You don't have permission to remove videos from this space",
+ );
+ }
+ }
+
const userVideos = await db()
.select({ id: videos.id })
.from(videos)
@@ -34,8 +48,6 @@ export async function removeVideosFromSpace(
throw new Error("No valid videos found");
}
- const isAllSpacesEntry = user.activeOrganizationId === spaceId;
-
if (isAllSpacesEntry) {
await db()
.delete(sharedVideos)