From 92b1264603e4427c3158f47cfb8faba80ceb78d6 Mon Sep 17 00:00:00 2001 From: Bryan Frimin Date: Mon, 22 Jun 2026 09:08:14 +0200 Subject: [PATCH] Fix alias resolver, field blur, and sitemap URLs The audit alias resolver returned raw service errors. Log them and return gqlutils.Internal like other resolvers in the file. Remove-only users could edit the alias field to a new value that was never saved. Reset local state when set permission is missing, and catch mutation rejections on blur. Sitemap generation appended audit report file IDs without deduplication, which could emit duplicate document URLs when multiple audits share the same report file. Signed-off-by: Bryan Frimin --- .../_components/CompliancePageAliasField.tsx | 47 ++++++++++--------- pkg/server/api/console/v1/audit_resolvers.go | 8 +++- pkg/trust/compliance_page_service.go | 16 +++++-- 3 files changed, 46 insertions(+), 25 deletions(-) diff --git a/apps/console/src/pages/organizations/compliance-page/_components/CompliancePageAliasField.tsx b/apps/console/src/pages/organizations/compliance-page/_components/CompliancePageAliasField.tsx index a49816d47..07a7effc6 100644 --- a/apps/console/src/pages/organizations/compliance-page/_components/CompliancePageAliasField.tsx +++ b/apps/console/src/pages/organizations/compliance-page/_components/CompliancePageAliasField.tsx @@ -80,32 +80,37 @@ export function CompliancePageAliasField(props: { return; } - if (trimmed === "") { - if (current !== "" && canRemoveAlias) { - await removeTrustCenterAlias({ - variables: { - input: { - resourceId, + try { + if (trimmed === "") { + if (current !== "" && canRemoveAlias) { + await removeTrustCenterAlias({ + variables: { + input: { + resourceId, + }, }, - }, - }); + }); + } + + return; } - return; - } + if (!canSetAlias) { + setValue(current); + return; + } - if (!canSetAlias) { - return; - } - - await setTrustCenterAlias({ - variables: { - input: { - resourceId, - alias: trimmed, + await setTrustCenterAlias({ + variables: { + input: { + resourceId, + alias: trimmed, + }, }, - }, - }); + }); + } catch { + // useMutationWithToasts already shows an error toast. + } }, [alias, canRemoveAlias, canSetAlias, removeTrustCenterAlias, resourceId, setTrustCenterAlias, value]); const canEdit = canSetAlias || (canRemoveAlias && (alias ?? "") !== ""); diff --git a/pkg/server/api/console/v1/audit_resolvers.go b/pkg/server/api/console/v1/audit_resolvers.go index 55ec3f879..848333e51 100644 --- a/pkg/server/api/console/v1/audit_resolvers.go +++ b/pkg/server/api/console/v1/audit_resolvers.go @@ -180,7 +180,13 @@ func (r *auditResolver) Alias(ctx context.Context, obj *types.Audit) (*string, e return nil, err } - return r.probo.TrustCenterAliases.GetByResourceID(ctx, scope, obj.ID) + alias, err := r.probo.TrustCenterAliases.GetByResourceID(ctx, scope, obj.ID) + if err != nil { + r.logger.ErrorCtx(ctx, "cannot get audit alias", log.Error(err)) + return nil, gqlutils.Internal(ctx) + } + + return alias, nil } // Permission is the resolver for the permission field. diff --git a/pkg/trust/compliance_page_service.go b/pkg/trust/compliance_page_service.go index 99260d1d1..267ff7145 100644 --- a/pkg/trust/compliance_page_service.go +++ b/pkg/trust/compliance_page_service.go @@ -240,8 +240,18 @@ func (s *Service) RenderRobotsTxt( } func (s *Service) fetchDocumentIDs(ctx context.Context, scope coredata.Scoper, orgID gid.GID) ([]string, error) { + seen := make(map[gid.GID]struct{}) var resourceIDs []gid.GID + appendResourceID := func(id gid.GID) { + if _, ok := seen[id]; ok { + return + } + + seen[id] = struct{}{} + resourceIDs = append(resourceIDs, id) + } + var cursorKey *page.CursorKey for { cursor := page.NewCursor( @@ -264,7 +274,7 @@ func (s *Service) fetchDocumentIDs(ctx context.Context, scope coredata.Scoper, o continue } - resourceIDs = append(resourceIDs, doc.ID) + appendResourceID(doc.ID) } if !result.Info.HasNext { @@ -304,7 +314,7 @@ func (s *Service) fetchDocumentIDs(ctx context.Context, scope coredata.Scoper, o continue } - resourceIDs = append(resourceIDs, file.ID) + appendResourceID(file.ID) } if !result.Info.HasNext { @@ -342,7 +352,7 @@ func (s *Service) fetchDocumentIDs(ctx context.Context, scope coredata.Scoper, o continue } - resourceIDs = append(resourceIDs, *audit.ReportFileID) + appendResourceID(*audit.ReportFileID) } if !result.Info.HasNext {