Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(web-backend): enforce inherited space passwords in view policy

Richie McIlroyc4d168ab689d
diff --git a/packages/web-backend/src/Videos/VideosPolicy.ts b/packages/web-backend/src/Videos/VideosPolicy.ts
index 5cc92d209..858483b61 100644
--- a/packages/web-backend/src/Videos/VideosPolicy.ts
+++ b/packages/web-backend/src/Videos/VideosPolicy.ts
@@ -1,10 +1,17 @@
import { isEmailAllowedByRestriction } from "@cap/utils";
-import { Policy, Video } from "@cap/web-domain";
+import {
+ type DatabaseError,
+ type Organisation,
+ Policy,
+ type User,
+ Video,
+} from "@cap/web-domain";
import { Array, Effect, Option } from "effect";
import { Database } from "../Database.ts";
import { OrganisationsRepo } from "../Organisations/OrganisationsRepo.ts";
import { SpacesRepo } from "../Spaces/SpacesRepo.ts";
+import { collectPasswordHashes } from "./EffectiveVideoRules.ts";
import { VideosRepo } from "./VideosRepo.ts";
export type VideosPolicyDeps = {
@@ -13,23 +20,26 @@ export type VideosPolicyDeps = {
id: Video.VideoId,
) => Effect.Effect<
Option.Option<readonly [Video.Video, Option.Option<string>]>,
- any
+ DatabaseError
>;
};
orgsRepo: {
membershipForVideo: (
- userId: any,
+ userId: User.UserId,
videoId: Video.VideoId,
- ) => Effect.Effect<readonly { membershipId: string }[], any>;
+ ) => Effect.Effect<readonly { membershipId: string }[], DatabaseError>;
allowedEmailDomain: (
- orgId: any,
- ) => Effect.Effect<Option.Option<string>, any>;
+ orgId: Organisation.OrganisationId,
+ ) => Effect.Effect<Option.Option<string>, DatabaseError>;
};
spacesRepo: {
membershipForVideo: (
- userId: any,
+ userId: User.UserId,
videoId: Video.VideoId,
- ) => Effect.Effect<Option.Option<{ membershipId: string }>, any>;
+ ) => Effect.Effect<Option.Option<{ membershipId: string }>, DatabaseError>;
+ passwordsForVideo: (
+ videoId: Video.VideoId,
+ ) => Effect.Effect<readonly { password: string | null }[], DatabaseError>;
};
};
@@ -51,7 +61,16 @@ export function buildCanView(
if (Option.isSome(user)) {
const userId = user.value.id;
if (userId === video.ownerId) return true;
+ }
+
+ const spacePasswords = yield* spacesRepo.passwordsForVideo(video.id);
+ const passwordHashes = collectPasswordHashes({
+ videoPassword: Option.getOrNull(password),
+ spacePasswords: [...spacePasswords],
+ });
+ if (Option.isSome(user)) {
+ const userId = user.value.id;
const [videoOrgShareMembership, videoSpaceShareMembership] =
yield* Effect.all([
orgsRepo
@@ -67,7 +86,7 @@ export function buildCanView(
yield* Effect.log(
"Explicit org/space membership found. Access granted.",
);
- yield* Video.verifyPassword(video, password);
+ yield* Video.verifyPasswordCandidates(video, passwordHashes);
return true;
}
}
@@ -108,7 +127,7 @@ export function buildCanView(
}
}
- yield* Video.verifyPassword(video, password);
+ yield* Video.verifyPasswordCandidates(video, passwordHashes);
return true;
}),