Fix misc bugs

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-03-04 10:45:43 +04:00
parent a160dc1f47
commit 8dc5fffa58
11 changed files with 75 additions and 55 deletions

View File

@@ -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<AuditRow_requestAccessMutation>(requestAccessMutation);

View File

@@ -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<DocumentRow_requestAccessMutation>(requestAccessMutation);

View File

@@ -19,20 +19,24 @@ export function RootErrorBoundary() {
if (error instanceof UnAuthenticatedError) {
return (
<Navigate to={{
pathname: "/connect",
search: queryString ? "?" + queryString : "",
}}
<Navigate
replace
to={{
pathname: "/connect",
search: queryString ? "?" + queryString : "",
}}
/>
);
}
if (error instanceof NDASignatureRequiredError) {
return (
<Navigate to={{
pathname: "/nda",
search: queryString ? "?" + queryString : "",
}}
<Navigate
replace
to={{
pathname: "/nda",
search: queryString ? "?" + queryString : "",
}}
/>
);
}

View File

@@ -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<TrustCenterFileRow_requestAccessMutation>(

View File

@@ -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,

View File

@@ -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();
}

View File

@@ -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;
}
}

View File

@@ -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) => {

View File

@@ -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) {

View File

@@ -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)
}

View File

@@ -319,7 +319,7 @@ func (s *Service) GetNDAFile(
}
if trustCenter.NonDisclosureAgreementFileID == nil {
return nil
return ErrNDAFileNotFound
}
file = &coredata.File{}