Use trust center from context

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-01-13 14:42:05 +04:00
committed by Bryan Frimin
parent 7322201dab
commit e220c259b3
33 changed files with 535 additions and 839 deletions

View File

@@ -53,7 +53,7 @@ export function DocumentRow(props: { document: DocumentRowFragment$key }) {
document.hasUserRequestedAccess,
);
return (
<div className="text-sm border-1 border-border-solid -mt-[1px] flex gap-3 flex-col md:flex-row md:justify-between px-6 py-3">
<div className="text-sm border border-border-solid -mt-px flex gap-3 flex-col md:flex-row md:justify-between px-6 py-3">
<div className="flex items-center gap-2">
<IconPageTextLine size={16} className=" flex-none text-txt-tertiary" />
{document.title}

View File

@@ -9,8 +9,8 @@ import { graphql } from "relay-runtime";
import { useMutationWithToasts } from "/hooks/useMutationWithToast";
const signMutation = graphql`
mutation NDADialogSignMutation($input: AcceptNonDisclosureAgreementInput!) {
acceptNonDisclosureAgreement(input: $input) {
mutation NDADialogSignMutation {
acceptNonDisclosureAgreement {
success
}
}
@@ -20,12 +20,10 @@ export function NDADialog({
name,
url,
fileName,
trustCenterId,
}: {
name: string;
url?: string | null;
fileName?: string | null;
trustCenterId: string;
}) {
const { __ } = useTranslate();
useEffect(() => {
@@ -43,16 +41,6 @@ export function NDADialog({
},
});
const handleSign = () => {
commitSigning({
variables: {
input: {
trustCenterId,
},
},
});
};
return (
<div className="fixed inset-0 bg-level-2 z-100 flex flex-col lg:h-screen">
<header className="flex items-center h-12 justify-between border-b border-border-solid px-4 flex-none">
@@ -82,7 +70,7 @@ export function NDADialog({
</Card>
)}
<Button
onClick={handleSign}
onClick={() => commitSigning({ variables: {} })}
className="h-10 w-full my-8"
disabled={isSigning}
icon={isSigning ? Spinner : undefined}

View File

@@ -10,7 +10,7 @@ import { Viewer } from "/providers/Viewer";
export function OrganizationSidebar({
trustCenter,
}: {
trustCenter: TrustGraphQuery$data["trustCenterBySlug"];
trustCenter: TrustGraphQuery$data["currentTrustCenter"];
}) {
const { __ } = useTranslate();
const isAuthenticated = !!use(Viewer);

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<febdedca828f8b6dc384f0d4f08e02f8>>
* @generated SignedSource<<3ef589b34a5cb80406c517d6e5eb938c>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -9,12 +9,7 @@
// @ts-nocheck
import { ConcreteRequest } from 'relay-runtime';
export type AcceptNonDisclosureAgreementInput = {
trustCenterId: string;
};
export type NDADialogSignMutation$variables = {
input: AcceptNonDisclosureAgreementInput;
};
export type NDADialogSignMutation$variables = Record<PropertyKey, never>;
export type NDADialogSignMutation$data = {
readonly acceptNonDisclosureAgreement: {
readonly success: boolean;
@@ -27,22 +22,9 @@ export type NDADialogSignMutation = {
const node: ConcreteRequest = (function(){
var v0 = [
{
"defaultValue": null,
"kind": "LocalArgument",
"name": "input"
}
],
v1 = [
{
"alias": null,
"args": [
{
"kind": "Variable",
"name": "input",
"variableName": "input"
}
],
"args": null,
"concreteType": "AcceptNonDisclosureAgreementPayload",
"kind": "LinkedField",
"name": "acceptNonDisclosureAgreement",
@@ -61,32 +43,32 @@ v1 = [
];
return {
"fragment": {
"argumentDefinitions": (v0/*: any*/),
"argumentDefinitions": [],
"kind": "Fragment",
"metadata": null,
"name": "NDADialogSignMutation",
"selections": (v1/*: any*/),
"selections": (v0/*: any*/),
"type": "Mutation",
"abstractKey": null
},
"kind": "Request",
"operation": {
"argumentDefinitions": (v0/*: any*/),
"argumentDefinitions": [],
"kind": "Operation",
"name": "NDADialogSignMutation",
"selections": (v1/*: any*/)
"selections": (v0/*: any*/)
},
"params": {
"cacheID": "130cfc307dca0525194e0103a0548bd0",
"cacheID": "bca0dcb3f227c89d8339b0238aa2e42a",
"id": null,
"metadata": {},
"name": "NDADialogSignMutation",
"operationKind": "mutation",
"text": "mutation NDADialogSignMutation(\n $input: AcceptNonDisclosureAgreementInput!\n) {\n acceptNonDisclosureAgreement(input: $input) {\n success\n }\n}\n"
"text": "mutation NDADialogSignMutation {\n acceptNonDisclosureAgreement {\n success\n }\n}\n"
}
};
})();
(node as any).hash = "1b9447e5cbb2ec7dce4f3f9c68493555";
(node as any).hash = "814a623444a446730f260e6b7bbf0083";
export default node;

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<5113feef2c7f7b13a2d6348202086916>>
* @generated SignedSource<<9f01a480ccc5fa00e310296e9aed1020>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -13,7 +13,6 @@ export type RequestDocumentAccessInput = {
documentId: string;
email: any;
fullName: string;
trustCenterId: string;
};
export type RequestAccessDialogDocumentMutation$variables = {
input: RequestDocumentAccessInput;

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<294b6a25a178cf3bd9269591ef61381f>>
* @generated SignedSource<<0777fa7e6e3d0c75eedfc8380d9965a4>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -12,7 +12,6 @@ import { ConcreteRequest } from 'relay-runtime';
export type RequestAllAccessesInput = {
email: any;
fullName: string;
trustCenterId: string;
};
export type RequestAccessDialogMutation$variables = {
input: RequestAllAccessesInput;

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<d3209530c326da3c7db6535cef428ded>>
* @generated SignedSource<<6fde198cd3eaa998d665639c48f5e630>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -13,7 +13,6 @@ export type RequestReportAccessInput = {
email: any;
fullName: string;
reportId: string;
trustCenterId: string;
};
export type RequestAccessDialogReportMutation$variables = {
input: RequestReportAccessInput;

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<1e744bd11b2d5dd4d982bf1ce8b2a721>>
* @generated SignedSource<<7c329901bcf9bbf05b1899356016b151>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -13,7 +13,6 @@ export type RequestTrustCenterFileAccessInput = {
email: any;
fullName: string;
trustCenterFileId: string;
trustCenterId: string;
};
export type RequestAccessDialogTrustCenterFileMutation$variables = {
input: RequestTrustCenterFileAccessInput;

View File

@@ -31,7 +31,6 @@ export function MainLayout(props: Props) {
{showNDADialog && (
<NDADialog
name={trustCenter.organization.name}
trustCenterId={trustCenter.id}
url={trustCenter.ndaFileUrl}
fileName={trustCenter.ndaFileName}
/>

View File

@@ -68,7 +68,7 @@ const overviewFragment = graphql`
export function OverviewPage() {
const { trustCenter } = useOutletContext<{
trustCenter: OverviewPageFragment$key &
TrustGraphQuery$data["trustCenterBySlug"];
TrustGraphQuery$data["currentTrustCenter"];
}>();
const fragment = useFragment(overviewFragment, trustCenter);
return (
@@ -100,18 +100,18 @@ function Documents({
documents: OverviewPageFragment$data["documents"]["edges"];
files: OverviewPageFragment$data["trustCenterFiles"]["edges"];
audits: NonNullable<
TrustGraphQuery$data["trustCenterBySlug"]
TrustGraphQuery$data["currentTrustCenter"]
>["audits"]["edges"];
url: string;
}) {
const { __ } = useTranslate();
const documentsPerType = groupBy(
documents.map((edge) => edge.node),
(node) => documentTypeLabel(node.documentType, __)
(node) => documentTypeLabel(node.documentType, __),
);
const filesPerCategory = groupBy(
files.map((edge) => edge.node),
(node) => node.category
(node) => node.category,
);
const hasAudits = audits.length > 0;
const hasDocuments = hasAudits || documents.length > 0 || files.length > 0;
@@ -185,7 +185,7 @@ function Subprocessors({
<p className="text-sm text-txt-secondary mb-4">
{sprintf(
__("Third-party subprocessors %s work with:"),
organizationName
organizationName,
)}
</p>
<Rows className="mb-8 *:py-5">

View File

@@ -2,7 +2,7 @@ import { createContext, type ReactNode } from "react";
import type { TrustGraphQuery$data } from "/queries/__generated__/TrustGraphQuery.graphql";
export const TrustCenterContext = createContext<
TrustGraphQuery$data["trustCenterBySlug"] | null
TrustGraphQuery$data["currentTrustCenter"] | null
>(null);
export const TrustCenterProvider = ({
@@ -10,7 +10,7 @@ export const TrustCenterProvider = ({
trustCenter,
}: {
children: ReactNode;
trustCenter: TrustGraphQuery$data["trustCenterBySlug"];
trustCenter: TrustGraphQuery$data["currentTrustCenter"];
}) => {
return (
<TrustCenterContext.Provider value={trustCenter}>

View File

@@ -1,8 +1,8 @@
import { graphql } from "relay-runtime";
export const trustGraphQuery = graphql`
query TrustGraphQuery($slug: String!) {
trustCenterBySlug(slug: $slug) {
query TrustGraphQuery {
currentTrustCenter {
id
slug
isUserAuthenticated
@@ -31,8 +31,8 @@ export const trustGraphQuery = graphql`
`;
export const trustDocumentsQuery = graphql`
query TrustGraphDocumentsQuery($slug: String!) {
trustCenterBySlug(slug: $slug) {
query TrustGraphDocumentsQuery {
currentTrustCenter {
id
organization {
name
@@ -60,8 +60,8 @@ export const trustDocumentsQuery = graphql`
`;
export const trustVendorsQuery = graphql`
query TrustGraphVendorsQuery($slug: String!) {
trustCenterBySlug(slug: $slug) {
query TrustGraphVendorsQuery {
currentTrustCenter {
id
organization {
name

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<0faaebe3baf4c750825599985210137d>>
* @generated SignedSource<<7b9033da420b208f17d993bee5023358>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -11,11 +11,9 @@
import { ConcreteRequest } from 'relay-runtime';
import { FragmentRefs } from "relay-runtime";
export type DocumentType = "ISMS" | "OTHER" | "POLICY" | "PROCEDURE";
export type TrustGraphDocumentsQuery$variables = {
slug: string;
};
export type TrustGraphDocumentsQuery$variables = Record<PropertyKey, never>;
export type TrustGraphDocumentsQuery$data = {
readonly trustCenterBySlug: {
readonly currentTrustCenter: {
readonly documents: {
readonly edges: ReadonlyArray<{
readonly node: {
@@ -46,63 +44,49 @@ export type TrustGraphDocumentsQuery = {
};
const node: ConcreteRequest = (function(){
var v0 = [
{
"defaultValue": null,
"kind": "LocalArgument",
"name": "slug"
}
],
v1 = [
{
"kind": "Variable",
"name": "slug",
"variableName": "slug"
}
],
v2 = {
var v0 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "id",
"storageKey": null
},
v3 = {
v1 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "name",
"storageKey": null
},
v4 = [
v2 = [
{
"kind": "Literal",
"name": "first",
"value": 50
}
],
v5 = {
v3 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "documentType",
"storageKey": null
},
v6 = {
v4 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "category",
"storageKey": null
},
v7 = {
v5 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "isUserAuthorized",
"storageKey": null
},
v8 = {
v6 = {
"alias": null,
"args": null,
"kind": "ScalarField",
@@ -111,20 +95,20 @@ v8 = {
};
return {
"fragment": {
"argumentDefinitions": (v0/*: any*/),
"argumentDefinitions": [],
"kind": "Fragment",
"metadata": null,
"name": "TrustGraphDocumentsQuery",
"selections": [
{
"alias": null,
"args": (v1/*: any*/),
"args": null,
"concreteType": "TrustCenter",
"kind": "LinkedField",
"name": "trustCenterBySlug",
"name": "currentTrustCenter",
"plural": false,
"selections": [
(v2/*: any*/),
(v0/*: any*/),
{
"alias": null,
"args": null,
@@ -133,13 +117,13 @@ return {
"name": "organization",
"plural": false,
"selections": [
(v3/*: any*/)
(v1/*: any*/)
],
"storageKey": null
},
{
"alias": null,
"args": (v4/*: any*/),
"args": (v2/*: any*/),
"concreteType": "DocumentConnection",
"kind": "LinkedField",
"name": "documents",
@@ -161,8 +145,8 @@ return {
"name": "node",
"plural": false,
"selections": [
(v2/*: any*/),
(v5/*: any*/),
(v0/*: any*/),
(v3/*: any*/),
{
"args": null,
"kind": "FragmentSpread",
@@ -179,7 +163,7 @@ return {
},
{
"alias": null,
"args": (v4/*: any*/),
"args": (v2/*: any*/),
"concreteType": "TrustCenterFileConnection",
"kind": "LinkedField",
"name": "trustCenterFiles",
@@ -201,8 +185,8 @@ return {
"name": "node",
"plural": false,
"selections": [
(v2/*: any*/),
(v6/*: any*/),
(v0/*: any*/),
(v4/*: any*/),
{
"args": null,
"kind": "FragmentSpread",
@@ -226,19 +210,19 @@ return {
},
"kind": "Request",
"operation": {
"argumentDefinitions": (v0/*: any*/),
"argumentDefinitions": [],
"kind": "Operation",
"name": "TrustGraphDocumentsQuery",
"selections": [
{
"alias": null,
"args": (v1/*: any*/),
"args": null,
"concreteType": "TrustCenter",
"kind": "LinkedField",
"name": "trustCenterBySlug",
"name": "currentTrustCenter",
"plural": false,
"selections": [
(v2/*: any*/),
(v0/*: any*/),
{
"alias": null,
"args": null,
@@ -247,14 +231,14 @@ return {
"name": "organization",
"plural": false,
"selections": [
(v3/*: any*/),
(v2/*: any*/)
(v1/*: any*/),
(v0/*: any*/)
],
"storageKey": null
},
{
"alias": null,
"args": (v4/*: any*/),
"args": (v2/*: any*/),
"concreteType": "DocumentConnection",
"kind": "LinkedField",
"name": "documents",
@@ -276,8 +260,8 @@ return {
"name": "node",
"plural": false,
"selections": [
(v2/*: any*/),
(v5/*: any*/),
(v0/*: any*/),
(v3/*: any*/),
{
"alias": null,
"args": null,
@@ -285,8 +269,8 @@ return {
"name": "title",
"storageKey": null
},
(v7/*: any*/),
(v8/*: any*/)
(v5/*: any*/),
(v6/*: any*/)
],
"storageKey": null
}
@@ -298,7 +282,7 @@ return {
},
{
"alias": null,
"args": (v4/*: any*/),
"args": (v2/*: any*/),
"concreteType": "TrustCenterFileConnection",
"kind": "LinkedField",
"name": "trustCenterFiles",
@@ -320,11 +304,11 @@ return {
"name": "node",
"plural": false,
"selections": [
(v2/*: any*/),
(v6/*: any*/),
(v3/*: any*/),
(v7/*: any*/),
(v8/*: any*/)
(v0/*: any*/),
(v4/*: any*/),
(v1/*: any*/),
(v5/*: any*/),
(v6/*: any*/)
],
"storageKey": null
}
@@ -340,16 +324,16 @@ return {
]
},
"params": {
"cacheID": "151fc8b1cf3becb2a69d87ce978fb71b",
"cacheID": "cf917e2efd7c2f644d222385443fd923",
"id": null,
"metadata": {},
"name": "TrustGraphDocumentsQuery",
"operationKind": "query",
"text": "query TrustGraphDocumentsQuery(\n $slug: String!\n) {\n trustCenterBySlug(slug: $slug) {\n id\n organization {\n name\n id\n }\n documents(first: 50) {\n edges {\n node {\n id\n documentType\n ...DocumentRowFragment\n }\n }\n }\n trustCenterFiles(first: 50) {\n edges {\n node {\n id\n category\n ...TrustCenterFileRowFragment\n }\n }\n }\n }\n}\n\nfragment DocumentRowFragment on Document {\n id\n title\n isUserAuthorized\n hasUserRequestedAccess\n}\n\nfragment TrustCenterFileRowFragment on TrustCenterFile {\n id\n name\n isUserAuthorized\n hasUserRequestedAccess\n}\n"
"text": "query TrustGraphDocumentsQuery {\n currentTrustCenter {\n id\n organization {\n name\n id\n }\n documents(first: 50) {\n edges {\n node {\n id\n documentType\n ...DocumentRowFragment\n }\n }\n }\n trustCenterFiles(first: 50) {\n edges {\n node {\n id\n category\n ...TrustCenterFileRowFragment\n }\n }\n }\n }\n}\n\nfragment DocumentRowFragment on Document {\n id\n title\n isUserAuthorized\n hasUserRequestedAccess\n}\n\nfragment TrustCenterFileRowFragment on TrustCenterFile {\n id\n name\n isUserAuthorized\n hasUserRequestedAccess\n}\n"
}
};
})();
(node as any).hash = "79e21d586ec18a0977c37df27aa9bdea";
(node as any).hash = "32ee5adbf1a5cf44f836f45990a95732";
export default node;

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<6458ae0015d6100916a1d446c608f61c>>
* @generated SignedSource<<1a198d80eadc34edf67fd0f757c6f120>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -10,11 +10,9 @@
import { ConcreteRequest } from 'relay-runtime';
import { FragmentRefs } from "relay-runtime";
export type TrustGraphQuery$variables = {
slug: string;
};
export type TrustGraphQuery$variables = Record<PropertyKey, never>;
export type TrustGraphQuery$data = {
readonly trustCenterBySlug: {
readonly currentTrustCenter: {
readonly audits: {
readonly edges: ReadonlyArray<{
readonly node: {
@@ -46,133 +44,119 @@ export type TrustGraphQuery = {
};
const node: ConcreteRequest = (function(){
var v0 = [
{
"defaultValue": null,
"kind": "LocalArgument",
"name": "slug"
}
],
v1 = [
{
"kind": "Variable",
"name": "slug",
"variableName": "slug"
}
],
v2 = {
var v0 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "id",
"storageKey": null
},
v3 = {
v1 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "slug",
"storageKey": null
},
v4 = {
v2 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "isUserAuthenticated",
"storageKey": null
},
v5 = {
v3 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "hasAcceptedNonDisclosureAgreement",
"storageKey": null
},
v6 = {
v4 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "ndaFileName",
"storageKey": null
},
v7 = {
v5 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "ndaFileUrl",
"storageKey": null
},
v8 = {
v6 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "name",
"storageKey": null
},
v9 = {
v7 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "description",
"storageKey": null
},
v10 = {
v8 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "websiteUrl",
"storageKey": null
},
v11 = {
v9 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "logoUrl",
"storageKey": null
},
v12 = {
v10 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "email",
"storageKey": null
},
v13 = {
v11 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "headquarterAddress",
"storageKey": null
},
v14 = [
v12 = [
{
"kind": "Literal",
"name": "first",
"value": 50
}
],
v15 = {
v13 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "category",
"storageKey": null
},
v16 = [
v14 = [
{
"kind": "Literal",
"name": "first",
"value": 5
}
],
v17 = {
v15 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "isUserAuthorized",
"storageKey": null
},
v18 = {
v16 = {
"alias": null,
"args": null,
"kind": "ScalarField",
@@ -181,25 +165,25 @@ v18 = {
};
return {
"fragment": {
"argumentDefinitions": (v0/*: any*/),
"argumentDefinitions": [],
"kind": "Fragment",
"metadata": null,
"name": "TrustGraphQuery",
"selections": [
{
"alias": null,
"args": (v1/*: any*/),
"args": null,
"concreteType": "TrustCenter",
"kind": "LinkedField",
"name": "trustCenterBySlug",
"name": "currentTrustCenter",
"plural": false,
"selections": [
(v0/*: any*/),
(v1/*: any*/),
(v2/*: any*/),
(v3/*: any*/),
(v4/*: any*/),
(v5/*: any*/),
(v6/*: any*/),
(v7/*: any*/),
{
"alias": null,
"args": null,
@@ -208,12 +192,12 @@ return {
"name": "organization",
"plural": false,
"selections": [
(v6/*: any*/),
(v7/*: any*/),
(v8/*: any*/),
(v9/*: any*/),
(v10/*: any*/),
(v11/*: any*/),
(v12/*: any*/),
(v13/*: any*/)
(v11/*: any*/)
],
"storageKey": null
},
@@ -224,7 +208,7 @@ return {
},
{
"alias": null,
"args": (v14/*: any*/),
"args": (v12/*: any*/),
"concreteType": "AuditConnection",
"kind": "LinkedField",
"name": "audits",
@@ -246,7 +230,7 @@ return {
"name": "node",
"plural": false,
"selections": [
(v2/*: any*/),
(v0/*: any*/),
{
"args": null,
"kind": "FragmentSpread",
@@ -270,24 +254,24 @@ return {
},
"kind": "Request",
"operation": {
"argumentDefinitions": (v0/*: any*/),
"argumentDefinitions": [],
"kind": "Operation",
"name": "TrustGraphQuery",
"selections": [
{
"alias": null,
"args": (v1/*: any*/),
"args": null,
"concreteType": "TrustCenter",
"kind": "LinkedField",
"name": "trustCenterBySlug",
"name": "currentTrustCenter",
"plural": false,
"selections": [
(v0/*: any*/),
(v1/*: any*/),
(v2/*: any*/),
(v3/*: any*/),
(v4/*: any*/),
(v5/*: any*/),
(v6/*: any*/),
(v7/*: any*/),
{
"alias": null,
"args": null,
@@ -296,13 +280,13 @@ return {
"name": "organization",
"plural": false,
"selections": [
(v6/*: any*/),
(v7/*: any*/),
(v8/*: any*/),
(v9/*: any*/),
(v10/*: any*/),
(v11/*: any*/),
(v12/*: any*/),
(v13/*: any*/),
(v2/*: any*/)
(v0/*: any*/)
],
"storageKey": null
},
@@ -336,10 +320,10 @@ return {
"name": "node",
"plural": false,
"selections": [
(v2/*: any*/),
(v8/*: any*/),
(v11/*: any*/),
(v10/*: any*/)
(v0/*: any*/),
(v6/*: any*/),
(v9/*: any*/),
(v8/*: any*/)
],
"storageKey": null
}
@@ -379,7 +363,7 @@ return {
"name": "node",
"plural": false,
"selections": [
(v2/*: any*/),
(v0/*: any*/),
{
"alias": null,
"args": null,
@@ -387,9 +371,9 @@ return {
"name": "countries",
"storageKey": null
},
(v6/*: any*/),
(v13/*: any*/),
(v8/*: any*/),
(v15/*: any*/),
(v10/*: any*/),
{
"alias": null,
"args": null,
@@ -408,7 +392,7 @@ return {
},
{
"alias": null,
"args": (v16/*: any*/),
"args": (v14/*: any*/),
"concreteType": "DocumentConnection",
"kind": "LinkedField",
"name": "documents",
@@ -430,7 +414,7 @@ return {
"name": "node",
"plural": false,
"selections": [
(v2/*: any*/),
(v0/*: any*/),
{
"alias": null,
"args": null,
@@ -438,8 +422,8 @@ return {
"name": "title",
"storageKey": null
},
(v17/*: any*/),
(v18/*: any*/),
(v15/*: any*/),
(v16/*: any*/),
{
"alias": null,
"args": null,
@@ -458,7 +442,7 @@ return {
},
{
"alias": null,
"args": (v16/*: any*/),
"args": (v14/*: any*/),
"concreteType": "TrustCenterFileConnection",
"kind": "LinkedField",
"name": "trustCenterFiles",
@@ -480,11 +464,11 @@ return {
"name": "node",
"plural": false,
"selections": [
(v2/*: any*/),
(v0/*: any*/),
(v13/*: any*/),
(v6/*: any*/),
(v15/*: any*/),
(v8/*: any*/),
(v17/*: any*/),
(v18/*: any*/)
(v16/*: any*/)
],
"storageKey": null
}
@@ -496,7 +480,7 @@ return {
},
{
"alias": null,
"args": (v14/*: any*/),
"args": (v12/*: any*/),
"concreteType": "AuditConnection",
"kind": "LinkedField",
"name": "audits",
@@ -518,7 +502,7 @@ return {
"name": "node",
"plural": false,
"selections": [
(v2/*: any*/),
(v0/*: any*/),
{
"alias": null,
"args": null,
@@ -527,7 +511,7 @@ return {
"name": "report",
"plural": false,
"selections": [
(v2/*: any*/),
(v0/*: any*/),
{
"alias": null,
"args": null,
@@ -535,8 +519,8 @@ return {
"name": "filename",
"storageKey": null
},
(v17/*: any*/),
(v18/*: any*/)
(v15/*: any*/),
(v16/*: any*/)
],
"storageKey": null
},
@@ -548,8 +532,8 @@ return {
"name": "framework",
"plural": false,
"selections": [
(v2/*: any*/),
(v8/*: any*/),
(v0/*: any*/),
(v6/*: any*/),
{
"alias": null,
"args": null,
@@ -582,16 +566,16 @@ return {
]
},
"params": {
"cacheID": "7f7d3a2db2deb10550db16704993a2d0",
"cacheID": "86e2d66de7f28486d0a0b649661c2d43",
"id": null,
"metadata": {},
"name": "TrustGraphQuery",
"operationKind": "query",
"text": "query TrustGraphQuery(\n $slug: String!\n) {\n trustCenterBySlug(slug: $slug) {\n id\n slug\n isUserAuthenticated\n hasAcceptedNonDisclosureAgreement\n ndaFileName\n ndaFileUrl\n organization {\n name\n description\n websiteUrl\n logoUrl\n email\n headquarterAddress\n id\n }\n ...OverviewPageFragment\n audits(first: 50) {\n edges {\n node {\n id\n ...AuditRowFragment\n }\n }\n }\n }\n}\n\nfragment AuditRowFragment on Audit {\n report {\n id\n filename\n isUserAuthorized\n hasUserRequestedAccess\n }\n framework {\n id\n name\n lightLogoURL\n darkLogoURL\n }\n}\n\nfragment DocumentRowFragment on Document {\n id\n title\n isUserAuthorized\n hasUserRequestedAccess\n}\n\nfragment OverviewPageFragment on TrustCenter {\n references(first: 14) {\n edges {\n node {\n id\n name\n logoUrl\n websiteUrl\n }\n }\n }\n vendors(first: 3) {\n edges {\n node {\n id\n countries\n ...VendorRowFragment\n }\n }\n }\n documents(first: 5) {\n edges {\n node {\n id\n ...DocumentRowFragment\n documentType\n }\n }\n }\n trustCenterFiles(first: 5) {\n edges {\n node {\n id\n category\n ...TrustCenterFileRowFragment\n }\n }\n }\n}\n\nfragment TrustCenterFileRowFragment on TrustCenterFile {\n id\n name\n isUserAuthorized\n hasUserRequestedAccess\n}\n\nfragment VendorRowFragment on Vendor {\n id\n name\n category\n websiteUrl\n privacyPolicyUrl\n countries\n}\n"
"text": "query TrustGraphQuery {\n currentTrustCenter {\n id\n slug\n isUserAuthenticated\n hasAcceptedNonDisclosureAgreement\n ndaFileName\n ndaFileUrl\n organization {\n name\n description\n websiteUrl\n logoUrl\n email\n headquarterAddress\n id\n }\n ...OverviewPageFragment\n audits(first: 50) {\n edges {\n node {\n id\n ...AuditRowFragment\n }\n }\n }\n }\n}\n\nfragment AuditRowFragment on Audit {\n report {\n id\n filename\n isUserAuthorized\n hasUserRequestedAccess\n }\n framework {\n id\n name\n lightLogoURL\n darkLogoURL\n }\n}\n\nfragment DocumentRowFragment on Document {\n id\n title\n isUserAuthorized\n hasUserRequestedAccess\n}\n\nfragment OverviewPageFragment on TrustCenter {\n references(first: 14) {\n edges {\n node {\n id\n name\n logoUrl\n websiteUrl\n }\n }\n }\n vendors(first: 3) {\n edges {\n node {\n id\n countries\n ...VendorRowFragment\n }\n }\n }\n documents(first: 5) {\n edges {\n node {\n id\n ...DocumentRowFragment\n documentType\n }\n }\n }\n trustCenterFiles(first: 5) {\n edges {\n node {\n id\n category\n ...TrustCenterFileRowFragment\n }\n }\n }\n}\n\nfragment TrustCenterFileRowFragment on TrustCenterFile {\n id\n name\n isUserAuthorized\n hasUserRequestedAccess\n}\n\nfragment VendorRowFragment on Vendor {\n id\n name\n category\n websiteUrl\n privacyPolicyUrl\n countries\n}\n"
}
};
})();
(node as any).hash = "fd44a0d5fcda45aaa0fe02b3051643c0";
(node as any).hash = "03abd3f1a77fe3d8799cdf69d0b30fad";
export default node;

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<a66aa837cc3bc56dd942e0eb62805d8f>>
* @generated SignedSource<<72173b053a11fc1da7712cc7167c8d31>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -11,11 +11,9 @@
import { ConcreteRequest } from 'relay-runtime';
import { FragmentRefs } from "relay-runtime";
export type CountryCode = "AD" | "AE" | "AF" | "AG" | "AI" | "AL" | "AM" | "AO" | "AQ" | "AR" | "AS" | "AT" | "AU" | "AW" | "AX" | "AZ" | "BA" | "BB" | "BD" | "BE" | "BF" | "BG" | "BH" | "BI" | "BJ" | "BL" | "BM" | "BN" | "BO" | "BQ" | "BR" | "BS" | "BT" | "BV" | "BW" | "BY" | "BZ" | "CA" | "CC" | "CD" | "CF" | "CG" | "CH" | "CI" | "CK" | "CL" | "CM" | "CN" | "CO" | "CR" | "CU" | "CV" | "CW" | "CX" | "CY" | "CZ" | "DE" | "DJ" | "DK" | "DM" | "DO" | "DZ" | "EC" | "EE" | "EG" | "EH" | "ER" | "ES" | "ET" | "EU" | "FI" | "FJ" | "FK" | "FM" | "FO" | "FR" | "GA" | "GB" | "GD" | "GE" | "GF" | "GG" | "GH" | "GI" | "GL" | "GM" | "GN" | "GP" | "GQ" | "GR" | "GT" | "GU" | "GW" | "GY" | "HK" | "HM" | "HN" | "HR" | "HT" | "HU" | "ID" | "IE" | "IL" | "IM" | "IN" | "IO" | "IQ" | "IR" | "IS" | "IT" | "JE" | "JM" | "JO" | "JP" | "KE" | "KG" | "KH" | "KI" | "KM" | "KN" | "KP" | "KR" | "KW" | "KY" | "KZ" | "LA" | "LB" | "LC" | "LI" | "LK" | "LR" | "LS" | "LT" | "LU" | "LV" | "LY" | "MA" | "MC" | "MD" | "ME" | "MF" | "MG" | "MH" | "MK" | "ML" | "MM" | "MN" | "MO" | "MP" | "MQ" | "MR" | "MS" | "MT" | "MU" | "MV" | "MW" | "MX" | "MY" | "MZ" | "NA" | "NC" | "NE" | "NF" | "NG" | "NI" | "NL" | "NO" | "NP" | "NR" | "NU" | "NZ" | "OM" | "PA" | "PE" | "PF" | "PG" | "PH" | "PK" | "PL" | "PM" | "PN" | "PR" | "PS" | "PT" | "PW" | "PY" | "QA" | "RE" | "RO" | "RS" | "RU" | "RW" | "SA" | "SB" | "SC" | "SD" | "SE" | "SG" | "SH" | "SI" | "SJ" | "SK" | "SL" | "SM" | "SN" | "SO" | "SR" | "SS" | "ST" | "SV" | "SX" | "SY" | "SZ" | "TC" | "TD" | "TF" | "TG" | "TH" | "TJ" | "TK" | "TL" | "TM" | "TN" | "TO" | "TR" | "TT" | "TV" | "TW" | "TZ" | "UA" | "UG" | "UM" | "US" | "UY" | "UZ" | "VA" | "VC" | "VE" | "VG" | "VI" | "VN" | "VU" | "WF" | "WS" | "YE" | "YT" | "ZA" | "ZM" | "ZW";
export type TrustGraphVendorsQuery$variables = {
slug: string;
};
export type TrustGraphVendorsQuery$variables = Record<PropertyKey, never>;
export type TrustGraphVendorsQuery$data = {
readonly trustCenterBySlug: {
readonly currentTrustCenter: {
readonly id: string;
readonly organization: {
readonly name: string;
@@ -37,42 +35,28 @@ export type TrustGraphVendorsQuery = {
};
const node: ConcreteRequest = (function(){
var v0 = [
{
"defaultValue": null,
"kind": "LocalArgument",
"name": "slug"
}
],
v1 = [
{
"kind": "Variable",
"name": "slug",
"variableName": "slug"
}
],
v2 = {
var v0 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "id",
"storageKey": null
},
v3 = {
v1 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "name",
"storageKey": null
},
v4 = [
v2 = [
{
"kind": "Literal",
"name": "first",
"value": 50
}
],
v5 = {
v3 = {
"alias": null,
"args": null,
"kind": "ScalarField",
@@ -81,20 +65,20 @@ v5 = {
};
return {
"fragment": {
"argumentDefinitions": (v0/*: any*/),
"argumentDefinitions": [],
"kind": "Fragment",
"metadata": null,
"name": "TrustGraphVendorsQuery",
"selections": [
{
"alias": null,
"args": (v1/*: any*/),
"args": null,
"concreteType": "TrustCenter",
"kind": "LinkedField",
"name": "trustCenterBySlug",
"name": "currentTrustCenter",
"plural": false,
"selections": [
(v2/*: any*/),
(v0/*: any*/),
{
"alias": null,
"args": null,
@@ -103,13 +87,13 @@ return {
"name": "organization",
"plural": false,
"selections": [
(v3/*: any*/)
(v1/*: any*/)
],
"storageKey": null
},
{
"alias": null,
"args": (v4/*: any*/),
"args": (v2/*: any*/),
"concreteType": "VendorConnection",
"kind": "LinkedField",
"name": "vendors",
@@ -131,8 +115,8 @@ return {
"name": "node",
"plural": false,
"selections": [
(v2/*: any*/),
(v5/*: any*/),
(v0/*: any*/),
(v3/*: any*/),
{
"args": null,
"kind": "FragmentSpread",
@@ -156,19 +140,19 @@ return {
},
"kind": "Request",
"operation": {
"argumentDefinitions": (v0/*: any*/),
"argumentDefinitions": [],
"kind": "Operation",
"name": "TrustGraphVendorsQuery",
"selections": [
{
"alias": null,
"args": (v1/*: any*/),
"args": null,
"concreteType": "TrustCenter",
"kind": "LinkedField",
"name": "trustCenterBySlug",
"name": "currentTrustCenter",
"plural": false,
"selections": [
(v2/*: any*/),
(v0/*: any*/),
{
"alias": null,
"args": null,
@@ -177,14 +161,14 @@ return {
"name": "organization",
"plural": false,
"selections": [
(v3/*: any*/),
(v2/*: any*/)
(v1/*: any*/),
(v0/*: any*/)
],
"storageKey": null
},
{
"alias": null,
"args": (v4/*: any*/),
"args": (v2/*: any*/),
"concreteType": "VendorConnection",
"kind": "LinkedField",
"name": "vendors",
@@ -206,9 +190,9 @@ return {
"name": "node",
"plural": false,
"selections": [
(v2/*: any*/),
(v5/*: any*/),
(v0/*: any*/),
(v3/*: any*/),
(v1/*: any*/),
{
"alias": null,
"args": null,
@@ -245,16 +229,16 @@ return {
]
},
"params": {
"cacheID": "4b60b2757d58e49101104addf411eff2",
"cacheID": "ab7e606f23e33445efbccc09a91e4c95",
"id": null,
"metadata": {},
"name": "TrustGraphVendorsQuery",
"operationKind": "query",
"text": "query TrustGraphVendorsQuery(\n $slug: String!\n) {\n trustCenterBySlug(slug: $slug) {\n id\n organization {\n name\n id\n }\n vendors(first: 50) {\n edges {\n node {\n id\n countries\n ...VendorRowFragment\n }\n }\n }\n }\n}\n\nfragment VendorRowFragment on Vendor {\n id\n name\n category\n websiteUrl\n privacyPolicyUrl\n countries\n}\n"
"text": "query TrustGraphVendorsQuery {\n currentTrustCenter {\n id\n organization {\n name\n id\n }\n vendors(first: 50) {\n edges {\n node {\n id\n countries\n ...VendorRowFragment\n }\n }\n }\n }\n}\n\nfragment VendorRowFragment on Vendor {\n id\n name\n category\n websiteUrl\n privacyPolicyUrl\n countries\n}\n"
}
};
})();
(node as any).hash = "9a4c9326d25ea59f5898467e38083caa";
(node as any).hash = "c38f80f339187ccce1c0dec76e9a9bd2";
export default node;

View File

@@ -17,6 +17,7 @@ export default defineConfig({
target: "http://localhost:8080",
changeOrigin: true,
},
// FIXME: remove
"/trust/YJwjPEJCAAEAFgAAAZsTYtQt-FLmpawO/api": {
target: "http://localhost:8080",
changeOrigin: true,

View File

@@ -420,73 +420,3 @@ func (s *Service) LoadOrganizationByDomain(ctx context.Context, domain string) (
return organizationID, err
}
type TrustCenterInfo struct {
ID gid.GID
OrganizationID gid.GID
}
func (s *Service) LoadTrustCenterBySlug(ctx context.Context, slug string) (*TrustCenterInfo, error) {
var info TrustCenterInfo
err := s.pg.WithConn(
ctx,
func(conn pg.Conn) error {
var trustCenter coredata.TrustCenter
if err := trustCenter.LoadBySlug(ctx, conn, slug); err != nil {
return fmt.Errorf("cannot load trust center: %w", err)
}
info.ID = trustCenter.ID
info.OrganizationID = trustCenter.OrganizationID
return nil
},
)
return &info, err
}
func (s *Service) LoadTrustCenterByID(ctx context.Context, id gid.GID) (*TrustCenterInfo, error) {
var info TrustCenterInfo
err := s.pg.WithConn(
ctx,
func(conn pg.Conn) error {
scope := coredata.NewScope(id.TenantID())
var trustCenter coredata.TrustCenter
if err := trustCenter.LoadByID(ctx, conn, scope, id); err != nil {
return fmt.Errorf("cannot load trust center: %w", err)
}
info.ID = trustCenter.ID
info.OrganizationID = trustCenter.OrganizationID
return nil
},
)
return &info, err
}
func (s *Service) LoadTrustCenterByOrganizationID(ctx context.Context, organizationID gid.GID) (*TrustCenterInfo, error) {
var info TrustCenterInfo
err := s.pg.WithConn(
ctx,
func(conn pg.Conn) error {
scope := coredata.NewScope(organizationID.TenantID())
var trustCenter coredata.TrustCenter
if err := trustCenter.LoadByOrganizationID(ctx, conn, scope, organizationID); err != nil {
return fmt.Errorf("cannot load trust center: %w", err)
}
info.ID = trustCenter.ID
info.OrganizationID = trustCenter.OrganizationID
return nil
},
)
return &info, err
}

View File

@@ -0,0 +1,52 @@
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
package compliancepage
import (
"net/http"
"github.com/99designs/gqlgen/graphql"
"github.com/vektah/gqlparser/v2/gqlerror"
"go.gearno.de/kit/httpserver"
"go.probo.inc/probo/pkg/server/gqlutils"
)
func NewCompliancePagePresenceMiddleware() func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
compliancePage := CompliancePageFromContext(r.Context())
if compliancePage == nil {
httpserver.RenderJSON(
w,
http.StatusNotFound,
&graphql.Response{
Errors: gqlerror.List{
gqlutils.NotFoundf(
r.Context(),
"compliance page not found",
),
},
},
)
return
}
next.ServeHTTP(w, r)
},
)
}
}

View File

@@ -0,0 +1,32 @@
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
package compliancepage
import (
"context"
"go.probo.inc/probo/pkg/coredata"
)
type ctxKey struct{ name string }
var (
compliancePageKey = &ctxKey{name: "compliance_page"}
)
func CompliancePageFromContext(ctx context.Context) *coredata.TrustCenter {
trustCenter, _ := ctx.Value(compliancePageKey).(*coredata.TrustCenter)
return trustCenter
}

View File

@@ -0,0 +1,56 @@
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
package compliancepage
import (
"context"
"net/http"
"github.com/go-chi/chi/v5"
"go.probo.inc/probo/pkg/gid"
"go.probo.inc/probo/pkg/trust"
)
func NewIDMiddleware(trustSvc *trust.Service) func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
// TODO: remove slug support
value := chi.URLParam(r, "slugOrId")
if id, err := gid.ParseGID(value); err == nil {
compliancePage, err := trustSvc.Get(ctx, id)
if err != nil || !compliancePage.Active {
next.ServeHTTP(w, r)
return
}
ctx = context.WithValue(ctx, compliancePageKey, compliancePage)
next.ServeHTTP(w, r.WithContext(ctx))
return
}
if compliancePage, err := trustSvc.GetBySlug(ctx, value); err == nil && compliancePage.Active {
ctx = context.WithValue(ctx, compliancePageKey, compliancePage)
next.ServeHTTP(w, r.WithContext(ctx))
return
}
next.ServeHTTP(w, r)
},
)
}
}

View File

@@ -0,0 +1,44 @@
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
package compliancepage
import (
"context"
"net/http"
"go.probo.inc/probo/pkg/trust"
)
func NewSNIMiddleware(trustSvc *trust.Service) func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
if r.TLS == nil {
next.ServeHTTP(w, r)
return
}
compliancePage, err := trustSvc.GetByDomainName(ctx, r.TLS.ServerName)
if err != nil || !compliancePage.Active {
next.ServeHTTP(w, r)
return
}
ctx = context.WithValue(ctx, compliancePageKey, compliancePage)
next.ServeHTTP(w, r.WithContext(ctx))
})
}
}

View File

@@ -28,7 +28,6 @@ import (
"go.probo.inc/probo/pkg/server/api/authn"
"go.probo.inc/probo/pkg/server/api/authz"
"go.probo.inc/probo/pkg/server/api/connect/v1/types"
"go.probo.inc/probo/pkg/server/gqlutils"
)
type (
@@ -44,8 +43,6 @@ type (
func NewMux(logger *log.Logger, svc *iam.Service, cookieConfig securecookie.Config, tokenSecret string, baseURL *baseurl.BaseURL) *chi.Mux {
r := chi.NewMux()
r.Use(gqlutils.HTTPContextMiddleware)
sessionMiddleware := authn.NewSessionMiddleware(svc, cookieConfig)
apiKeyMiddleware := authn.NewAPIKeyMiddleware(svc, tokenSecret)
graphqlHandler := NewGraphQLHandler(svc, logger, baseURL, cookieConfig)

View File

@@ -25,9 +25,9 @@ import (
"go.gearno.de/kit/log"
"go.probo.inc/probo/pkg/gid"
"go.probo.inc/probo/pkg/iam"
"go.probo.inc/probo/pkg/probo"
"go.probo.inc/probo/pkg/securecookie"
"go.probo.inc/probo/pkg/server/api/authn"
"go.probo.inc/probo/pkg/server/api/compliancepage"
"go.probo.inc/probo/pkg/server/api/trust/v1/schema"
"go.probo.inc/probo/pkg/server/api/trust/v1/types"
"go.probo.inc/probo/pkg/server/gqlutils"
@@ -58,16 +58,19 @@ type (
type ctxKey struct{ name string }
var (
TrustCenterKey = &ctxKey{name: "trust_center"}
trustCenterIDKey = &ctxKey{name: "trust_center_id"}
)
func TrustCenterFromContext(ctx context.Context) probo.TrustCenterInfo {
trustCenter, _ := ctx.Value(TrustCenterKey).(probo.TrustCenterInfo)
return trustCenter
func TrustCenterIDFromContext(ctx context.Context) gid.GID {
if trustCenterID, ok := ctx.Value(trustCenterIDKey).(gid.GID); ok {
return trustCenterID
}
return gid.Nil
}
func ContextWithTrustCenter(ctx context.Context, trustCenter probo.TrustCenterInfo) context.Context {
return context.WithValue(ctx, TrustCenterKey, trustCenter)
func ContextWithTrustCenterID(ctx context.Context, trustCenterID gid.GID) context.Context {
return context.WithValue(ctx, trustCenterIDKey, trustCenterID)
}
func NewMux(
@@ -78,8 +81,8 @@ func NewMux(
) *chi.Mux {
r := chi.NewMux()
sessionMiddleware := authn.NewSessionMiddleware(iamSvc, cookieConfig)
r.Use(sessionMiddleware)
r.Use(compliancepage.NewCompliancePagePresenceMiddleware())
r.Use(authn.NewSessionMiddleware(iamSvc, cookieConfig))
config := schema.Config{
Resolvers: &Resolver{

View File

@@ -553,7 +553,6 @@ type SignInWithTokenPayload {
}
input RequestAllAccessesInput {
trustCenterId: ID!
email: EmailAddr!
fullName: String!
}
@@ -570,26 +569,19 @@ input ExportReportPDFInput {
reportId: ID!
}
input AcceptNonDisclosureAgreementInput {
trustCenterId: ID!
}
input RequestDocumentAccessInput {
trustCenterId: ID!
documentId: ID!
email: EmailAddr!
fullName: String!
}
input RequestReportAccessInput {
trustCenterId: ID!
reportId: ID!
email: EmailAddr!
fullName: String!
}
input RequestTrustCenterFileAccessInput {
trustCenterId: ID!
trustCenterFileId: ID!
email: EmailAddr!
fullName: String!
@@ -618,7 +610,6 @@ type AcceptNonDisclosureAgreementPayload {
type Query {
viewer: Identity
node(id: ID!): Node!
trustCenterBySlug(slug: String!): TrustCenter @mustBeAuthenticated(role: NONE)
currentTrustCenter: TrustCenter @mustBeAuthenticated(role: NONE)
}
@@ -634,9 +625,8 @@ type Mutation {
exportReportPDF(input: ExportReportPDFInput!): ExportReportPDFPayload!
@mustBeAuthenticated(role: NONE)
acceptNonDisclosureAgreement(
input: AcceptNonDisclosureAgreementInput!
): AcceptNonDisclosureAgreementPayload! @mustBeAuthenticated(role: USER)
acceptNonDisclosureAgreement: AcceptNonDisclosureAgreementPayload!
@mustBeAuthenticated(role: USER)
requestDocumentAccess(
input: RequestDocumentAccessInput!

View File

@@ -130,7 +130,7 @@ type ComplexityRoot struct {
}
Mutation struct {
AcceptNonDisclosureAgreement func(childComplexity int, input types.AcceptNonDisclosureAgreementInput) int
AcceptNonDisclosureAgreement func(childComplexity int) int
ExportDocumentPDF func(childComplexity int, input types.ExportDocumentPDFInput) int
ExportReportPDF func(childComplexity int, input types.ExportReportPDFInput) int
ExportTrustCenterFile func(childComplexity int, input types.ExportTrustCenterFileInput) int
@@ -161,7 +161,6 @@ type ComplexityRoot struct {
Query struct {
CurrentTrustCenter func(childComplexity int) int
Node func(childComplexity int, id gid.GID) int
TrustCenterBySlug func(childComplexity int, slug string) int
Viewer func(childComplexity int) int
}
@@ -277,7 +276,7 @@ type MutationResolver interface {
RequestAllAccesses(ctx context.Context, input types.RequestAllAccessesInput) (*types.RequestAccessesPayload, error)
ExportDocumentPDF(ctx context.Context, input types.ExportDocumentPDFInput) (*types.ExportDocumentPDFPayload, error)
ExportReportPDF(ctx context.Context, input types.ExportReportPDFInput) (*types.ExportReportPDFPayload, error)
AcceptNonDisclosureAgreement(ctx context.Context, input types.AcceptNonDisclosureAgreementInput) (*types.AcceptNonDisclosureAgreementPayload, error)
AcceptNonDisclosureAgreement(ctx context.Context) (*types.AcceptNonDisclosureAgreementPayload, error)
RequestDocumentAccess(ctx context.Context, input types.RequestDocumentAccessInput) (*types.RequestAccessesPayload, error)
RequestReportAccess(ctx context.Context, input types.RequestReportAccessInput) (*types.RequestAccessesPayload, error)
RequestTrustCenterFileAccess(ctx context.Context, input types.RequestTrustCenterFileAccessInput) (*types.RequestAccessesPayload, error)
@@ -289,7 +288,6 @@ type OrganizationResolver interface {
type QueryResolver interface {
Viewer(ctx context.Context) (*types.Identity, error)
Node(ctx context.Context, id gid.GID) (types.Node, error)
TrustCenterBySlug(ctx context.Context, slug string) (*types.TrustCenter, error)
CurrentTrustCenter(ctx context.Context) (*types.TrustCenter, error)
}
type ReportResolver interface {
@@ -531,12 +529,7 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin
break
}
args, err := ec.field_Mutation_acceptNonDisclosureAgreement_args(ctx, rawArgs)
if err != nil {
return 0, false
}
return e.complexity.Mutation.AcceptNonDisclosureAgreement(childComplexity, args["input"].(types.AcceptNonDisclosureAgreementInput)), true
return e.complexity.Mutation.AcceptNonDisclosureAgreement(childComplexity), true
case "Mutation.exportDocumentPDF":
if e.complexity.Mutation.ExportDocumentPDF == nil {
break
@@ -711,17 +704,6 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin
}
return e.complexity.Query.Node(childComplexity, args["id"].(gid.GID)), true
case "Query.trustCenterBySlug":
if e.complexity.Query.TrustCenterBySlug == nil {
break
}
args, err := ec.field_Query_trustCenterBySlug_args(ctx, rawArgs)
if err != nil {
return 0, false
}
return e.complexity.Query.TrustCenterBySlug(childComplexity, args["slug"].(string)), true
case "Query.viewer":
if e.complexity.Query.Viewer == nil {
break
@@ -1088,7 +1070,6 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler {
opCtx := graphql.GetOperationContext(ctx)
ec := executionContext{opCtx, e, 0, 0, make(chan graphql.DeferredResult)}
inputUnmarshalMap := graphql.BuildUnmarshalerMap(
ec.unmarshalInputAcceptNonDisclosureAgreementInput,
ec.unmarshalInputExportDocumentPDFInput,
ec.unmarshalInputExportReportPDFInput,
ec.unmarshalInputExportTrustCenterFileInput,
@@ -1749,7 +1730,6 @@ type SignInWithTokenPayload {
}
input RequestAllAccessesInput {
trustCenterId: ID!
email: EmailAddr!
fullName: String!
}
@@ -1766,26 +1746,19 @@ input ExportReportPDFInput {
reportId: ID!
}
input AcceptNonDisclosureAgreementInput {
trustCenterId: ID!
}
input RequestDocumentAccessInput {
trustCenterId: ID!
documentId: ID!
email: EmailAddr!
fullName: String!
}
input RequestReportAccessInput {
trustCenterId: ID!
reportId: ID!
email: EmailAddr!
fullName: String!
}
input RequestTrustCenterFileAccessInput {
trustCenterId: ID!
trustCenterFileId: ID!
email: EmailAddr!
fullName: String!
@@ -1814,7 +1787,6 @@ type AcceptNonDisclosureAgreementPayload {
type Query {
viewer: Identity
node(id: ID!): Node!
trustCenterBySlug(slug: String!): TrustCenter @mustBeAuthenticated(role: NONE)
currentTrustCenter: TrustCenter @mustBeAuthenticated(role: NONE)
}
@@ -1830,9 +1802,8 @@ type Mutation {
exportReportPDF(input: ExportReportPDFInput!): ExportReportPDFPayload!
@mustBeAuthenticated(role: NONE)
acceptNonDisclosureAgreement(
input: AcceptNonDisclosureAgreementInput!
): AcceptNonDisclosureAgreementPayload! @mustBeAuthenticated(role: USER)
acceptNonDisclosureAgreement: AcceptNonDisclosureAgreementPayload!
@mustBeAuthenticated(role: USER)
requestDocumentAccess(
input: RequestDocumentAccessInput!
@@ -1869,17 +1840,6 @@ func (ec *executionContext) dir_mustBeAuthenticated_args(ctx context.Context, ra
return args, nil
}
func (ec *executionContext) field_Mutation_acceptNonDisclosureAgreement_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) {
var err error
args := map[string]any{}
arg0, err := graphql.ProcessArgField(ctx, rawArgs, "input", ec.unmarshalNAcceptNonDisclosureAgreementInput2goᚗproboᚗincᚋproboᚋpkgᚋserverᚋapiᚋtrustᚋv1ᚋtypesᚐAcceptNonDisclosureAgreementInput)
if err != nil {
return nil, err
}
args["input"] = arg0
return args, nil
}
func (ec *executionContext) field_Mutation_exportDocumentPDF_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) {
var err error
args := map[string]any{}
@@ -1990,17 +1950,6 @@ func (ec *executionContext) field_Query_node_args(ctx context.Context, rawArgs m
return args, nil
}
func (ec *executionContext) field_Query_trustCenterBySlug_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) {
var err error
args := map[string]any{}
arg0, err := graphql.ProcessArgField(ctx, rawArgs, "slug", ec.unmarshalNString2string)
if err != nil {
return nil, err
}
args["slug"] = arg0
return args, nil
}
func (ec *executionContext) field_TrustCenter_audits_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) {
var err error
args := map[string]any{}
@@ -3366,8 +3315,7 @@ func (ec *executionContext) _Mutation_acceptNonDisclosureAgreement(ctx context.C
field,
ec.fieldContext_Mutation_acceptNonDisclosureAgreement,
func(ctx context.Context) (any, error) {
fc := graphql.GetFieldContext(ctx)
return ec.resolvers.Mutation().AcceptNonDisclosureAgreement(ctx, fc.Args["input"].(types.AcceptNonDisclosureAgreementInput))
return ec.resolvers.Mutation().AcceptNonDisclosureAgreement(ctx)
},
func(ctx context.Context, next graphql.Resolver) graphql.Resolver {
directive0 := next
@@ -3394,7 +3342,7 @@ func (ec *executionContext) _Mutation_acceptNonDisclosureAgreement(ctx context.C
)
}
func (ec *executionContext) fieldContext_Mutation_acceptNonDisclosureAgreement(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
func (ec *executionContext) fieldContext_Mutation_acceptNonDisclosureAgreement(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
fc = &graphql.FieldContext{
Object: "Mutation",
Field: field,
@@ -3408,17 +3356,6 @@ func (ec *executionContext) fieldContext_Mutation_acceptNonDisclosureAgreement(c
return nil, fmt.Errorf("no field named %q was found under type AcceptNonDisclosureAgreementPayload", field.Name)
},
}
defer func() {
if r := recover(); r != nil {
err = ec.Recover(ctx, r)
ec.Error(ctx, err)
}
}()
ctx = graphql.WithFieldContext(ctx, fc)
if fc.Args, err = ec.field_Mutation_acceptNonDisclosureAgreement_args(ctx, field.ArgumentMap(ec.Variables)); err != nil {
ec.Error(ctx, err)
return fc, err
}
return fc, nil
}
@@ -4077,93 +4014,6 @@ func (ec *executionContext) fieldContext_Query_node(ctx context.Context, field g
return fc, nil
}
func (ec *executionContext) _Query_trustCenterBySlug(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
return graphql.ResolveField(
ctx,
ec.OperationContext,
field,
ec.fieldContext_Query_trustCenterBySlug,
func(ctx context.Context) (any, error) {
fc := graphql.GetFieldContext(ctx)
return ec.resolvers.Query().TrustCenterBySlug(ctx, fc.Args["slug"].(string))
},
func(ctx context.Context, next graphql.Resolver) graphql.Resolver {
directive0 := next
directive1 := func(ctx context.Context) (any, error) {
role, err := ec.unmarshalORole2ᚖgoᚗproboᚗincᚋproboᚋpkgᚋserverᚋapiᚋtrustᚋv1ᚋtypesᚐRole(ctx, "NONE")
if err != nil {
var zeroVal *types.TrustCenter
return zeroVal, err
}
if ec.directives.MustBeAuthenticated == nil {
var zeroVal *types.TrustCenter
return zeroVal, errors.New("directive mustBeAuthenticated is not implemented")
}
return ec.directives.MustBeAuthenticated(ctx, nil, directive0, role)
}
next = directive1
return next
},
ec.marshalOTrustCenter2ᚖgoᚗproboᚗincᚋproboᚋpkgᚋserverᚋapiᚋtrustᚋv1ᚋtypesᚐTrustCenter,
true,
false,
)
}
func (ec *executionContext) fieldContext_Query_trustCenterBySlug(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
fc = &graphql.FieldContext{
Object: "Query",
Field: field,
IsMethod: true,
IsResolver: true,
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
switch field.Name {
case "id":
return ec.fieldContext_TrustCenter_id(ctx, field)
case "active":
return ec.fieldContext_TrustCenter_active(ctx, field)
case "slug":
return ec.fieldContext_TrustCenter_slug(ctx, field)
case "ndaFileName":
return ec.fieldContext_TrustCenter_ndaFileName(ctx, field)
case "ndaFileUrl":
return ec.fieldContext_TrustCenter_ndaFileUrl(ctx, field)
case "organization":
return ec.fieldContext_TrustCenter_organization(ctx, field)
case "isUserAuthenticated":
return ec.fieldContext_TrustCenter_isUserAuthenticated(ctx, field)
case "hasAcceptedNonDisclosureAgreement":
return ec.fieldContext_TrustCenter_hasAcceptedNonDisclosureAgreement(ctx, field)
case "documents":
return ec.fieldContext_TrustCenter_documents(ctx, field)
case "audits":
return ec.fieldContext_TrustCenter_audits(ctx, field)
case "vendors":
return ec.fieldContext_TrustCenter_vendors(ctx, field)
case "references":
return ec.fieldContext_TrustCenter_references(ctx, field)
case "trustCenterFiles":
return ec.fieldContext_TrustCenter_trustCenterFiles(ctx, field)
}
return nil, fmt.Errorf("no field named %q was found under type TrustCenter", field.Name)
},
}
defer func() {
if r := recover(); r != nil {
err = ec.Recover(ctx, r)
ec.Error(ctx, err)
}
}()
ctx = graphql.WithFieldContext(ctx, fc)
if fc.Args, err = ec.field_Query_trustCenterBySlug_args(ctx, field.ArgumentMap(ec.Variables)); err != nil {
ec.Error(ctx, err)
return fc, err
}
return fc, nil
}
func (ec *executionContext) _Query_currentTrustCenter(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
return graphql.ResolveField(
ctx,
@@ -7505,33 +7355,6 @@ func (ec *executionContext) fieldContext___Type_isOneOf(_ context.Context, field
// region **************************** input.gotpl *****************************
func (ec *executionContext) unmarshalInputAcceptNonDisclosureAgreementInput(ctx context.Context, obj any) (types.AcceptNonDisclosureAgreementInput, error) {
var it types.AcceptNonDisclosureAgreementInput
asMap := map[string]any{}
for k, v := range obj.(map[string]any) {
asMap[k] = v
}
fieldsInOrder := [...]string{"trustCenterId"}
for _, k := range fieldsInOrder {
v, ok := asMap[k]
if !ok {
continue
}
switch k {
case "trustCenterId":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("trustCenterId"))
data, err := ec.unmarshalNID2goᚗproboᚗincᚋproboᚋpkgᚋgidᚐGID(ctx, v)
if err != nil {
return it, err
}
it.TrustCenterID = data
}
}
return it, nil
}
func (ec *executionContext) unmarshalInputExportDocumentPDFInput(ctx context.Context, obj any) (types.ExportDocumentPDFInput, error) {
var it types.ExportDocumentPDFInput
asMap := map[string]any{}
@@ -7620,20 +7443,13 @@ func (ec *executionContext) unmarshalInputRequestAllAccessesInput(ctx context.Co
asMap[k] = v
}
fieldsInOrder := [...]string{"trustCenterId", "email", "fullName"}
fieldsInOrder := [...]string{"email", "fullName"}
for _, k := range fieldsInOrder {
v, ok := asMap[k]
if !ok {
continue
}
switch k {
case "trustCenterId":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("trustCenterId"))
data, err := ec.unmarshalNID2goᚗproboᚗincᚋproboᚋpkgᚋgidᚐGID(ctx, v)
if err != nil {
return it, err
}
it.TrustCenterID = data
case "email":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("email"))
data, err := ec.unmarshalNEmailAddr2goᚗproboᚗincᚋproboᚋpkgᚋmailᚐAddr(ctx, v)
@@ -7661,20 +7477,13 @@ func (ec *executionContext) unmarshalInputRequestDocumentAccessInput(ctx context
asMap[k] = v
}
fieldsInOrder := [...]string{"trustCenterId", "documentId", "email", "fullName"}
fieldsInOrder := [...]string{"documentId", "email", "fullName"}
for _, k := range fieldsInOrder {
v, ok := asMap[k]
if !ok {
continue
}
switch k {
case "trustCenterId":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("trustCenterId"))
data, err := ec.unmarshalNID2goᚗproboᚗincᚋproboᚋpkgᚋgidᚐGID(ctx, v)
if err != nil {
return it, err
}
it.TrustCenterID = data
case "documentId":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("documentId"))
data, err := ec.unmarshalNID2goᚗproboᚗincᚋproboᚋpkgᚋgidᚐGID(ctx, v)
@@ -7709,20 +7518,13 @@ func (ec *executionContext) unmarshalInputRequestReportAccessInput(ctx context.C
asMap[k] = v
}
fieldsInOrder := [...]string{"trustCenterId", "reportId", "email", "fullName"}
fieldsInOrder := [...]string{"reportId", "email", "fullName"}
for _, k := range fieldsInOrder {
v, ok := asMap[k]
if !ok {
continue
}
switch k {
case "trustCenterId":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("trustCenterId"))
data, err := ec.unmarshalNID2goᚗproboᚗincᚋproboᚋpkgᚋgidᚐGID(ctx, v)
if err != nil {
return it, err
}
it.TrustCenterID = data
case "reportId":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("reportId"))
data, err := ec.unmarshalNID2goᚗproboᚗincᚋproboᚋpkgᚋgidᚐGID(ctx, v)
@@ -7757,20 +7559,13 @@ func (ec *executionContext) unmarshalInputRequestTrustCenterFileAccessInput(ctx
asMap[k] = v
}
fieldsInOrder := [...]string{"trustCenterId", "trustCenterFileId", "email", "fullName"}
fieldsInOrder := [...]string{"trustCenterFileId", "email", "fullName"}
for _, k := range fieldsInOrder {
v, ok := asMap[k]
if !ok {
continue
}
switch k {
case "trustCenterId":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("trustCenterId"))
data, err := ec.unmarshalNID2goᚗproboᚗincᚋproboᚋpkgᚋgidᚐGID(ctx, v)
if err != nil {
return it, err
}
it.TrustCenterID = data
case "trustCenterFileId":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("trustCenterFileId"))
data, err := ec.unmarshalNID2goᚗproboᚗincᚋproboᚋpkgᚋgidᚐGID(ctx, v)
@@ -8951,25 +8746,6 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr
func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) })
}
out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) })
case "trustCenterBySlug":
field := field
innerFunc := func(ctx context.Context, _ *graphql.FieldSet) (res graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
}
}()
res = ec._Query_trustCenterBySlug(ctx, field)
return res
}
rrm := func(ctx context.Context) graphql.Marshaler {
return ec.OperationContext.RootResolverMiddleware(ctx,
func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) })
}
out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) })
case "currentTrustCenter":
field := field
@@ -10511,11 +10287,6 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o
// region ***************************** type.gotpl *****************************
func (ec *executionContext) unmarshalNAcceptNonDisclosureAgreementInput2goᚗproboᚗincᚋproboᚋpkgᚋserverᚋapiᚋtrustᚋv1ᚋtypesᚐAcceptNonDisclosureAgreementInput(ctx context.Context, v any) (types.AcceptNonDisclosureAgreementInput, error) {
res, err := ec.unmarshalInputAcceptNonDisclosureAgreementInput(ctx, v)
return res, graphql.ErrorOnPath(ctx, err)
}
func (ec *executionContext) marshalNAcceptNonDisclosureAgreementPayload2goᚗproboᚗincᚋproboᚋpkgᚋserverᚋapiᚋtrustᚋv1ᚋtypesᚐAcceptNonDisclosureAgreementPayload(ctx context.Context, sel ast.SelectionSet, v types.AcceptNonDisclosureAgreementPayload) graphql.Marshaler {
return ec._AcceptNonDisclosureAgreementPayload(ctx, sel, &v)
}

View File

@@ -20,10 +20,6 @@ type Node interface {
GetID() gid.GID
}
type AcceptNonDisclosureAgreementInput struct {
TrustCenterID gid.GID `json:"trustCenterId"`
}
type AcceptNonDisclosureAgreementPayload struct {
Success bool `json:"success"`
}
@@ -155,27 +151,23 @@ type RequestAccessesPayload struct {
}
type RequestAllAccessesInput struct {
TrustCenterID gid.GID `json:"trustCenterId"`
Email mail.Addr `json:"email"`
FullName string `json:"fullName"`
Email mail.Addr `json:"email"`
FullName string `json:"fullName"`
}
type RequestDocumentAccessInput struct {
TrustCenterID gid.GID `json:"trustCenterId"`
DocumentID gid.GID `json:"documentId"`
Email mail.Addr `json:"email"`
FullName string `json:"fullName"`
DocumentID gid.GID `json:"documentId"`
Email mail.Addr `json:"email"`
FullName string `json:"fullName"`
}
type RequestReportAccessInput struct {
TrustCenterID gid.GID `json:"trustCenterId"`
ReportID gid.GID `json:"reportId"`
Email mail.Addr `json:"email"`
FullName string `json:"fullName"`
ReportID gid.GID `json:"reportId"`
Email mail.Addr `json:"email"`
FullName string `json:"fullName"`
}
type RequestTrustCenterFileAccessInput struct {
TrustCenterID gid.GID `json:"trustCenterId"`
TrustCenterFileID gid.GID `json:"trustCenterFileId"`
Email mail.Addr `json:"email"`
FullName string `json:"fullName"`

View File

@@ -18,6 +18,7 @@ import (
"go.probo.inc/probo/pkg/iam"
"go.probo.inc/probo/pkg/page"
"go.probo.inc/probo/pkg/server/api/authn"
"go.probo.inc/probo/pkg/server/api/compliancepage"
"go.probo.inc/probo/pkg/server/api/trust/v1/schema"
"go.probo.inc/probo/pkg/server/api/trust/v1/types"
"go.probo.inc/probo/pkg/server/gqlutils"
@@ -69,6 +70,7 @@ func (r *auditResolver) Report(ctx context.Context, obj *types.Audit) (*types.Re
// IsUserAuthorized is the resolver for the isUserAuthorized field.
func (r *documentResolver) IsUserAuthorized(ctx context.Context, obj *types.Document) (bool, error) {
trustService := r.TrustService(ctx, obj.ID.TenantID())
trustCenter := compliancepage.CompliancePageFromContext(ctx)
document, err := trustService.Documents.Get(ctx, obj.ID)
if err != nil {
@@ -85,7 +87,6 @@ func (r *documentResolver) IsUserAuthorized(ctx context.Context, obj *types.Docu
return false, gqlutils.Unauthenticatedf(ctx, "unauthenticated")
}
trustCenter := TrustCenterFromContext(ctx)
documentAccess, err := trustService.TrustCenterAccesses.LoadDocumentAccess(
ctx,
trustCenter.ID,
@@ -105,13 +106,13 @@ func (r *documentResolver) IsUserAuthorized(ctx context.Context, obj *types.Docu
// HasUserRequestedAccess is the resolver for the hasUserRequestedAccess field.
func (r *documentResolver) HasUserRequestedAccess(ctx context.Context, obj *types.Document) (bool, error) {
trustService := r.TrustService(ctx, obj.ID.TenantID())
trustCenter := compliancepage.CompliancePageFromContext(ctx)
identity := authn.IdentityFromContext(ctx)
if identity == nil {
return false, nil // User is not authenticated, so no access requested
}
trustCenter := TrustCenterFromContext(ctx)
// Try to load document access - if it exists (regardless of active status), user has requested it
_, err := trustService.TrustCenterAccesses.LoadDocumentAccess(
ctx,
@@ -166,7 +167,8 @@ func (r *mutationResolver) SignInWithToken(ctx context.Context, input types.Sign
// RequestAllAccesses is the resolver for the requestAllAccesses field.
func (r *mutationResolver) RequestAllAccesses(ctx context.Context, input types.RequestAllAccessesInput) (*types.RequestAccessesPayload, error) {
trustService := r.TrustService(ctx, input.TrustCenterID.TenantID())
trustCenter := compliancepage.CompliancePageFromContext(ctx)
trustService := r.TrustService(ctx, trustCenter.ID.TenantID())
identity := authn.IdentityFromContext(ctx)
if identity == nil {
@@ -186,7 +188,7 @@ func (r *mutationResolver) RequestAllAccesses(ctx context.Context, input types.R
access, err := trustService.TrustCenterAccesses.Request(
ctx,
&trust.TrustCenterAccessRequest{
TrustCenterID: input.TrustCenterID,
TrustCenterID: trustCenter.ID,
Email: identity.EmailAddress,
FullName: identity.FullName,
DocumentIDs: nil,
@@ -212,8 +214,7 @@ func (r *mutationResolver) RequestAllAccesses(ctx context.Context, input types.R
// ExportDocumentPDF is the resolver for the exportDocumentPDF field.
func (r *mutationResolver) ExportDocumentPDF(ctx context.Context, input types.ExportDocumentPDFInput) (*types.ExportDocumentPDFPayload, error) {
trustService := r.TrustService(ctx, input.DocumentID.TenantID())
trustCenterInfo := TrustCenterFromContext(ctx)
trustCenter := compliancepage.CompliancePageFromContext(ctx)
document, err := trustService.Documents.Get(ctx, input.DocumentID)
if err != nil {
@@ -241,10 +242,6 @@ func (r *mutationResolver) ExportDocumentPDF(ctx context.Context, input types.Ex
ndaExists := true
hasAcceptedNDA := false
trustCenter, _, err := trustService.TrustCenters.Get(
ctx,
trustCenterInfo.ID,
)
if err != nil {
r.logger.ErrorCtx(ctx, "cannot get trust center", log.Error(err))
return nil, gqlutils.Internal(ctx)
@@ -256,7 +253,7 @@ func (r *mutationResolver) ExportDocumentPDF(ctx context.Context, input types.Ex
if ndaExists {
hasAcceptedNDA, err = trustService.TrustCenterAccesses.HasAcceptedNonDisclosureAgreement(
ctx,
trustCenterInfo.ID,
trustCenter.ID,
identity.EmailAddress,
)
if err != nil {
@@ -267,7 +264,7 @@ func (r *mutationResolver) ExportDocumentPDF(ctx context.Context, input types.Ex
documentAccess, err := trustService.TrustCenterAccesses.LoadDocumentAccess(
ctx,
trustCenterInfo.ID,
trustCenter.ID,
identity.EmailAddress,
input.DocumentID,
)
@@ -301,7 +298,7 @@ func (r *mutationResolver) ExportDocumentPDF(ctx context.Context, input types.Ex
func (r *mutationResolver) ExportReportPDF(ctx context.Context, input types.ExportReportPDFInput) (*types.ExportReportPDFPayload, error) {
trustService := r.TrustService(ctx, input.ReportID.TenantID())
trustCenterInfo := TrustCenterFromContext(ctx)
trustCenter := compliancepage.CompliancePageFromContext(ctx)
audit, err := trustService.Audits.GetByReportID(ctx, input.ReportID)
if err != nil {
@@ -329,10 +326,6 @@ func (r *mutationResolver) ExportReportPDF(ctx context.Context, input types.Expo
ndaExists := true
hasAcceptedNDA := false
trustCenter, _, err := trustService.TrustCenters.Get(
ctx,
trustCenterInfo.ID,
)
if err != nil {
r.logger.ErrorCtx(ctx, "cannot get trust center", log.Error(err))
return nil, gqlutils.Internal(ctx)
@@ -344,7 +337,7 @@ func (r *mutationResolver) ExportReportPDF(ctx context.Context, input types.Expo
if ndaExists {
hasAcceptedNDA, err = trustService.TrustCenterAccesses.HasAcceptedNonDisclosureAgreement(
ctx,
trustCenterInfo.ID,
trustCenter.ID,
identity.EmailAddress,
)
if err != nil {
@@ -355,7 +348,7 @@ func (r *mutationResolver) ExportReportPDF(ctx context.Context, input types.Expo
reportAccess, err := trustService.TrustCenterAccesses.LoadReportAccess(
ctx,
trustCenterInfo.ID,
trustCenter.ID,
identity.EmailAddress,
input.ReportID,
)
@@ -386,15 +379,25 @@ func (r *mutationResolver) ExportReportPDF(ctx context.Context, input types.Expo
}
// AcceptNonDisclosureAgreement is the resolver for the acceptNonDisclosureAgreement field.
func (r *mutationResolver) AcceptNonDisclosureAgreement(ctx context.Context, input types.AcceptNonDisclosureAgreementInput) (*types.AcceptNonDisclosureAgreementPayload, error) {
trustService := r.TrustService(ctx, input.TrustCenterID.TenantID())
func (r *mutationResolver) AcceptNonDisclosureAgreement(ctx context.Context) (*types.AcceptNonDisclosureAgreementPayload, error) {
trustCenter := compliancepage.CompliancePageFromContext(ctx)
trustService := r.TrustService(ctx, trustCenter.ID.TenantID())
identity := authn.IdentityFromContext(ctx)
if identity == nil {
return nil, gqlutils.Unauthenticatedf(ctx, "unauthenticated")
}
if err := trustService.TrustCenterAccesses.AcceptNonDisclosureAgreement(ctx, input.TrustCenterID, identity.EmailAddress); err != nil {
httpReq := gqlutils.HTTPRequestFromContext(ctx)
if err := trustService.TrustCenterAccesses.AcceptNonDisclosureAgreement(
ctx,
&trust.AcceptNDARequest{
TrustCenterID: trustCenter.ID,
Email: identity.EmailAddress,
IPAddr: httpReq.RemoteAddr,
},
); err != nil {
r.logger.ErrorCtx(ctx, "cannot accept NDA", log.Error(err))
return nil, gqlutils.Internal(ctx)
}
@@ -404,7 +407,8 @@ func (r *mutationResolver) AcceptNonDisclosureAgreement(ctx context.Context, inp
// RequestDocumentAccess is the resolver for the requestDocumentAccess field.
func (r *mutationResolver) RequestDocumentAccess(ctx context.Context, input types.RequestDocumentAccessInput) (*types.RequestAccessesPayload, error) {
trustService := r.TrustService(ctx, input.TrustCenterID.TenantID())
trustCenter := compliancepage.CompliancePageFromContext(ctx)
trustService := r.TrustService(ctx, trustCenter.ID.TenantID())
document, err := trustService.Documents.Get(ctx, input.DocumentID)
if err != nil {
@@ -436,7 +440,7 @@ func (r *mutationResolver) RequestDocumentAccess(ctx context.Context, input type
access, err := trustService.TrustCenterAccesses.Request(
ctx,
&trust.TrustCenterAccessRequest{
TrustCenterID: input.TrustCenterID,
TrustCenterID: trustCenter.ID,
Email: identity.EmailAddress,
FullName: identity.FullName,
DocumentIDs: []gid.GID{input.DocumentID},
@@ -461,7 +465,8 @@ func (r *mutationResolver) RequestDocumentAccess(ctx context.Context, input type
// RequestReportAccess is the resolver for the requestReportAccess field.
func (r *mutationResolver) RequestReportAccess(ctx context.Context, input types.RequestReportAccessInput) (*types.RequestAccessesPayload, error) {
trustService := r.TrustService(ctx, input.TrustCenterID.TenantID())
trustCenter := compliancepage.CompliancePageFromContext(ctx)
trustService := r.TrustService(ctx, trustCenter.ID.TenantID())
audit, err := trustService.Audits.GetByReportID(ctx, input.ReportID)
if err != nil {
@@ -494,7 +499,7 @@ func (r *mutationResolver) RequestReportAccess(ctx context.Context, input types.
access, err := trustService.TrustCenterAccesses.Request(
ctx,
&trust.TrustCenterAccessRequest{
TrustCenterID: input.TrustCenterID,
TrustCenterID: trustCenter.ID,
Email: identity.EmailAddress,
FullName: identity.FullName,
DocumentIDs: []gid.GID{},
@@ -519,7 +524,8 @@ func (r *mutationResolver) RequestReportAccess(ctx context.Context, input types.
// RequestTrustCenterFileAccess is the resolver for the requestTrustCenterFileAccess field.
func (r *mutationResolver) RequestTrustCenterFileAccess(ctx context.Context, input types.RequestTrustCenterFileAccessInput) (*types.RequestAccessesPayload, error) {
trustService := r.TrustService(ctx, input.TrustCenterID.TenantID())
trustCenter := compliancepage.CompliancePageFromContext(ctx)
trustService := r.TrustService(ctx, trustCenter.ID.TenantID())
trustCenterFile, err := trustService.TrustCenterFiles.Get(ctx, input.TrustCenterFileID)
if err != nil {
@@ -552,7 +558,7 @@ func (r *mutationResolver) RequestTrustCenterFileAccess(ctx context.Context, inp
access, err := trustService.TrustCenterAccesses.Request(
ctx,
&trust.TrustCenterAccessRequest{
TrustCenterID: input.TrustCenterID,
TrustCenterID: trustCenter.ID,
Email: identity.EmailAddress,
FullName: identity.FullName,
DocumentIDs: []gid.GID{},
@@ -578,9 +584,8 @@ func (r *mutationResolver) RequestTrustCenterFileAccess(ctx context.Context, inp
// ExportTrustCenterFile is the resolver for the exportTrustCenterFile field.
func (r *mutationResolver) ExportTrustCenterFile(ctx context.Context, input types.ExportTrustCenterFileInput) (*types.ExportTrustCenterFilePayload, error) {
trustService := r.TrustService(ctx, input.TrustCenterFileID.TenantID())
trustCenterInfo := TrustCenterFromContext(ctx)
trustCenter := compliancepage.CompliancePageFromContext(ctx)
trustService := r.TrustService(ctx, trustCenter.ID.TenantID())
trustCenterFile, err := trustService.TrustCenterFiles.Get(ctx, input.TrustCenterFileID)
if err != nil {
@@ -608,21 +613,13 @@ func (r *mutationResolver) ExportTrustCenterFile(ctx context.Context, input type
ndaExists := true
hasAcceptedNDA := false
trustCenter, _, err := trustService.TrustCenters.Get(
ctx,
trustCenterInfo.ID,
)
if err != nil {
r.logger.ErrorCtx(ctx, "cannot get trust center", log.Error(err))
return nil, gqlutils.Internal(ctx)
}
if trustCenter.NonDisclosureAgreementFileID == nil {
ndaExists = false
}
if ndaExists {
hasAcceptedNDA, err = trustService.TrustCenterAccesses.HasAcceptedNonDisclosureAgreement(ctx,
trustCenterInfo.ID,
trustCenter.ID,
identity.EmailAddress,
)
if err != nil {
@@ -632,7 +629,7 @@ func (r *mutationResolver) ExportTrustCenterFile(ctx context.Context, input type
}
fileAccess, err := trustService.TrustCenterAccesses.LoadTrustCenterFileAccess(ctx,
trustCenterInfo.ID,
trustCenter.ID,
identity.EmailAddress,
input.TrustCenterFileID,
)
@@ -761,47 +758,18 @@ func (r *queryResolver) Node(ctx context.Context, id gid.GID) (types.Node, error
}
}
// TrustCenterBySlug is the resolver for the trustCenterBySlug field.
func (r *queryResolver) TrustCenterBySlug(ctx context.Context, slug string) (*types.TrustCenter, error) {
rootTrustService := r.RootTrustService(ctx)
// CurrentTrustCenter is the resolver for the currentTrustCenter field.
func (r *queryResolver) CurrentTrustCenter(ctx context.Context) (*types.TrustCenter, error) {
trustCenter := compliancepage.CompliancePageFromContext(ctx)
trustCenter, err := rootTrustService.TrustCenters.GetBySlug(ctx, slug)
if err != nil {
return nil, nil
}
if !trustCenter.Active {
return nil, nil
}
trustService := r.TrustService(ctx, trustCenter.TenantID)
trustCenter, file, err := trustService.TrustCenters.Get(ctx, trustCenter.ID)
if err != nil {
panic(fmt.Errorf("cannot get trust center: %w", err))
}
trustService := r.TrustService(ctx, trustCenter.ID.TenantID())
org, err := trustService.Organizations.Get(ctx, trustCenter.OrganizationID)
if err != nil {
panic(fmt.Errorf("cannot get organization: %w", err))
}
response := types.NewTrustCenter(trustCenter, file)
response.Organization = types.NewOrganization(org)
return response, nil
}
// CurrentTrustCenter is the resolver for the currentTrustCenter field.
func (r *queryResolver) CurrentTrustCenter(ctx context.Context) (*types.TrustCenter, error) {
trustCenterInfo := TrustCenterFromContext(ctx)
trustService := r.TrustService(ctx, trustCenterInfo.ID.TenantID())
org, err := trustService.Organizations.Get(ctx, trustCenterInfo.OrganizationID)
if err != nil {
panic(fmt.Errorf("cannot get organization: %w", err))
}
trustCenter, file, err := trustService.TrustCenters.Get(ctx, trustCenterInfo.ID)
trustCenter, file, err := trustService.TrustCenters.Get(ctx, trustCenter.ID)
if err != nil {
panic(fmt.Errorf("cannot get trust center: %w", err))
}
@@ -816,7 +784,7 @@ func (r *queryResolver) CurrentTrustCenter(ctx context.Context) (*types.TrustCen
func (r *reportResolver) IsUserAuthorized(ctx context.Context, obj *types.Report) (bool, error) {
trustService := r.TrustService(ctx, obj.ID.TenantID())
trustCenterInfo := TrustCenterFromContext(ctx)
trustCenter := compliancepage.CompliancePageFromContext(ctx)
audit, err := trustService.Audits.GetByReportID(ctx, obj.ID)
if err != nil {
@@ -834,7 +802,7 @@ func (r *reportResolver) IsUserAuthorized(ctx context.Context, obj *types.Report
}
reportAccess, err := trustService.TrustCenterAccesses.LoadReportAccess(ctx,
trustCenterInfo.ID,
trustCenter.ID,
identity.EmailAddress,
obj.ID,
)
@@ -852,7 +820,7 @@ func (r *reportResolver) IsUserAuthorized(ctx context.Context, obj *types.Report
func (r *reportResolver) HasUserRequestedAccess(ctx context.Context, obj *types.Report) (bool, error) {
trustService := r.TrustService(ctx, obj.ID.TenantID())
trustCenterInfo := TrustCenterFromContext(ctx)
trustCenter := compliancepage.CompliancePageFromContext(ctx)
identity := authn.IdentityFromContext(ctx)
if identity == nil {
@@ -860,7 +828,7 @@ func (r *reportResolver) HasUserRequestedAccess(ctx context.Context, obj *types.
}
_, err := trustService.TrustCenterAccesses.LoadReportAccess(ctx,
trustCenterInfo.ID,
trustCenter.ID,
identity.EmailAddress,
obj.ID,
)
@@ -1018,7 +986,7 @@ func (r *trustCenterResolver) TrustCenterFiles(ctx context.Context, obj *types.T
func (r *trustCenterFileResolver) IsUserAuthorized(ctx context.Context, obj *types.TrustCenterFile) (bool, error) {
trustService := r.TrustService(ctx, obj.ID.TenantID())
trustCenterInfo := TrustCenterFromContext(ctx)
trustCenter := compliancepage.CompliancePageFromContext(ctx)
trustCenterFile, err := trustService.TrustCenterFiles.Get(ctx, obj.ID)
if err != nil {
@@ -1036,7 +1004,7 @@ func (r *trustCenterFileResolver) IsUserAuthorized(ctx context.Context, obj *typ
}
fileAccess, err := trustService.TrustCenterAccesses.LoadTrustCenterFileAccess(ctx,
trustCenterInfo.ID,
trustCenter.ID,
identity.EmailAddress,
obj.ID,
)
@@ -1054,7 +1022,7 @@ func (r *trustCenterFileResolver) IsUserAuthorized(ctx context.Context, obj *typ
func (r *trustCenterFileResolver) HasUserRequestedAccess(ctx context.Context, obj *types.TrustCenterFile) (bool, error) {
trustService := r.TrustService(ctx, obj.ID.TenantID())
trustCenterInfo := TrustCenterFromContext(ctx)
trustCenter := compliancepage.CompliancePageFromContext(ctx)
identity := authn.IdentityFromContext(ctx)
if identity == nil {
@@ -1062,7 +1030,7 @@ func (r *trustCenterFileResolver) HasUserRequestedAccess(ctx context.Context, ob
}
_, err := trustService.TrustCenterAccesses.LoadTrustCenterFileAccess(ctx,
trustCenterInfo.ID,
trustCenter.ID,
identity.EmailAddress,
obj.ID,
)

View File

@@ -59,7 +59,9 @@ func NewHandler[S graphql.ExecutableSchema](executableSchema S, logger *log.Logg
}
func (gqlh *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
gqlh.gqlhandler.ServeHTTP(w, r)
ctx := WithHTTPContext(r.Context(), w, r)
gqlh.gqlhandler.ServeHTTP(w, r.WithContext(ctx))
}
func (gqlh *Handler) Use(extension graphql.HandlerExtension) {

View File

@@ -28,16 +28,6 @@ var (
httpRequestKey = &ctxKey{name: "http_request"}
)
func HTTPContextMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
ctx := WithHTTPContext(r.Context(), w, r)
next.ServeHTTP(w, r.WithContext(ctx))
},
)
}
func WithHTTPContext(ctx context.Context, w http.ResponseWriter, r *http.Request) context.Context {
ctx = context.WithValue(ctx, httpResponseWriterKey, w)

View File

@@ -25,12 +25,11 @@ import (
"go.probo.inc/probo/pkg/agents"
"go.probo.inc/probo/pkg/baseurl"
"go.probo.inc/probo/pkg/connector"
"go.probo.inc/probo/pkg/gid"
"go.probo.inc/probo/pkg/iam"
"go.probo.inc/probo/pkg/probo"
"go.probo.inc/probo/pkg/securecookie"
"go.probo.inc/probo/pkg/server/api"
trust_v1 "go.probo.inc/probo/pkg/server/api/trust/v1"
"go.probo.inc/probo/pkg/server/api/compliancepage"
trust_web "go.probo.inc/probo/pkg/server/trust"
console_web "go.probo.inc/probo/pkg/server/web"
"go.probo.inc/probo/pkg/slack"
@@ -60,6 +59,7 @@ type Server struct {
router *chi.Mux
extraHeaderFields map[string]string
proboService *probo.Service
trustService *trust.Service
logger *log.Logger
}
@@ -102,6 +102,7 @@ func NewServer(cfg Config) (*Server, error) {
router: router,
extraHeaderFields: cfg.ExtraHeaderFields,
proboService: cfg.Probo,
trustService: cfg.Trust,
logger: cfg.Logger,
}
@@ -114,7 +115,7 @@ func (s *Server) setupRoutes() {
s.router.Mount("/api", http.StripPrefix("/api", s.apiServer))
s.router.Route("/trust/{slugOrId}", func(r chi.Router) {
r.Use(s.loadTrustCenterBySlugOrID)
r.Use(compliancepage.NewIDMiddleware(s.trustService))
r.Use(s.stripTrustPrefix)
r.Mount("/", s.trustCenterRouter())
})
@@ -137,117 +138,6 @@ func (s *Server) handleCustomDomain404(w http.ResponseWriter, r *http.Request) {
httpserver.RenderError(w, http.StatusNotFound, errors.New("not found"))
}
func (s *Server) loadTrustCenterBySlugOrID(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
slugOrId := chi.URLParam(r, "slugOrId")
// Try to parse as GID first
var trustCenter *probo.TrustCenterInfo
var err error
if id, parseErr := gid.ParseGID(slugOrId); parseErr == nil {
// It's a valid ID, load by ID
s.logger.InfoCtx(ctx, "loading trust center by ID",
log.String("id", id.String()),
log.String("path", r.URL.Path),
)
trustCenter, err = s.proboService.LoadTrustCenterByID(ctx, id)
if err != nil {
s.logger.WarnCtx(ctx, "trust center not found",
log.String("id", id.String()),
log.Error(err),
)
http.Error(w, "Trust center not found", http.StatusNotFound)
return
}
s.logger.InfoCtx(ctx, "trust center loaded by ID",
log.String("id", id.String()),
log.String("trust_center_id", trustCenter.ID.String()),
log.String("organization_id", trustCenter.OrganizationID.String()),
)
} else {
// Not a valid ID, treat as slug
s.logger.InfoCtx(ctx, "loading trust center by slug",
log.String("slug", slugOrId),
log.String("path", r.URL.Path),
)
trustCenter, err = s.proboService.LoadTrustCenterBySlug(ctx, slugOrId)
if err != nil {
s.logger.WarnCtx(ctx, "trust center not found",
log.String("slug", slugOrId),
log.Error(err),
)
http.Error(w, "Trust center not found", http.StatusNotFound)
return
}
s.logger.InfoCtx(ctx, "trust center loaded by slug",
log.String("slug", slugOrId),
log.String("trust_center_id", trustCenter.ID.String()),
log.String("organization_id", trustCenter.OrganizationID.String()),
)
}
ctx = trust_v1.ContextWithTrustCenter(ctx, *trustCenter)
next.ServeHTTP(w, r.WithContext(ctx))
})
}
func (s *Server) loadTrustCenterByDomain(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
// For HTTP requests, use r.Host; for HTTPS requests, use r.TLS.ServerName
var domain string
if r.TLS != nil && r.TLS.ServerName != "" {
domain = r.TLS.ServerName
} else {
domain = r.Host
}
if domain == "" {
next.ServeHTTP(w, r)
return
}
s.logger.InfoCtx(ctx, "loading organization by custom domain",
log.String("domain", domain),
log.String("path", r.URL.Path),
)
organizationID, err := s.proboService.LoadOrganizationByDomain(ctx, domain)
if err != nil {
s.logger.WarnCtx(ctx, "organization not found for domain",
log.String("domain", domain),
log.Error(err),
)
next.ServeHTTP(w, r)
return
}
s.logger.InfoCtx(ctx, "organization loaded",
log.String("domain", domain),
log.String("organization_id", organizationID.String()),
)
trustCenter, err := s.proboService.LoadTrustCenterByOrganizationID(ctx, organizationID)
if err != nil {
s.logger.WarnCtx(ctx, "trust center not found",
log.Error(err),
)
http.Error(w, "Trust center not found", http.StatusNotFound)
return
}
ctx = trust_v1.ContextWithTrustCenter(ctx, *trustCenter)
next.ServeHTTP(w, r.WithContext(ctx))
})
}
func (s *Server) stripTrustPrefix(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
slugOrId := chi.URLParam(r, "slugOrId")
@@ -279,6 +169,7 @@ func (s *Server) trustCenterRouter() chi.Router {
func (s *Server) TrustCenterHandler() http.Handler {
r := chi.NewRouter()
r.Use(compliancepage.NewSNIMiddleware(s.trustService))
r.Use(func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Strict-Transport-Security", "max-age=31536000; preload")
@@ -287,7 +178,6 @@ func (s *Server) TrustCenterHandler() http.Handler {
})
})
r.Use(s.loadTrustCenterByDomain)
r.NotFound(s.handleCustomDomain404)
r.Mount("/", s.trustCenterRouter())

View File

@@ -15,6 +15,8 @@
package trust
import (
"context"
"fmt"
"time"
"github.com/aws/aws-sdk-go-v2/service/s3"
@@ -146,6 +148,84 @@ func (s *Service) WithTenant(tenantID gid.TenantID) *TenantService {
return tenantService
}
func (s *Service) GetTokenSecret() string {
return s.tokenSecret
func (s *Service) Get(
ctx context.Context,
id gid.GID,
) (*coredata.TrustCenter, error) {
trustCenter := &coredata.TrustCenter{}
err := s.pg.WithConn(
ctx,
func(conn pg.Conn) error {
err := trustCenter.LoadByID(ctx, conn, coredata.NewNoScope(), id)
if err != nil {
return fmt.Errorf("cannot load trust center: %w", err)
}
return nil
},
)
if err != nil {
return nil, err
}
return trustCenter, nil
}
func (s *Service) GetBySlug(
ctx context.Context,
slug string,
) (*coredata.TrustCenter, error) {
trustCenter := &coredata.TrustCenter{}
err := s.pg.WithConn(
ctx,
func(conn pg.Conn) error {
err := trustCenter.LoadBySlug(ctx, conn, slug)
if err != nil {
return fmt.Errorf("cannot load trust center: %w", err)
}
return nil
},
)
if err != nil {
return nil, err
}
return trustCenter, nil
}
func (s *Service) GetByDomainName(ctx context.Context, domain string) (*coredata.TrustCenter, error) {
trustCenter := &coredata.TrustCenter{}
err := s.pg.WithConn(
ctx,
func(conn pg.Conn) error {
var customDomain coredata.CustomDomain
if err := customDomain.LoadByDomain(ctx, conn, coredata.NewNoScope(), s.encryptionKey, domain); err != nil {
return fmt.Errorf("cannot load custom domain: %w", err)
}
var org coredata.Organization
if err := org.LoadByCustomDomainID(ctx, conn, coredata.NewNoScope(), customDomain.ID); err != nil {
return fmt.Errorf("cannot load organization: %w", err)
}
trustCenter = &coredata.TrustCenter{}
if err := trustCenter.LoadByOrganizationID(ctx, conn, coredata.NewNoScope(), org.ID); err != nil {
return fmt.Errorf("cannot load trust center: %w", err)
}
return nil
},
)
if err != nil {
return nil, err
}
return trustCenter, err
}

View File

@@ -246,22 +246,28 @@ func (s TrustCenterAccessService) HasAcceptedNonDisclosureAgreement(ctx context.
return access.HasAcceptedNonDisclosureAgreement, nil
}
func (s TrustCenterAccessService) AcceptNonDisclosureAgreement(ctx context.Context, trustCenterID gid.GID, email mail.Addr) error {
type AcceptNDARequest struct {
TrustCenterID gid.GID
Email mail.Addr
IPAddr string
}
func (s TrustCenterAccessService) AcceptNonDisclosureAgreement(ctx context.Context, req *AcceptNDARequest) error {
return s.svc.pg.WithTx(ctx, func(tx pg.Conn) error {
access := &coredata.TrustCenterAccess{}
if err := access.LoadByTrustCenterIDAndEmail(ctx, tx, s.svc.scope, trustCenterID, email); err != nil {
if err := access.LoadByTrustCenterIDAndEmail(ctx, tx, s.svc.scope, req.TrustCenterID, req.Email); err != nil {
return fmt.Errorf("cannot load trust center access: %w", err)
}
trustCenter := &coredata.TrustCenter{}
if err := trustCenter.LoadByID(ctx, tx, s.svc.scope, trustCenterID); err != nil {
if err := trustCenter.LoadByID(ctx, tx, s.svc.scope, req.TrustCenterID); err != nil {
return fmt.Errorf("cannot load trust center: %w", err)
}
acceptationLogs, err := json.Marshal(map[string]string{
"email": email.String(),
"email": req.Email.String(),
"timestamp": time.Now().Format(time.RFC3339),
"ip": ctx.Value(coredata.ContextKeyIPAddress).(string),
"ip": req.IPAddr,
})
if err != nil {
return fmt.Errorf("cannot marshal non disclosure agreement acceptation logs: %w", err)

View File

@@ -22,40 +22,15 @@ import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/s3"
"go.gearno.de/kit/pg"
"go.probo.inc/probo/pkg/coredata"
"go.probo.inc/probo/pkg/gid"
"go.gearno.de/kit/pg"
)
type TrustCenterService struct {
svc *TenantService
}
func (s TrustCenterService) GetBySlug(
ctx context.Context,
slug string,
) (*coredata.TrustCenter, error) {
trustCenter := &coredata.TrustCenter{}
err := s.svc.pg.WithConn(
ctx,
func(conn pg.Conn) error {
err := trustCenter.LoadBySlug(ctx, conn, slug)
if err != nil {
return fmt.Errorf("cannot load trust center: %w", err)
}
return nil
},
)
if err != nil {
return nil, err
}
return trustCenter, nil
}
func (s TrustCenterService) Get(
ctx context.Context,
trustCenterID gid.GID,