From bcea40d0183bcee62fc2872afb7198221b5c2c9b Mon Sep 17 00:00:00 2001
From: Vladislav Frolov <50615459+Cheshiriks@users.noreply.github.com>
Date: Wed, 13 Sep 2023 19:03:18 +0300
Subject: [PATCH] Change the criticality to a float number (#2585)
* Change the criticality to a float number
---
db/v-2/tables/vulnerability-metadata.xml | 5 +++++
.../service/vulnerability/VulnerabilityService.kt | 2 +-
.../save/entities/cosv/VulnerabilityMetadataDto.kt | 2 +-
.../entities/vulnerability/VulnerabilityDto.kt | 4 ++--
.../com/saveourtool/save/utils/CosvSchemaUtils.kt | 2 +-
.../save/entities/cosv/VulnerabilityMetadata.kt | 2 +-
.../cosv/repository/CosvRepositoryInStorage.kt | 4 ++--
.../views/vuln/CreateVulnerabilityView.kt | 10 +++++-----
.../components/views/vuln/VulnerabilityBadge.kt | 14 ++++++++------
.../externals/progressbar/ReactCircleBuilder.kt | 2 +-
.../com/saveourtool/save/frontend/themes/Colors.kt | 1 +
11 files changed, 28 insertions(+), 20 deletions(-)
diff --git a/db/v-2/tables/vulnerability-metadata.xml b/db/v-2/tables/vulnerability-metadata.xml
index 924dcbe8de..cca72a897e 100644
--- a/db/v-2/tables/vulnerability-metadata.xml
+++ b/db/v-2/tables/vulnerability-metadata.xml
@@ -10,4 +10,9 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/save-backend/src/main/kotlin/com/saveourtool/save/backend/service/vulnerability/VulnerabilityService.kt b/save-backend/src/main/kotlin/com/saveourtool/save/backend/service/vulnerability/VulnerabilityService.kt
index d4e02faeba..1f5b570b0b 100644
--- a/save-backend/src/main/kotlin/com/saveourtool/save/backend/service/vulnerability/VulnerabilityService.kt
+++ b/save-backend/src/main/kotlin/com/saveourtool/save/backend/service/vulnerability/VulnerabilityService.kt
@@ -218,7 +218,7 @@ class VulnerabilityService(
identifier = "default-${Random.nextInt()}",
summary = "STUB",
details = "STUB",
- severityNum = 0,
+ severityNum = 0f,
submitted = getCurrentLocalDateTime().toJavaLocalDateTime(),
modified = getCurrentLocalDateTime().toJavaLocalDateTime(),
user = userRepository.getByIdOrNotFound(authentication.userId()),
diff --git a/save-cloud-common/src/commonMain/kotlin/com/saveourtool/save/entities/cosv/VulnerabilityMetadataDto.kt b/save-cloud-common/src/commonMain/kotlin/com/saveourtool/save/entities/cosv/VulnerabilityMetadataDto.kt
index b177c1d233..550812e644 100644
--- a/save-cloud-common/src/commonMain/kotlin/com/saveourtool/save/entities/cosv/VulnerabilityMetadataDto.kt
+++ b/save-cloud-common/src/commonMain/kotlin/com/saveourtool/save/entities/cosv/VulnerabilityMetadataDto.kt
@@ -23,7 +23,7 @@ data class VulnerabilityMetadataDto(
val identifier: String,
val summary: String,
val details: String,
- val severityNum: Int,
+ val severityNum: Float,
val modified: LocalDateTime,
val submitted: LocalDateTime,
val user: UserInfo,
diff --git a/save-cloud-common/src/commonMain/kotlin/com/saveourtool/save/entities/vulnerability/VulnerabilityDto.kt b/save-cloud-common/src/commonMain/kotlin/com/saveourtool/save/entities/vulnerability/VulnerabilityDto.kt
index 9139064454..5eed2b52f4 100644
--- a/save-cloud-common/src/commonMain/kotlin/com/saveourtool/save/entities/vulnerability/VulnerabilityDto.kt
+++ b/save-cloud-common/src/commonMain/kotlin/com/saveourtool/save/entities/vulnerability/VulnerabilityDto.kt
@@ -28,7 +28,7 @@ import kotlinx.serialization.Serializable
@Serializable
data class VulnerabilityDto(
val identifier: String,
- val progress: Int,
+ val progress: Float,
val projects: List,
val description: String?,
val shortDescription: String,
@@ -65,7 +65,7 @@ data class VulnerabilityDto(
companion object {
val empty = VulnerabilityDto(
"",
- 0,
+ 0f,
emptyList(),
"",
"",
diff --git a/save-cloud-common/src/commonMain/kotlin/com/saveourtool/save/utils/CosvSchemaUtils.kt b/save-cloud-common/src/commonMain/kotlin/com/saveourtool/save/utils/CosvSchemaUtils.kt
index 39eb584e6f..2c5c4dbbd8 100644
--- a/save-cloud-common/src/commonMain/kotlin/com/saveourtool/save/utils/CosvSchemaUtils.kt
+++ b/save-cloud-common/src/commonMain/kotlin/com/saveourtool/save/utils/CosvSchemaUtils.kt
@@ -91,7 +91,7 @@ fun CosvSchema<*, *, *, *>.getRelatedLink(): String? = references
/**
* @return Severity for a single progress
*/
-fun Int.asSeverity(): Severity = Severity(
+fun Float.asSeverity(): Severity = Severity(
type = SeverityType.CVSS_V3,
score = "N/A",
scoreNum = toString(),
diff --git a/save-cloud-common/src/jvmMain/kotlin/com/saveourtool/save/entities/cosv/VulnerabilityMetadata.kt b/save-cloud-common/src/jvmMain/kotlin/com/saveourtool/save/entities/cosv/VulnerabilityMetadata.kt
index 562e16e677..0325c188d4 100644
--- a/save-cloud-common/src/jvmMain/kotlin/com/saveourtool/save/entities/cosv/VulnerabilityMetadata.kt
+++ b/save-cloud-common/src/jvmMain/kotlin/com/saveourtool/save/entities/cosv/VulnerabilityMetadata.kt
@@ -30,7 +30,7 @@ class VulnerabilityMetadata(
var identifier: String,
var summary: String,
var details: String,
- var severityNum: Int,
+ var severityNum: Float,
var modified: LocalDateTime,
var submitted: LocalDateTime,
@ManyToOne
diff --git a/save-cosv/src/main/kotlin/com/saveourtool/save/cosv/repository/CosvRepositoryInStorage.kt b/save-cosv/src/main/kotlin/com/saveourtool/save/cosv/repository/CosvRepositoryInStorage.kt
index b19c39fc9e..65a6ec8779 100644
--- a/save-cosv/src/main/kotlin/com/saveourtool/save/cosv/repository/CosvRepositoryInStorage.kt
+++ b/save-cosv/src/main/kotlin/com/saveourtool/save/cosv/repository/CosvRepositoryInStorage.kt
@@ -135,7 +135,7 @@ class CosvRepositoryInStorage(
identifier = id,
summary = summary ?: "Summary not provided",
details = details ?: "Details not provided",
- severityNum = severity?.firstOrNull()?.scoreNum?.toInt() ?: 0,
+ severityNum = severity?.firstOrNull()?.scoreNum?.toFloat() ?: 0f,
modified = modified.toJavaLocalDateTime(),
submitted = getCurrentLocalDateTime().toJavaLocalDateTime(),
user = user,
@@ -149,7 +149,7 @@ class CosvRepositoryInStorage(
details = entry.details ?: "Details not provided"
severityNum = entry.severity?.firstOrNull()
?.scoreNum
- ?.toInt() ?: 0
+ ?.toFloat() ?: 0f
modified = entry.modified.toJavaLocalDateTime()
}
diff --git a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/views/vuln/CreateVulnerabilityView.kt b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/views/vuln/CreateVulnerabilityView.kt
index 03b6271c8f..eb0c6c8fe0 100644
--- a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/views/vuln/CreateVulnerabilityView.kt
+++ b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/views/vuln/CreateVulnerabilityView.kt
@@ -301,17 +301,17 @@ val createVulnerabilityView: VFC = VFC {
required = true
defaultValue = 0
onChange = { event ->
- val progress = event.target.value.toIntOrNull()
- if (progress !in (1..100)) {
- setConflictErrorMessage("Progress must be an integer number from 1 to 100")
+ val progress = event.target.value.toFloat()
+ if (progress !in (0f..10f)) {
+ setConflictErrorMessage("Progress must be an float number with only one digit after the decimal point from 0 to 10.0")
} else {
- setVulnerability { it.copy(progress = progress!!) }
+ setVulnerability { it.copy(progress = progress) }
setConflictErrorMessage(null)
}
}
asDynamic()["data-toggle"] = "tooltip"
asDynamic()["data-placement"] = "bottom"
- title = "Vulnerability criticality percentage (1..100)"
+ title = "Vulnerability criticality percentage (0..10.0)"
}
}
}
diff --git a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/views/vuln/VulnerabilityBadge.kt b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/views/vuln/VulnerabilityBadge.kt
index 011819eae5..bc658d3019 100644
--- a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/views/vuln/VulnerabilityBadge.kt
+++ b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/views/vuln/VulnerabilityBadge.kt
@@ -14,16 +14,18 @@ import react.dom.html.ReactHTML.h4
import web.cssom.*
import web.cssom.TextDecoration.Companion.underline
-private const val FOR_GREEN = 34
-private const val FOR_YELLOW = 67
-private const val MAX_VALUE = 100
+private const val FOR_GREEN = 3.9f
+private const val FOR_YELLOW = 6.9f
+private const val FOR_ORANGE = 8.9f
+private const val MAX_VALUE = 10.0f
val vulnerabilityBadge: FC = FC { props ->
val (color, criticalityLabel) = when (props.vulnerability.progress) {
- in 0..FOR_GREEN -> Colors.SUCCESS.value to "Low"
- in FOR_GREEN..FOR_YELLOW -> Colors.WARNING.value to "Moderate"
+ in 0f..FOR_GREEN -> Colors.SUCCESS.value to "Low"
+ in FOR_GREEN..FOR_YELLOW -> Colors.WARNING.value to "Medium"
+ in FOR_YELLOW..FOR_ORANGE -> Colors.ORANGE.value to "High"
in FOR_YELLOW..MAX_VALUE -> Colors.DANGER.value to "Critical"
- else -> throw IllegalStateException("Progress should be in [0; 100], got ${props.vulnerability.progress}")
+ else -> throw IllegalStateException("Progress should be in [0; 10.0], got ${props.vulnerability.progress}")
}
div {
className = ClassName("card shadow")
diff --git a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/externals/progressbar/ReactCircleBuilder.kt b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/externals/progressbar/ReactCircleBuilder.kt
index d5609c697f..b11ef0f69a 100644
--- a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/externals/progressbar/ReactCircleBuilder.kt
+++ b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/externals/progressbar/ReactCircleBuilder.kt
@@ -16,7 +16,7 @@ import react.react
*/
@Suppress("LongParameterList", "TOO_MANY_PARAMETERS")
fun ChildrenBuilder.progressBar(
- progress: Int,
+ progress: Float,
size: String = "10rem",
lineWidth: String = "5rem",
color: String = Colors.SUCCESS.value,
diff --git a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/themes/Colors.kt b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/themes/Colors.kt
index 7e22dbde10..f84ce967f3 100644
--- a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/themes/Colors.kt
+++ b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/themes/Colors.kt
@@ -9,6 +9,7 @@ enum class Colors(val value: String) {
GOLD("rgba(188,187,47, 0.1)"),
GREEN("rgba(139, 237, 78, 0.1)"),
GREY("rgba(188,186,179, 0.1)"),
+ ORANGE("#ffa500"),
RED("rgba(245, 50, 50, 0.1)"),
SAVE_PRIMARY("#3075c0"),
SUCCESS("#28a745"),