-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added notification for propose new vulnerability (#2833)
* Added notification for propose new vulnerability
- Loading branch information
1 parent
075fe77
commit 2d70218
Showing
3 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...saveourtool/save/backend/controllers/vulnerability/event/VulnerabilityMetadataListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.saveourtool.save.backend.controllers.vulnerability.event | ||
|
||
import com.saveourtool.save.backend.service.NotificationService | ||
import com.saveourtool.save.backend.service.UserDetailsService | ||
import com.saveourtool.save.domain.Role | ||
import com.saveourtool.save.entities.Notification | ||
import com.saveourtool.save.entities.cosv.VulnerabilityMetadata | ||
import com.saveourtool.save.entities.cosv.evententities.VulnerabilityMetadataEvent | ||
import com.saveourtool.save.entities.vulnerability.VulnerabilityStatus | ||
import org.springframework.context.event.EventListener | ||
import org.springframework.stereotype.Component | ||
|
||
/** | ||
* A vulnerability metadata listener for sending notifications. | ||
*/ | ||
@Component | ||
class VulnerabilityMetadataListener( | ||
private val userDetailsService: UserDetailsService, | ||
private val notificationService: NotificationService, | ||
) { | ||
/** | ||
* @param vulnerabilityEvent new VulnerabilityMetadataEvent | ||
*/ | ||
@EventListener | ||
fun createVulnerabilityMetadata(vulnerabilityEvent: VulnerabilityMetadataEvent) { | ||
if (vulnerabilityEvent.vulnerabilityMetadata.status == VulnerabilityStatus.PENDING_REVIEW) { | ||
val recipients = userDetailsService.findByRole(Role.SUPER_ADMIN.asSpringSecurityRole()) | ||
val notifications = recipients.map { | ||
Notification( | ||
message = messageNewVulnerabilityMetadata(vulnerabilityEvent.vulnerabilityMetadata), | ||
user = it, | ||
) | ||
} | ||
notificationService.saveAll(notifications) | ||
} | ||
} | ||
|
||
companion object { | ||
/** | ||
* @param vulnerability | ||
* @return message | ||
*/ | ||
fun messageNewVulnerabilityMetadata(vulnerability: VulnerabilityMetadata) = """ | ||
New vulnerability: ${vulnerability.identifier} is waiting for approve. | ||
""".trimIndent() | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...ain/kotlin/com/saveourtool/save/entities/cosv/evententities/VulnerabilityMetadataEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.saveourtool.save.entities.cosv.evententities | ||
|
||
import com.saveourtool.save.entities.cosv.VulnerabilityMetadata | ||
|
||
/** | ||
* @property vulnerabilityMetadata | ||
**/ | ||
data class VulnerabilityMetadataEvent( | ||
var vulnerabilityMetadata: VulnerabilityMetadata | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters