Skip to content

Commit

Permalink
VulnerabilityView localization (#2594)
Browse files Browse the repository at this point in the history
* VulnerabilityView localization

### What's done:
 * Added localization for VulnerabilityView

---------

Co-authored-by: Kirill Gevorkyan <[email protected]>
  • Loading branch information
sanyavertolet and kgevorkyan authored Sep 15, 2023
1 parent 4d028aa commit ca39e60
Show file tree
Hide file tree
Showing 18 changed files with 303 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,20 +186,19 @@ class VulnerabilityService(
* @param name name of vulnerability
* @return vulnerability dto by name with description
*/
fun getVulnerabilityWithDescriptionByIdentifier(name: String): Mono<VulnerabilityDto> =
cosvRepository.findLatestRawExt(name)
.blockingMap { rawCosvExt ->
rawCosvExt to lnkCosvMetadataTagRepository.findAllByVulnerabilityMetadataIdentifier(rawCosvExt.metadata.identifier)
}
.map { (rawCostExt, tags) ->
rawCostExt.toVulnerabilityDtoWithDescription()
.copy(
dates = rawCostExt.cosv.getTimeline(),
participants = rawCostExt.saveContributors,
userInfo = rawCostExt.metadata.user,
tags = tags.map { it.tag.name }.toSet(),
)
}
fun getVulnerabilityWithDescriptionByIdentifier(name: String): Mono<VulnerabilityDto> = cosvRepository.findLatestRawExt(name)
.blockingMap { rawCosvExt ->
rawCosvExt to lnkCosvMetadataTagRepository.findAllByVulnerabilityMetadataIdentifier(rawCosvExt.metadata.identifier)
}
.map { (rawCostExt, tags) ->
rawCostExt.toVulnerabilityDtoWithDescription()
.copy(
dates = rawCostExt.cosv.getTimeline(),
participants = rawCostExt.saveContributors,
userInfo = rawCostExt.metadata.user,
tags = tags.map { it.tag.name }.toSet(),
)
}

/**
* @param vulnerabilityDto dto of new vulnerability
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import com.saveourtool.save.entities.CommentDto
import com.saveourtool.save.frontend.components.inputform.InputTypes
import com.saveourtool.save.frontend.externals.fontawesome.faPaperPlane
import com.saveourtool.save.frontend.externals.fontawesome.faTimes
import com.saveourtool.save.frontend.externals.i18next.TranslationFunction
import com.saveourtool.save.frontend.externals.i18next.useTranslation
import com.saveourtool.save.frontend.utils.*
import com.saveourtool.save.frontend.utils.AVATAR_PLACEHOLDER
import com.saveourtool.save.info.UserInfo
Expand Down Expand Up @@ -35,12 +37,10 @@ import kotlinx.serialization.json.Json
/**
* @return a function component
*/
@Suppress(
"GENERIC_VARIABLE_WRONG_DECLARATION",
"MAGIC_NUMBER",
)
@Suppress("MAGIC_NUMBER")
val newCommentWindow: FC<NewCommentWindowProps> = FC { props ->
val (comment, setComment) = useState(CommentDto.empty)
val (t) = useTranslation("comments")

val enrollRequest = useDeferredRequest {
val commentNew = comment.copy(section = window.location.pathname)
Expand All @@ -65,7 +65,8 @@ val newCommentWindow: FC<NewCommentWindowProps> = FC { props ->
props.currentUserInfo.avatar,
props.currentUserInfo.name,
props.currentUserInfo.rating,
"#f7f5fb"
t,
"#f7f5fb",
)
div {
className = ClassName("col")
Expand All @@ -81,7 +82,7 @@ val newCommentWindow: FC<NewCommentWindowProps> = FC { props ->
rows = 5
id = InputTypes.COMMENT.name
required = true
placeholder = "Write a comment"
placeholder = "Write a comment".t()
}
}
}
Expand All @@ -103,14 +104,16 @@ val newCommentWindow: FC<NewCommentWindowProps> = FC { props ->
/**
* [FC] for comment displaying
*/
@Suppress("GENERIC_VARIABLE_WRONG_DECLARATION", "MAGIC_NUMBER")
@Suppress("MAGIC_NUMBER")
val commentWindow: FC<CommentWindowProps> = FC { props ->
val (t) = useTranslation("comments")
div {
className = ClassName("shadow input-group row no-gutters mx-auto border-secondary")
renderLeftColumn(
props.comment.userAvatar,
props.comment.userName,
props.comment.userRating,
t,
)
div {
className = ClassName("shadow-none card col-10 text-left border-0")
Expand All @@ -120,12 +123,12 @@ val commentWindow: FC<CommentWindowProps> = FC { props ->
style = jso { background = "#f1f1f1".unsafeCast<Background>() }
span {
className = ClassName("ml-1")
+(comment.createDate?.toUnixCalendarFormat(TimeZone.currentSystemDefault()) ?: "Unknown")
+(comment.createDate?.toUnixCalendarFormat(TimeZone.currentSystemDefault()) ?: "Unknown".t())
}
div {
if (props.currentUserInfo?.canDelete(props.comment) == true) {
buttonBuilder(faTimes, style = "", classes = "btn-sm") {
if (window.confirm("Are you sure you want to delete a comment?")) {
if (window.confirm("Are you sure you want to delete a comment?".t())) {
props.setCommentForDeletion(props.comment)
}
}
Expand Down Expand Up @@ -177,11 +180,12 @@ external interface NewCommentWindowProps : PropsWithChildren {

private fun UserInfo.canDelete(commentDto: CommentDto) = isSuperAdmin() || name == commentDto.userName

@Suppress("MAGIC_NUMBER")
@Suppress("MAGIC_NUMBER", "IDENTIFIER_LENGTH")
private fun ChildrenBuilder.renderLeftColumn(
userAvatar: String?,
name: String,
rating: Long,
t: TranslationFunction,
color: String = "#f1f1f1",
) {
val (avatar, setAvatar) = useState(userAvatar?.avatarRenderer() ?: AVATAR_PROFILE_PLACEHOLDER)
Expand Down Expand Up @@ -217,7 +221,7 @@ private fun ChildrenBuilder.renderLeftColumn(
}
div {
className = ClassName("col-12 text-center text-xs font-weight-bold text-info text-uppercase")
+"Rating"
+"Rating".t()
}
div {
className = ClassName("col-12 text-center text-xs")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package com.saveourtool.save.frontend.components.basic
import com.saveourtool.save.entities.vulnerability.VulnerabilityDateType
import com.saveourtool.save.entities.vulnerability.VulnerabilityDateType.Companion.isSystemDateType
import com.saveourtool.save.entities.vulnerability.VulnerabilityDto
import com.saveourtool.save.frontend.externals.i18next.useTranslation
import com.saveourtool.save.frontend.utils.buttonBuilder
import react.*
import react.dom.html.ReactHTML.div
Expand All @@ -15,6 +16,7 @@ import kotlinx.datetime.LocalDateTime
const val HOVERABLE_CONST = "hoverable"

val timelineComponent: FC<TimelineComponentProps> = FC { props ->
val (t) = useTranslation("dates")
val hoverable = props.onNodeClick?.let { HOVERABLE_CONST }.orEmpty()

div {
Expand All @@ -28,7 +30,7 @@ val timelineComponent: FC<TimelineComponentProps> = FC { props ->

props.onAddClick?.let { onClickCallback ->
buttonBuilder(
label = "Add date",
label = "Add date".t(),
style = "secondary",
isOutline = true,
classes = "btn btn-sm btn-primary"
Expand Down Expand Up @@ -62,7 +64,7 @@ val timelineComponent: FC<TimelineComponentProps> = FC { props ->
}
div {
className = ClassName("text-label")
+label
+label.t()
}
div {
className = ClassName("date-label")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package com.saveourtool.save.frontend.components.views.vuln

import com.saveourtool.save.entities.vulnerability.VulnerabilityDto
import com.saveourtool.save.frontend.externals.i18next.useTranslation
import com.saveourtool.save.frontend.externals.progressbar.progressBar
import com.saveourtool.save.frontend.themes.Colors
import js.core.jso
Expand All @@ -20,6 +21,7 @@ private const val FOR_ORANGE = 8.9f
private const val MAX_VALUE = 10.0f

val vulnerabilityBadge: FC<VulnerabilityBadgeProps> = FC { props ->
val (t) = useTranslation("vulnerability")
val (color, criticalityLabel) = when (props.vulnerability.progress) {
in 0f..FOR_GREEN -> Colors.SUCCESS.value to "Low"
in FOR_GREEN..FOR_YELLOW -> Colors.WARNING.value to "Medium"
Expand Down Expand Up @@ -50,7 +52,7 @@ val vulnerabilityBadge: FC<VulnerabilityBadgeProps> = FC { props ->
className = ClassName("row align-items-center mb-2")
h4 {
className = ClassName("text-gray-900 mb-2")
+"Criticality Scoring"
+"Criticality Scoring".t()
}
}
div {
Expand Down Expand Up @@ -90,9 +92,4 @@ external interface VulnerabilityBadgeProps : Props {
* [VulnerabilityDto] to display
*/
var vulnerability: VulnerabilityDto

/**
* horizontal alignment
*/
var horizontalAlignment: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.saveourtool.save.entities.CommentDto
import com.saveourtool.save.entities.vulnerability.VulnerabilityDto
import com.saveourtool.save.frontend.components.basic.commentWindow
import com.saveourtool.save.frontend.components.basic.newCommentWindow
import com.saveourtool.save.frontend.externals.i18next.useTranslation
import com.saveourtool.save.frontend.utils.*
import com.saveourtool.save.info.UserInfo

Expand All @@ -25,6 +26,7 @@ import kotlinx.serialization.json.Json
private const val DEFAULT_MAX_COMMENT_AMOUNT = 5

val vulnerabilityCommentTab: FC<VulnerabilityCommentTabProps> = FC { props ->
val (t) = useTranslation("comments")
val (comments, setComments) = useState(emptyList<CommentDto>())
val (isAllCommentsShown, setIsAllCommentsShown) = useState(false)

Expand Down Expand Up @@ -114,7 +116,7 @@ val vulnerabilityCommentTab: FC<VulnerabilityCommentTabProps> = FC { props ->
className = ClassName("col-12 mt-3")
h4 {
className = ClassName("text-center card p-2 shadow")
+"Authorize in order to write comments"
+"Authorize in order to write comments".t()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.saveourtool.save.entities.vulnerability.VulnerabilityDateType.Compani
import com.saveourtool.save.frontend.components.inputform.*
import com.saveourtool.save.frontend.components.inputform.inputTextDisabled
import com.saveourtool.save.frontend.components.modal.modal
import com.saveourtool.save.frontend.externals.i18next.useTranslation
import com.saveourtool.save.frontend.utils.*

import react.FC
Expand All @@ -25,6 +26,7 @@ import kotlinx.serialization.json.Json
* Component that allows to add new project in vulnerability
*/
val vulnerabilityDateModal: FC<VulnerabilityDateModalProps> = FC { props ->
val (t) = useTranslation(arrayOf("vulnerability", "dates"))
val (vulnerabilityDate, setVulnerabilityDate) = useState(VulnerabilityDateDto.empty)
val (conflictMessage, setConflictMessage) = useState<String?>(null)
val addDate = useDeferredRequest {
Expand All @@ -50,7 +52,7 @@ val vulnerabilityDateModal: FC<VulnerabilityDateModalProps> = FC { props ->
inputTextDisabled(
InputTypes.CVE_NAME,
"mt-3",
"Vulnerability identifier",
"Vulnerability identifier".t(),
props.identifier,
true,
)
Expand All @@ -59,22 +61,22 @@ val vulnerabilityDateModal: FC<VulnerabilityDateModalProps> = FC { props ->
className = ClassName("mt-3")
label {
className = ClassName("form-label")
+"Date type"
+"Date type".t()
span {
className = ClassName("text-danger text-left")
+"*"
}
}

selectorBuilder(
vulnerabilityDate.type.value,
VulnerabilityDateType.values().map { it.value }.filterNot { it.isSystemDateType() },
"dates:${vulnerabilityDate.type.value}".t(),
VulnerabilityDateType.values().map { "dates:${it.value}".t() }.filterNot { it.isSystemDateType() },
classes = "form-control custom-select",
) { event ->
setVulnerabilityDate { date ->
val type = requireNotNull(
event.target.value.let { typeName ->
VulnerabilityDateType.values().find { it.value == typeName }
VulnerabilityDateType.values().find { "dates:${it.value}".t() == "dates:$typeName".t() }
}
)
date.copy(type = type)
Expand All @@ -87,7 +89,7 @@ val vulnerabilityDateModal: FC<VulnerabilityDateModalProps> = FC { props ->
InputTypes.CVE_DATE,
true,
"mt-3",
"Date",
"Date".t(),
) { event ->
setVulnerabilityDate { date ->
date.copy(date = event.target.value.dateStringToLocalDateTime())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.saveourtool.save.frontend.components.basic.renderAvatar
import com.saveourtool.save.frontend.components.basic.renderUserAvatarWithName
import com.saveourtool.save.frontend.components.basic.userBoard
import com.saveourtool.save.frontend.externals.fontawesome.*
import com.saveourtool.save.frontend.externals.i18next.useTranslation
import com.saveourtool.save.frontend.utils.*
import com.saveourtool.save.info.UserInfo
import com.saveourtool.save.utils.toUnixCalendarFormat
Expand All @@ -32,6 +33,7 @@ import kotlinx.serialization.json.Json
*/
@Suppress("EMPTY_BLOCK_STRUCTURE_ERROR", "MAGIC_NUMBER")
val vulnerabilityGeneralInfo: FC<VulnerabilityGeneralInfo> = FC { props ->
val (t) = useTranslation("vulnerability")
val enrollRequest = useDeferredRequest {
post(
"$apiUrl/vulnerabilities/update",
Expand Down Expand Up @@ -67,8 +69,8 @@ val vulnerabilityGeneralInfo: FC<VulnerabilityGeneralInfo> = FC { props ->
style = jso {
textDecoration = underline
}
+"Edit "
fontAwesomeIcon(icon = faEdit)
+"Edit".t()
fontAwesomeIcon(icon = faEdit, "ml-1")
}
},
isOutline = true, classes = "text-xs text-left ml-auto"
Expand Down Expand Up @@ -111,7 +113,7 @@ val vulnerabilityGeneralInfo: FC<VulnerabilityGeneralInfo> = FC { props ->
className = ClassName("d-flex justify-content-between align-items-center")
label {
className = ClassName("m-0")
+"Last update time:"
+"${"Last update time".t()}:"
}
label {
className = ClassName("m-0")
Expand All @@ -121,7 +123,7 @@ val vulnerabilityGeneralInfo: FC<VulnerabilityGeneralInfo> = FC { props ->
hr { }
h6 {
className = ClassName("font-weight-bold text-primary-blue mb-4")
+"Description"
+"Description".t()
}
textarea {
className = ClassName("auto_height form-control-plaintext px-2 pt-0 pb-0 text-gray-900")
Expand All @@ -143,7 +145,7 @@ val vulnerabilityGeneralInfo: FC<VulnerabilityGeneralInfo> = FC { props ->
hr { }
h6 {
className = ClassName("font-weight-bold text-primary-blue mb-4")
+"Tags"
+"Tags".t()
}
div {
vulnerabilityTagsComponent {
Expand All @@ -160,7 +162,7 @@ val vulnerabilityGeneralInfo: FC<VulnerabilityGeneralInfo> = FC { props ->
hr { }
h6 {
className = ClassName("font-weight-bold text-primary-blue mb-4")
+"Related link"
+"Related link".t()
}
Link {
to = relatedLink.toString()
Expand All @@ -171,7 +173,7 @@ val vulnerabilityGeneralInfo: FC<VulnerabilityGeneralInfo> = FC { props ->
hr { }
h6 {
className = ClassName("font-weight-bold text-primary-blue mb-3")
+"Author"
+"Author".t()
}
renderUserAvatarWithName(this@run, isHorizontal = true, classes = "mr-2") {
height = 4.rem
Expand All @@ -183,7 +185,7 @@ val vulnerabilityGeneralInfo: FC<VulnerabilityGeneralInfo> = FC { props ->
hr { }
h6 {
className = ClassName("font-weight-bold text-primary-blue mb-3")
+"Organization"
+"Organization".t()
}
Link {
renderAvatar(this@run) {
Expand All @@ -198,7 +200,7 @@ val vulnerabilityGeneralInfo: FC<VulnerabilityGeneralInfo> = FC { props ->
hr { }
h6 {
className = ClassName("font-weight-bold text-primary-blue mb-4")
+"Collaborators"
+"Collaborators".t()
}
userBoard {
users = participants
Expand Down
Loading

0 comments on commit ca39e60

Please sign in to comment.