Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions app/api/views-dataroom/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { generateOTP } from "@/lib/utils/generate-otp";
import { LOCALHOST_IP } from "@/lib/utils/geo";
import { checkGlobalBlockList } from "@/lib/utils/global-block-list";
import { validateEmail } from "@/lib/utils/validate-email";
import { isEmailAllowedByAllowList } from "@/lib/utils/allow-list-access";

export async function POST(request: NextRequest) {
try {
Expand Down Expand Up @@ -110,6 +111,12 @@ export async function POST(request: NextRequest) {
domainId: true,
allowList: true,
denyList: true,
allowListGroupId: true,
allowListGroup: {
select: {
allowList: true,
},
},
enableAgreement: true,
agreementId: true,
enableWatermark: true,
Expand Down Expand Up @@ -289,19 +296,24 @@ export async function POST(request: NextRequest) {
return NextResponse.json({ message: "Access denied" }, { status: 403 });
}

// Check if email is allowed to visit the link
if (link.allowList && link.allowList.length > 0) {
// Determine if the email or its domain is allowed
const isAllowed = link.allowList.some((allowed) =>
isEmailMatched(email, allowed),
);
// Check if email is allowed by either link allowList or AllowListGroup
if (email && typeof email === "string" && email.includes("@")) {
const hasAnyAllowList = (link.allowList && link.allowList.length > 0) ||
(link.allowListGroup?.allowList && link.allowListGroup.allowList.length > 0);

// Deny access if the email is not allowed
if (!isAllowed) {
return NextResponse.json(
{ message: "Unauthorized access" },
{ status: 403 },
if (hasAnyAllowList) {
const isAllowed = isEmailAllowedByAllowList(
email,
link.allowList,
link.allowListGroup
);

if (!isAllowed) {
return NextResponse.json(
{ message: "Unauthorized access" },
{ status: 403 },
);
}
}
}

Expand Down
36 changes: 24 additions & 12 deletions app/api/views/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import { parseSheet } from "@/lib/sheet";
import { recordLinkView } from "@/lib/tracking/record-link-view";
import { CustomUser, WatermarkConfigSchema } from "@/lib/types";
import { checkPassword, decryptEncrpytedPassword, log } from "@/lib/utils";
import { extractEmailDomain, isEmailMatched } from "@/lib/utils/email-domain";
import { generateOTP } from "@/lib/utils/generate-otp";
import { LOCALHOST_IP } from "@/lib/utils/geo";
import { checkGlobalBlockList } from "@/lib/utils/global-block-list";
import { validateEmail } from "@/lib/utils/validate-email";
import { isEmailMatched } from "@/lib/utils/email-domain";
import { isEmailAllowedByAllowList } from "@/lib/utils/allow-list-access";

export async function POST(request: NextRequest) {
try {
Expand Down Expand Up @@ -93,6 +94,12 @@ export async function POST(request: NextRequest) {
slug: true,
allowList: true,
denyList: true,
allowListGroupId: true,
allowListGroup: {
select: {
allowList: true,
},
},
enableAgreement: true,
agreementId: true,
enableWatermark: true,
Expand Down Expand Up @@ -224,19 +231,24 @@ export async function POST(request: NextRequest) {
return NextResponse.json({ message: "Access denied" }, { status: 403 });
}

// Check if email is allowed to visit the link
if (link.allowList && link.allowList.length > 0) {
// Determine if the email or its domain is allowed
const isAllowed = link.allowList.some((allowed) =>
isEmailMatched(email, allowed),
);
// Check if email is allowed by either link allowList or AllowListGroup
if (email && typeof email === "string" && email.includes("@")) {
const hasAnyAllowList = (link.allowList && link.allowList.length > 0) ||
(link.allowListGroup?.allowList && link.allowListGroup.allowList.length > 0);

// Deny access if the email is not allowed
if (!isAllowed) {
return NextResponse.json(
{ message: "Unauthorized access" },
{ status: 403 },
if (hasAnyAllowList) {
const isAllowed = isEmailAllowedByAllowList(
email,
link.allowList,
link.allowListGroup
);

if (!isAllowed) {
return NextResponse.json(
{ message: "Unauthorized access" },
{ status: 403 },
);
}
}
}

Expand Down
37 changes: 32 additions & 5 deletions components/layouts/breadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useRouter } from "next/router";

import React, { useEffect, useMemo, useRef, useState } from "react";

import { useAllowListGroup } from "@/lib/swr/use-allow-list-groups";
import { useDataroom } from "@/lib/swr/use-dataroom";
import { useDocument } from "@/lib/swr/use-document";
import { useFolderWithParents } from "@/lib/swr/use-folders";
Expand Down Expand Up @@ -365,9 +366,7 @@ const VisitorsBreadcrumb = () => {
<Breadcrumb>
<BreadcrumbList>
<BreadcrumbItem>
<BreadcrumbLink asChild>
<Link href="/visitors">Visitors</Link>
</BreadcrumbLink>
<BreadcrumbPage>Visitors</BreadcrumbPage>
</BreadcrumbItem>
</BreadcrumbList>
</Breadcrumb>
Expand Down Expand Up @@ -396,6 +395,28 @@ const SingleVisitorBreadcrumb = () => {
);
};

const SingleVisitorGroupBreadcrumb = ({ groupId }: { groupId: string }) => {
const { allowListGroup } = useAllowListGroup(groupId);

return (
<Breadcrumb>
<BreadcrumbList>
<BreadcrumbItem>
<BreadcrumbLink asChild>
<Link href="/visitors?tab=allow-lists">Visitors</Link>
</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbItem>
<BreadcrumbPage>
{allowListGroup?.name || "Loading..."}
</BreadcrumbPage>
</BreadcrumbItem>
</BreadcrumbList>
</Breadcrumb>
);
};

const AnalyticsBreadcrumb = () => {
const router = useRouter();
const { type = "links" } = router.query;
Expand Down Expand Up @@ -435,8 +456,9 @@ const AnalyticsBreadcrumb = () => {
export const AppBreadcrumb = () => {
const router = useRouter();
const path = router.pathname;
const { id } = router.query as {
const { id, groupId } = router.query as {
id?: string;
groupId?: string;
};

const breadcrumb = useMemo(() => {
Expand Down Expand Up @@ -516,8 +538,13 @@ export const AppBreadcrumb = () => {
return <SingleVisitorBreadcrumb />;
}

// Visitor group route
if (path === "/visitors/groups/[groupId]" && groupId) {
return <SingleVisitorGroupBreadcrumb groupId={groupId} />;
}

return null;
}, [path, id]);
}, [path, id, groupId]);

return breadcrumb;
};
Loading