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 <bryan@probo.com>
This commit is contained in:
@@ -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 ?? "") !== "");
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user