From 8dc5fffa580216aa88d7fec2857ae69e063e1227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20R=C3=A9?= Date: Wed, 4 Mar 2026 10:45:43 +0400 Subject: [PATCH] Fix misc bugs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Émile Ré --- apps/trust/src/components/AuditRow.tsx | 2 +- apps/trust/src/components/DocumentRow.tsx | 2 +- .../src/components/RootErrorBoundary.tsx | 20 +++++++----- .../src/components/TrustCenterFileRow.tsx | 2 +- .../src/hooks/useRequestAccessCallback.ts | 32 +++++-------------- apps/trust/src/pages/NDAPage.tsx | 12 +++++-- apps/trust/src/pages/auth/ConnectPage.tsx | 18 +++++++---- .../src/pages/auth/VerifyMagicLinkPage.tsx | 14 ++++---- pkg/server/api/trust/v1/nda_directive.go | 4 +++ pkg/server/api/trust/v1/v1_resolver.go | 22 ++++++++++--- pkg/trust/service.go | 2 +- 11 files changed, 75 insertions(+), 55 deletions(-) diff --git a/apps/trust/src/components/AuditRow.tsx b/apps/trust/src/components/AuditRow.tsx index 80dcc8100..f9b25e87b 100644 --- a/apps/trust/src/components/AuditRow.tsx +++ b/apps/trust/src/components/AuditRow.tsx @@ -78,7 +78,7 @@ export function AuditRow(props: { audit: AuditRowFragment$key }) { const navigate = useNavigate(); const audit = useFragment(auditRowFragment, props.audit); - const hasRequested = !!audit.report?.access; + const hasRequested = audit.report?.access?.status === "REQUESTED"; const [requestAccess, isRequestingAccess] = useMutation(requestAccessMutation); diff --git a/apps/trust/src/components/DocumentRow.tsx b/apps/trust/src/components/DocumentRow.tsx index 72f3c2729..39c7aaa0a 100644 --- a/apps/trust/src/components/DocumentRow.tsx +++ b/apps/trust/src/components/DocumentRow.tsx @@ -63,7 +63,7 @@ export function DocumentRow(props: { document: DocumentRowFragment$key }) { const [searchParams] = useSearchParams(); const document = useFragment(documentRowFragment, props.document); - const hasRequested = !!document.access; + const hasRequested = document.access?.status === "REQUESTED"; const [requestAccess, isRequestingAccess] = useMutation(requestAccessMutation); diff --git a/apps/trust/src/components/RootErrorBoundary.tsx b/apps/trust/src/components/RootErrorBoundary.tsx index d1b2013a0..182da8f30 100644 --- a/apps/trust/src/components/RootErrorBoundary.tsx +++ b/apps/trust/src/components/RootErrorBoundary.tsx @@ -19,20 +19,24 @@ export function RootErrorBoundary() { if (error instanceof UnAuthenticatedError) { return ( - ); } if (error instanceof NDASignatureRequiredError) { return ( - ); } diff --git a/apps/trust/src/components/TrustCenterFileRow.tsx b/apps/trust/src/components/TrustCenterFileRow.tsx index ccde91de2..90ec95b5f 100644 --- a/apps/trust/src/components/TrustCenterFileRow.tsx +++ b/apps/trust/src/components/TrustCenterFileRow.tsx @@ -67,7 +67,7 @@ export function TrustCenterFileRow(props: { const navigate = useNavigate(); const file = useFragment(trustCenterFileRowFragment, props.file); - const hasRequested = !!file.access; + const hasRequested = file.access?.status === "REQUESTED"; const [requestAccess, isRequestingAccess] = useMutation( diff --git a/apps/trust/src/hooks/useRequestAccessCallback.ts b/apps/trust/src/hooks/useRequestAccessCallback.ts index 92d53ff1e..337d5789a 100644 --- a/apps/trust/src/hooks/useRequestAccessCallback.ts +++ b/apps/trust/src/hooks/useRequestAccessCallback.ts @@ -103,6 +103,7 @@ export function useRequestAccessCallback() { useEffect(() => { if (documentId) { + searchParams.delete("request-document-id"); void requestDocumentAccess({ variables: { input: { documentId }, @@ -110,22 +111,18 @@ export function useRequestAccessCallback() { onCompleted: (_, errors) => { if (errors?.length) { toast(errorToastArgs(__, errors)); - searchParams.delete("request-document-id"); - setSearchParams(searchParams); return; } toast(successToastArgs(__)); - searchParams.delete("request-document-id"); - setSearchParams(searchParams); }, onError: (error) => { toast(errorToastArgs(__, error)); - searchParams.delete("request-document-id"); - setSearchParams(searchParams); }, }); + setSearchParams(searchParams); } else if (reportId) { + searchParams.delete("request-report-id"); void requestReportAccess({ variables: { input: { reportId }, @@ -133,22 +130,18 @@ export function useRequestAccessCallback() { onCompleted: (_, errors) => { if (errors?.length) { toast(errorToastArgs(__, errors)); - searchParams.delete("request-report-id"); - setSearchParams(searchParams); return; } toast(successToastArgs(__)); - searchParams.delete("request-report-id"); - setSearchParams(searchParams); }, onError: (error) => { toast(errorToastArgs(__, error)); - searchParams.delete("request-report-id"); - setSearchParams(searchParams); }, }); + setSearchParams(searchParams); } else if (fileId) { + searchParams.delete("request-file-id"); void requestFileAccess({ variables: { input: { trustCenterFileId: fileId }, @@ -156,43 +149,34 @@ export function useRequestAccessCallback() { onCompleted: (_, errors) => { if (errors?.length) { toast(errorToastArgs(__, errors)); - searchParams.delete("request-file-id"); - setSearchParams(searchParams); return; } toast(successToastArgs(__)); - searchParams.delete("request-file-id"); - setSearchParams(searchParams); }, onError: (error) => { toast(errorToastArgs(__, error)); - searchParams.delete("request-file-id"); - setSearchParams(searchParams); }, }); + setSearchParams(searchParams); } else if (all) { + searchParams.delete("request-all"); void requestAll({ variables: {}, onCompleted: (_, errors) => { if (errors?.length) { toast(errorToastArgs(__, errors)); - searchParams.delete("request-all"); - setSearchParams(searchParams); return; } toast(successToastArgs(__)); - searchParams.delete("request-all"); - setSearchParams(searchParams); window.location.href = location.pathname; }, onError: (error) => { toast(errorToastArgs(__, error)); - searchParams.delete("request-all"); - setSearchParams(searchParams); }, }); + setSearchParams(searchParams); } }, [ documentId, diff --git a/apps/trust/src/pages/NDAPage.tsx b/apps/trust/src/pages/NDAPage.tsx index a4b6c30e3..bfe60deb3 100644 --- a/apps/trust/src/pages/NDAPage.tsx +++ b/apps/trust/src/pages/NDAPage.tsx @@ -108,8 +108,16 @@ export function NDAPage(props: { const continueUrlParam = searchParams.get("continue"); let safeContinueUrl: string; if (continueUrlParam) { - const continueUrl = new URL(continueUrlParam); - safeContinueUrl = window.location.origin + continueUrl.pathname + continueUrl.search; + try { + const continueUrl = new URL(continueUrlParam, window.location.origin); + if (continueUrl.origin === window.location.origin && continueUrl.pathname.startsWith(`${getPathPrefix()}/`)) { + safeContinueUrl = window.location.origin + continueUrl.pathname + continueUrl.search; + } else { + safeContinueUrl = window.location.origin + getPathPrefix(); + } + } catch { + safeContinueUrl = window.location.origin + getPathPrefix(); + } } else { safeContinueUrl = window.location.origin + getPathPrefix(); } diff --git a/apps/trust/src/pages/auth/ConnectPage.tsx b/apps/trust/src/pages/auth/ConnectPage.tsx index 4f4622c92..b09b60de0 100644 --- a/apps/trust/src/pages/auth/ConnectPage.tsx +++ b/apps/trust/src/pages/auth/ConnectPage.tsx @@ -63,11 +63,18 @@ export function ConnectPage(props: { const continueUrlParam = searchParams.get("continue"); let safeContinueUrl: string; if (continueUrlParam) { - const continueUrl = new URL(continueUrlParam); - safeContinueUrl = window.location.origin + continueUrl.pathname + continueUrl.search; + try { + const continueUrl = new URL(continueUrlParam, window.location.origin); + if (continueUrl.origin === window.location.origin && continueUrl.pathname.startsWith(`${getPathPrefix()}/`)) { + safeContinueUrl = window.location.origin + continueUrl.pathname + continueUrl.search; + } else { + safeContinueUrl = window.location.origin + (getPathPrefix() || "/"); + } + } catch { + safeContinueUrl = window.location.origin + (getPathPrefix() || "/"); + } } else { - const pathPrefix = getPathPrefix(); - safeContinueUrl = window.location.origin + (pathPrefix ? getPathPrefix() : "/"); + safeContinueUrl = window.location.origin + (getPathPrefix() || "/"); } useEffect(() => { @@ -119,8 +126,7 @@ export function ConnectPage(props: { if (errors) { for (const err of errors) { if (err.extensions?.code === "ALREADY_AUTHENTICATED") { - const pathPrefix = getPathPrefix(); - window.location.href = pathPrefix ? getPathPrefix() : "/"; + window.location.href = getPathPrefix() || "/"; return; } } diff --git a/apps/trust/src/pages/auth/VerifyMagicLinkPage.tsx b/apps/trust/src/pages/auth/VerifyMagicLinkPage.tsx index 7de9ab5d2..f085c033a 100644 --- a/apps/trust/src/pages/auth/VerifyMagicLinkPage.tsx +++ b/apps/trust/src/pages/auth/VerifyMagicLinkPage.tsx @@ -42,8 +42,7 @@ export default function VerifyMagicLinkPagePageMutation() { if (errors) { for (const err of errors) { if (err.extensions?.code === "ALREADY_AUTHENTICATED") { - const pathPrefix = getPathPrefix(); - window.location.href = pathPrefix ? getPathPrefix() : "/"; + window.location.href = getPathPrefix() || "/"; return; } } @@ -64,11 +63,14 @@ export default function VerifyMagicLinkPagePageMutation() { }); if (verifyMagicLink?.continue) { - const continueUrl = new URL(verifyMagicLink.continue); - window.location.href = window.location.origin + continueUrl.pathname + continueUrl.search; + try { + const continueUrl = new URL(verifyMagicLink.continue, window.location.origin); + window.location.href = window.location.origin + continueUrl.pathname + continueUrl.search; + } catch { + window.location.href = getPathPrefix() || "/"; + } } else { - const pathPrefix = getPathPrefix(); - window.location.href = pathPrefix ? getPathPrefix() : "/"; + window.location.href = getPathPrefix() || "/"; } }, onError: (err) => { diff --git a/pkg/server/api/trust/v1/nda_directive.go b/pkg/server/api/trust/v1/nda_directive.go index e32d3af8a..1ac25e077 100644 --- a/pkg/server/api/trust/v1/nda_directive.go +++ b/pkg/server/api/trust/v1/nda_directive.go @@ -47,6 +47,10 @@ func newNDADirectiveFunc( } compliancePage := compliancepage.CompliancePageFromContext(ctx) + if compliancePage == nil { + logger.ErrorCtx(ctx, "cannot get compliance page from context") + return nil, gqlutils.Internal(ctx) + } if _, err := trustSvc.GetNDAFile(ctx, compliancePage.ID); err != nil { if errors.Is(err, trust.ErrNDAFileNotFound) { diff --git a/pkg/server/api/trust/v1/v1_resolver.go b/pkg/server/api/trust/v1/v1_resolver.go index a8646fb37..993fb6440 100644 --- a/pkg/server/api/trust/v1/v1_resolver.go +++ b/pkg/server/api/trust/v1/v1_resolver.go @@ -132,10 +132,14 @@ func (r *documentResolver) Access(ctx context.Context, obj *types.Document) (*ty obj.ID, ) if err != nil { - if errors.Is(err, trust.ErrDocumentAccessNotFound) { + if errors.Is(err, trust.ErrMembershipNotFound) || errors.Is(err, trust.ErrDocumentAccessNotFound) { return nil, nil } + if errors.Is(err, trust.ErrMembershipInactive) { + return nil, gqlutils.Forbidden(ctx, err) + } + r.logger.ErrorCtx(ctx, "cannot get document access", log.Error(err)) return nil, gqlutils.Internal(ctx) } @@ -851,11 +855,15 @@ func (r *reportResolver) Access(ctx context.Context, obj *types.Report) (*types. obj.ID, ) if err != nil { - if errors.Is(err, trust.ErrDocumentAccessNotFound) { + if errors.Is(err, trust.ErrMembershipNotFound) || errors.Is(err, trust.ErrDocumentAccessNotFound) { return nil, nil } - r.logger.ErrorCtx(ctx, "cannot get document access", log.Error(err)) + if errors.Is(err, trust.ErrMembershipInactive) { + return nil, gqlutils.Forbidden(ctx, err) + } + + r.logger.ErrorCtx(ctx, "cannot get audit report access", log.Error(err)) return nil, gqlutils.Internal(ctx) } @@ -1067,11 +1075,15 @@ func (r *trustCenterFileResolver) Access(ctx context.Context, obj *types.TrustCe obj.ID, ) if err != nil { - if errors.Is(err, trust.ErrDocumentAccessNotFound) { + if errors.Is(err, trust.ErrMembershipNotFound) || errors.Is(err, trust.ErrDocumentAccessNotFound) { return nil, nil } - r.logger.ErrorCtx(ctx, "cannot get document access", log.Error(err)) + if errors.Is(err, trust.ErrMembershipInactive) { + return nil, gqlutils.Forbidden(ctx, err) + } + + r.logger.ErrorCtx(ctx, "cannot get file access", log.Error(err)) return nil, gqlutils.Internal(ctx) } diff --git a/pkg/trust/service.go b/pkg/trust/service.go index 53c651b41..7fca56b6d 100644 --- a/pkg/trust/service.go +++ b/pkg/trust/service.go @@ -319,7 +319,7 @@ func (s *Service) GetNDAFile( } if trustCenter.NonDisclosureAgreementFileID == nil { - return nil + return ErrNDAFileNotFound } file = &coredata.File{}