Skip to content

Commit

Permalink
Change the criticality to a float number (#2585)
Browse files Browse the repository at this point in the history
* Change the criticality to a float number
  • Loading branch information
Cheshiriks authored Sep 13, 2023
1 parent 2f83f43 commit bcea40d
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 20 deletions.
5 changes: 5 additions & 0 deletions db/v-2/tables/vulnerability-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@
<renameColumn tableName="vulnerability_metadata" oldColumnName="cosv_id"
newColumnName="identifier" columnDataType="varchar(100)"/>
</changeSet>

<changeSet id="vulnerability-metadata-2" author="frolov">
<modifyDataType tableName="vulnerability_metadata" columnName="severity_num" newDataType="float"/>
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import kotlinx.serialization.Serializable
@Serializable
data class VulnerabilityDto(
val identifier: String,
val progress: Int,
val progress: Float,
val projects: List<VulnerabilityProjectDto>,
val description: String?,
val shortDescription: String,
Expand Down Expand Up @@ -65,7 +65,7 @@ data class VulnerabilityDto(
companion object {
val empty = VulnerabilityDto(
"",
0,
0f,
emptyList(),
"",
"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<VulnerabilityBadgeProps> = 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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit bcea40d

Please sign in to comment.