feat: Add compliance page to settings (#26777)
* Add compliance page to settings * fix: sanitize error logging in B2 download route Avoid logging raw error objects which may expose sensitive B2 credentials or internal information. Use sanitized error message instead. Co-Authored-By: unknown <> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
11 files changed
+397
-1
No files matched your search
@@ -0,0 +1,101 @@
|
||||
"use client";
|
||||
|
||||
import { useSession } from "next-auth/react";
|
||||
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import {
|
||||
SkeletonContainer,
|
||||
SkeletonText,
|
||||
} from "@calcom/ui/components/skeleton";
|
||||
|
||||
import { ComplianceDocumentCard } from "./compliance/ComplianceDocumentCard";
|
||||
import {
|
||||
COMPLIANCE_DOCUMENTS,
|
||||
DOCUMENT_CATEGORIES,
|
||||
} from "./compliance/compliance-documents";
|
||||
|
||||
const SkeletonLoader = () => {
|
||||
return (
|
||||
<SkeletonContainer>
|
||||
<div className="border-subtle border border-t-0 px-4 py-8 sm:px-6">
|
||||
<SkeletonText className="h-8 w-full" />
|
||||
<SkeletonText className="mt-4 h-8 w-full" />
|
||||
<SkeletonText className="mt-4 h-8 w-full" />
|
||||
</div>
|
||||
</SkeletonContainer>
|
||||
);
|
||||
};
|
||||
|
||||
const ComplianceView = () => {
|
||||
const { t } = useLocale();
|
||||
const session = useSession();
|
||||
|
||||
if (session.status === "loading") return <SkeletonLoader />;
|
||||
|
||||
// User has access to restricted documents if they're part of an organization
|
||||
const hasRestrictedAccess = !!session.data?.user?.org?.id;
|
||||
|
||||
const dpaDocuments = COMPLIANCE_DOCUMENTS.filter(
|
||||
(doc) => doc.category === DOCUMENT_CATEGORIES.DPA
|
||||
);
|
||||
const reportDocuments = COMPLIANCE_DOCUMENTS.filter(
|
||||
(doc) => doc.category === DOCUMENT_CATEGORIES.REPORTS
|
||||
);
|
||||
const otherDocuments = COMPLIANCE_DOCUMENTS.filter(
|
||||
(doc) => doc.category === DOCUMENT_CATEGORIES.OTHER
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="border-subtle space-y-8 rounded-b-xl border border-t-0 px-4 py-6 sm:px-6">
|
||||
{/* DPA Section */}
|
||||
<section>
|
||||
<h2 className="text-emphasis mb-4 text-base font-semibold">
|
||||
{t("data_privacy")}
|
||||
</h2>
|
||||
<div className="space-y-3">
|
||||
{dpaDocuments.map((doc) => (
|
||||
<ComplianceDocumentCard
|
||||
key={doc.id}
|
||||
document={doc}
|
||||
hasAccess={!doc.restricted || hasRestrictedAccess}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Reports Section */}
|
||||
<section>
|
||||
<h2 className="text-emphasis mb-4 text-base font-semibold">
|
||||
{t("compliance_reports")}
|
||||
</h2>
|
||||
<div className="space-y-3">
|
||||
{reportDocuments.map((doc) => (
|
||||
<ComplianceDocumentCard
|
||||
key={doc.id}
|
||||
document={doc}
|
||||
hasAccess={!doc.restricted || hasRestrictedAccess}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Other Documents Section */}
|
||||
<section>
|
||||
<h2 className="text-emphasis mb-4 text-base font-semibold">
|
||||
{t("other_documents")}
|
||||
</h2>
|
||||
<div className="space-y-3">
|
||||
{otherDocuments.map((doc) => (
|
||||
<ComplianceDocumentCard
|
||||
key={doc.id}
|
||||
document={doc}
|
||||
hasAccess={!doc.restricted || hasRestrictedAccess}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ComplianceView;
|
||||
@@ -0,0 +1,66 @@
|
||||
"use client";
|
||||
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import classNames from "@calcom/ui/classNames";
|
||||
import { Button } from "@calcom/ui/components/button";
|
||||
import { Icon } from "@calcom/ui/components/icon";
|
||||
import { Tooltip } from "@calcom/ui/components/tooltip";
|
||||
|
||||
import type { ComplianceDocument } from "./compliance-documents";
|
||||
|
||||
interface ComplianceDocumentCardProps {
|
||||
document: ComplianceDocument;
|
||||
hasAccess: boolean;
|
||||
}
|
||||
|
||||
export function ComplianceDocumentCard({ document, hasAccess }: ComplianceDocumentCardProps) {
|
||||
const { t } = useLocale();
|
||||
|
||||
const getDownloadUrl = () => {
|
||||
if (document.source.type === "url") {
|
||||
return document.source.url;
|
||||
}
|
||||
// For B2 documents, use our API route
|
||||
return `/api/compliance/download?id=${document.id}`;
|
||||
};
|
||||
|
||||
const handleDownload = () => {
|
||||
if (hasAccess) {
|
||||
window.open(getDownloadUrl(), "_blank", "noopener,noreferrer");
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className={classNames(
|
||||
"border-subtle bg-default flex items-center justify-between rounded-lg border p-4",
|
||||
!hasAccess && "opacity-60"
|
||||
)}>
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="bg-subtle flex h-10 w-10 items-center justify-center rounded-lg">
|
||||
<Icon name="file-text" className="text-default h-5 w-5" />
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-emphasis text-sm font-medium">{t(document.name)}</p>
|
||||
<p className="text-subtle text-sm">{t(document.description)}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{hasAccess ? (
|
||||
<Button color="secondary" onClick={handleDownload} StartIcon="download">
|
||||
{t("download")}
|
||||
</Button>
|
||||
) : (
|
||||
<Tooltip content={t("compliance_upgrade_tooltip")}>
|
||||
<span>
|
||||
<Button color="secondary" href="/settings/billing" StartIcon="lock">
|
||||
{t("upgrade_to_access")}
|
||||
</Button>
|
||||
</span>
|
||||
</Tooltip>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
export const DOCUMENT_CATEGORIES = {
|
||||
DPA: "dpa",
|
||||
REPORTS: "reports",
|
||||
OTHER: "other",
|
||||
} as const;
|
||||
|
||||
export type DocumentCategory = (typeof DOCUMENT_CATEGORIES)[keyof typeof DOCUMENT_CATEGORIES];
|
||||
|
||||
export type DocumentSource =
|
||||
| { type: "url"; url: string }
|
||||
| { type: "b2"; fileName: string }; // fileName is the path in B2 bucket
|
||||
|
||||
export interface ComplianceDocument {
|
||||
id: string;
|
||||
name: string; // Translation key
|
||||
description: string; // Translation key
|
||||
source: DocumentSource;
|
||||
category: DocumentCategory;
|
||||
restricted: boolean; // true = Organizations/Enterprise only
|
||||
}
|
||||
|
||||
export const COMPLIANCE_DOCUMENTS: ComplianceDocument[] = [
|
||||
// DPA Section - External URL
|
||||
{
|
||||
id: "dpa",
|
||||
name: "data_protection_agreement",
|
||||
description: "dpa_description",
|
||||
source: { type: "url", url: "https://go.cal.com/dpa" },
|
||||
category: DOCUMENT_CATEGORIES.DPA,
|
||||
restricted: false,
|
||||
},
|
||||
// Reports Section - B2 Storage
|
||||
{
|
||||
id: "soc2-report",
|
||||
name: "soc2_report",
|
||||
description: "soc2_report_description",
|
||||
source: { type: "b2", fileName: "SOC2.pdf" },
|
||||
category: DOCUMENT_CATEGORIES.REPORTS,
|
||||
restricted: true,
|
||||
},
|
||||
{
|
||||
id: "iso27001-cert",
|
||||
name: "iso27001_certification",
|
||||
description: "iso27001_description",
|
||||
source: { type: "b2", fileName: "ISO27001-2022.pdf" },
|
||||
category: DOCUMENT_CATEGORIES.REPORTS,
|
||||
restricted: true,
|
||||
},
|
||||
// Other Documents - B2 Storage
|
||||
{
|
||||
id: "pentest-report",
|
||||
name: "pentest_report",
|
||||
description: "pentest_report_description",
|
||||
source: { type: "b2", fileName: "pentest.pdf" },
|
||||
category: DOCUMENT_CATEGORIES.OTHER,
|
||||
restricted: true,
|
||||
},
|
||||
];
|
||||
Reference in new issue
Block a user