Skip to content

Commit 1389336

Browse files
authored
Merge pull request #1943 from l3montree-dev/delete-reopened-and-fixed-system-events
Delete reopened and fixed system events
2 parents 7e662f2 + 748a2a7 commit 1389336

3 files changed

Lines changed: 47 additions & 12 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
-- Copyright (C) 2026 l3montree GmbH
2+
--
3+
-- This program is free software: you can redistribute it and/or modify
4+
-- it under the terms of the GNU Affero General Public License as
5+
-- published by the Free Software Foundation, either version 3 of the
6+
-- License, or (at your option) any later version.
7+
--
8+
-- This program is distributed in the hope that it will be useful,
9+
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
-- GNU Affero General Public License for more details.
12+
--
13+
-- You should have received a copy of the GNU Affero General Public License
14+
-- along with this program. If not, see <https://www.gnu.org/licenses/>.
15+
16+
17+
DELETE FROM public.vuln_events
18+
WHERE user_id = 'system'
19+
AND dependency_vuln_id IS NOT NULL
20+
AND type IN ('fixed', 'reopened');
21+
22+
UPDATE public.dependency_vulns dv
23+
SET state = CASE last_event.type WHEN 'reopened' THEN 'open' WHEN 'detected' THEN 'open' ELSE last_event.type END
24+
FROM (
25+
SELECT DISTINCT ON (dependency_vuln_id) dependency_vuln_id, type
26+
FROM public.vuln_events
27+
WHERE dependency_vuln_id IS NOT NULL
28+
AND type IN ('falsePositive', 'accepted', 'reopened', 'fixed', 'detected')
29+
ORDER BY dependency_vuln_id, created_at DESC
30+
) AS last_event
31+
WHERE dv.id = last_event.dependency_vuln_id
32+
AND dv.state != last_event.type;

services/dependency_vuln_service.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ func saveArtifactAssociations(tx shared.DB, vulns []models.DependencyVuln) error
8585
}
8686

8787
func (s *DependencyVulnService) UserFixedDependencyVulns(ctx context.Context, tx shared.DB, userID string, dependencyVulns []models.DependencyVuln, assetVersion models.AssetVersion, asset models.Asset) error {
88-
if len(dependencyVulns) == 0 {
88+
// we are not creating fixed or reopened events, if the user is "system", because this can only happen if there is a problem with the scanner or the database.
89+
if len(dependencyVulns) == 0 || userID == "system" {
8990
return nil
9091
}
9192

@@ -107,7 +108,8 @@ func (s *DependencyVulnService) UserFixedDependencyVulns(ctx context.Context, tx
107108
}
108109

109110
func (s *DependencyVulnService) UserReopenedToOpen(ctx context.Context, tx shared.DB, userID string, dependencyVulns []models.DependencyVuln) error {
110-
if len(dependencyVulns) == 0 {
111+
// we are not creating fixed or reopened events, if the user is "system", because this can only happen if there is a problem with the scanner or the database.
112+
if len(dependencyVulns) == 0 || userID == "system" {
111113
return nil
112114
}
113115

transformer/vulnevent_transformer.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,16 @@ func ConvertVulnEventsToDtos(events []models.VulnEventDetail) []dtos.VulnEventDT
4949

5050
func ConvertVulnEventToDto(event models.VulnEvent) dtos.VulnEventDTO {
5151
return dtos.VulnEventDTO{
52-
ID: event.ID,
53-
Type: event.Type,
54-
VulnID: event.GetVulnID(),
55-
VulnType: event.GetVulnType(),
56-
UserID: event.UserID,
57-
Justification: event.Justification,
58-
MechanicalJustification: event.MechanicalJustification,
59-
ArbitraryJSONData: event.GetArbitraryJSONData(),
60-
CreatedAt: event.CreatedAt,
61-
CreatedByVexRule: event.CreatedByVexRule,
52+
ID: event.ID,
53+
Type: event.Type,
54+
VulnID: event.GetVulnID(),
55+
VulnType: event.GetVulnType(),
56+
UserID: event.UserID,
57+
Justification: event.Justification,
58+
MechanicalJustification: event.MechanicalJustification,
59+
ArbitraryJSONData: event.GetArbitraryJSONData(),
60+
CreatedAt: event.CreatedAt,
61+
CreatedByVexRule: event.CreatedByVexRule,
62+
OriginalAssetVersionName: event.OriginalAssetVersionName,
6263
}
6364
}

0 commit comments

Comments
 (0)