Skip to content

Commit 9191cd9

Browse files
authored
Merge pull request #2827 from trycompai/chas/add-comments-to-findings
CS-367 [Feature] Ability to add comments directly to findings
2 parents 2121ae0 + 1dd4f40 commit 9191cd9

5 files changed

Lines changed: 38 additions & 1 deletion

File tree

‎apps/api/src/audit/audit-log.constants.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export const COMMENT_ENTITY_TYPE_MAP: Record<string, AuditLogEntityType> = {
6161
[CommentEntityType.vendor]: AuditLogEntityType.vendor,
6262
[CommentEntityType.risk]: AuditLogEntityType.risk,
6363
[CommentEntityType.policy]: AuditLogEntityType.policy,
64+
[CommentEntityType.finding]: AuditLogEntityType.finding,
6465
};
6566

6667
// Fields that reference the member table and should be resolved to user names.

‎apps/api/src/comments/comment-mention-notifier.service.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,27 @@ async function buildFallbackCommentContext(params: {
174174
};
175175
}
176176

177+
if (entityType === CommentEntityType.finding) {
178+
const finding = await db.finding.findFirst({
179+
where: { id: entityId, organizationId },
180+
select: { content: true },
181+
});
182+
183+
if (!finding) {
184+
return null;
185+
}
186+
187+
const url = new URL(`${appUrl}/${organizationId}/overview/findings`);
188+
url.searchParams.set('open', entityId);
189+
190+
const snippet = finding.content?.trim().split('\n')[0]?.slice(0, 80);
191+
return {
192+
entityName: snippet || 'Finding',
193+
entityRoutePath: 'overview/findings',
194+
commentUrl: url.toString(),
195+
};
196+
}
197+
177198
// CommentEntityType.policy
178199
const policy = await db.policy.findFirst({
179200
where: { id: entityId, organizationId },

‎apps/api/src/comments/comments.service.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ export class CommentsService {
120120
break;
121121
}
122122

123+
case CommentEntityType.finding: {
124+
const finding = await db.finding.findFirst({
125+
where: { id: entityId, organizationId },
126+
});
127+
entityExists = !!finding;
128+
break;
129+
}
130+
123131
default:
124132
throw new BadRequestException(`Unsupported entity type: ${entityType}`);
125133
}

‎apps/app/src/app/(app)/[orgId]/overview/components/FindingDetailSheet.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,12 @@ export function FindingDetailSheet({
415415
Comments
416416
</Text>
417417
{finding ? (
418-
<Comments entityId={finding.id} entityType="finding" />
418+
<Comments
419+
entityId={finding.id}
420+
entityType="finding"
421+
organizationId={organizationId}
422+
readOnly={!canUpdate}
423+
/>
419424
) : null}
420425
</Stack>
421426

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterEnum
2+
ALTER TYPE "CommentEntityType" ADD VALUE 'finding';

0 commit comments

Comments
 (0)