From 26908003314498c899545bf73319f274fb9071b5 Mon Sep 17 00:00:00 2001 From: Quentin Machu Date: Sat, 23 Jan 2016 22:02:51 -0500 Subject: [PATCH] database: create notification during vulnerability insertion --- database/pgsql/vulnerability.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/database/pgsql/vulnerability.go b/database/pgsql/vulnerability.go index b8a71f06..6ee07a70 100644 --- a/database/pgsql/vulnerability.go +++ b/database/pgsql/vulnerability.go @@ -196,12 +196,6 @@ func (pgSQL *pgSQL) insertVulnerability(vulnerability database.Vulnerability) er tx.Rollback() return handleError("i_vulnerability", err) } - - // Create NewVulnerabilityNotification. - notification := database.VulnerabilityNotification{NewVulnerability: vulnerability} - if err := pgSQL.insertNotification(tx, notification); err != nil { - return err - } } else { // Update vulnerability if vulnerability.Description != existingVulnerability.Description || @@ -228,6 +222,22 @@ func (pgSQL *pgSQL) insertVulnerability(vulnerability database.Vulnerability) er return err } + // Create notification. + var notification database.VulnerabilityNotification + if existingVulnerability.ID == 0 { + notification = database.VulnerabilityNotification{ + NewVulnerability: vulnerability, + } + } else { + notification = database.VulnerabilityNotification{ + OldVulnerability: &existingVulnerability, + NewVulnerability: vulnerability, + } + } + if err := pgSQL.insertNotification(tx, notification); err != nil { + return err + } + // Commit transaction. err = tx.Commit() if err != nil {