Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Propagate policy denial reasons to UI

Richie McIlroya4c4c3ec1979
diff --git a/apps/web/app/s/[videoId]/page.tsx b/apps/web/app/s/[videoId]/page.tsx
index 0ca9e5930..6eafdca3c 100644
--- a/apps/web/app/s/[videoId]/page.tsx
+++ b/apps/web/app/s/[videoId]/page.tsx
@@ -116,26 +116,47 @@ const ALLOWED_REFERRERS = [
"linkedin.com",
];
-function PolicyDeniedView() {
+function PolicyDeniedView({ reason }: { reason?: string }) {
+ let title = "This video is private";
+ let description = (
+ <>
+ If you own this video, please <Link href="/login">sign in</Link> to manage
+ sharing.
+ </>
+ );
+
+ if (reason === "email_restriction_login_required") {
+ title = "This video requires sign-in";
+ description = (
+ <>
+ The owner of this video has restricted access. Please{" "}
+ <Link href="/login">sign in</Link> with an authorized email address to
+ view.
+ </>
+ );
+ } else if (reason === "email_restriction_denied") {
+ title = "Access restricted";
+ description =
+ "Your email address does not meet the requirements set by the video owner.";
+ }
+
return (
<div className="flex flex-col justify-center items-center p-4 min-h-screen text-center">
<Logo className="size-32" />
- <h1 className="mb-2 text-2xl font-semibold">This video is private</h1>
- <p className="text-gray-400">
- If you own this video, please <Link href="/login">sign in</Link> to
- manage sharing.
- </p>
+ <h1 className="mb-2 text-2xl font-semibold">{title}</h1>
+ <p className="text-gray-400">{description}</p>
</div>
);
}
-const renderPolicyDenied = (videoId: Video.VideoId) =>
- Effect.succeed(<PolicyDeniedView key={videoId} />);
+const renderPolicyDenied = (videoId: Video.VideoId, reason?: string) =>
+ Effect.succeed(<PolicyDeniedView key={videoId} reason={reason} />);
const renderNoSuchElement = () => Effect.sync(() => notFound());
const getShareVideoPageCatchers = (videoId: Video.VideoId) => ({
- PolicyDenied: () => renderPolicyDenied(videoId),
+ PolicyDenied: (e: Policy.PolicyDeniedError) =>
+ renderPolicyDenied(videoId, e.reason),
NoSuchElementException: renderNoSuchElement,
});
@@ -210,8 +231,8 @@ export async function generateMetadata(
Effect.catchTags({
PolicyDenied: () =>
Effect.succeed({
- title: "Cap: This video is private",
- description: "This video is private and cannot be shared.",
+ title: "Cap: This video is restricted",
+ description: "This video has restricted access.",
openGraph: {
images: [
{
diff --git a/packages/web-backend/src/Videos/VideosPolicy.ts b/packages/web-backend/src/Videos/VideosPolicy.ts
index dd45a8295..5cc92d209 100644
--- a/packages/web-backend/src/Videos/VideosPolicy.ts
+++ b/packages/web-backend/src/Videos/VideosPolicy.ts
@@ -89,11 +89,22 @@ export function buildCanView(
yield* Effect.log(
"Email access restriction active and user not logged in. Access denied.",
);
- return false;
+ yield* Effect.fail(
+ new Policy.PolicyDeniedError({
+ reason: "email_restriction_login_required",
+ }),
+ );
}
- if (!isEmailAllowedByRestriction(user.value.email, restriction)) {
+ if (
+ Option.isSome(user) &&
+ !isEmailAllowedByRestriction(user.value.email, restriction)
+ ) {
yield* Effect.log("Email access restriction active. Access denied.");
- return false;
+ yield* Effect.fail(
+ new Policy.PolicyDeniedError({
+ reason: "email_restriction_denied",
+ }),
+ );
}
}
diff --git a/packages/web-domain/src/Policy.ts b/packages/web-domain/src/Policy.ts
index bfa3f628a..cd965ee13 100644
--- a/packages/web-domain/src/Policy.ts
+++ b/packages/web-domain/src/Policy.ts
@@ -19,7 +19,7 @@ export type PublicPolicy<E = never, R = never> = Effect.Effect<
export class PolicyDeniedError extends Schema.TaggedError<PolicyDeniedError>()(
"PolicyDenied",
- {},
+ { reason: Schema.optional(Schema.String) },
HttpApiSchema.annotations({ status: 403 }),
) {}