Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editing view preparations: propagating of edit flag to children components #2559

Merged
merged 4 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api-gateway/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,8 @@ spring:
scope:
- user_info
---
# logout timeout
server:
servlet:
session:
timeout: 15m
orchestr7 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ class VulnerabilityController(
)
@ApiResponse(responseCode = "200", description = "Successfully updated vulnerability")
@RequiresAuthorizationSourceHeader
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
fun update(
@RequestBody vulnerabilityDto: VulnerabilityDto,
authentication: Authentication,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,16 +296,17 @@ class VulnerabilityService(

val vulnerability = vulnerabilityRepository.findByIdentifier(vulnerabilityDto.identifier).orNotFound()

if (!authentication.hasRole(Role.SUPER_ADMIN) && (userId != vulnerability.userId || vulnerability.status == VulnerabilityStatus.APPROVED)) {
// only Super Users and owners of unapproved vuln. can edit it
if (authentication.hasRole(Role.SUPER_ADMIN) || (userId == vulnerability.userId && vulnerability.status != VulnerabilityStatus.APPROVED)) {
val vulnerabilityUpdate = vulnerability.apply {
progress = vulnerabilityDto.progress
description = vulnerabilityDto.description.orEmpty()
status = vulnerabilityDto.status
}
vulnerabilityRepository.save(vulnerabilityUpdate)
} else {
throw ResponseStatusException(HttpStatus.FORBIDDEN)
}

val vulnerabilityUpdate = vulnerability.apply {
progress = vulnerabilityDto.progress
description = vulnerabilityDto.description.orEmpty()
status = vulnerabilityDto.status
}
vulnerabilityRepository.save(vulnerabilityUpdate)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ enum class VulnerabilityDateType(val value: String) {
*/
PUBLISHED("Published"),

/**
* Date when the vuln was submitted to our archive, our platform specific
*/
SUBMITTED("Submitted"),

/**
* Date from [com.saveourtool.osv4k.OsvSchema.withdrawn] in COSV schema
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import react.router.useNavigate
import web.cssom.ClassName
import web.html.ButtonType

import kotlinx.browser.window

/**
* Loader animation
*/
Expand Down Expand Up @@ -102,7 +104,8 @@ val requestModalHandler: FC<RequestModalProps> = FC { props ->
onClick = {
if (response?.status == 401.toShort()) {
// if 401 - change current URL to the main page (with login screen)
navigate("/")
navigate(to = "/")
window.location.reload()
}
setResponse(null)
setModalState(modalState.copy(isErrorModalOpen = false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

package com.saveourtool.save.frontend.components.basic

import com.saveourtool.save.entities.vulnerability.VulnerabilityDateType
import com.saveourtool.save.entities.vulnerability.VulnerabilityDto
import com.saveourtool.save.frontend.utils.buttonBuilder
import react.*
import react.dom.html.ReactHTML.div
Expand All @@ -28,45 +30,50 @@ val timelineComponent: FC<TimelineComponentProps> = FC { props ->
label = "Add date",
style = "secondary",
isOutline = true,
classes = "btn btn-primary"
classes = "btn btn-sm btn-primary"
) {
onClickCallback()
}
}

if (props.dates.isNotEmpty()) {
div {
className = ClassName("p-0 timeline-container")
div {
className = ClassName("p-0 timeline-container")
className = ClassName("steps-container")
div {
className = ClassName("steps-container")
div {
className = ClassName("line")
}
props.dates.toList()
.sortedBy { it.second }
.forEach { (label, dateTime) ->
div {
className = ClassName("step $hoverable")
className = ClassName("line")
}
props.dates
.plus(
VulnerabilityDateType.SUBMITTED.value to
(props.vulnerability.creationDateTime ?: LocalDateTime(0, 1, 1, 0, 0, 0, 0))
sanyavertolet marked this conversation as resolved.
Show resolved Hide resolved
)
.toList()
.sortedBy { it.second }
.forEach { (label, dateTime) ->
div {
className =
ClassName(if (!label.isSubmittedType()) "step $hoverable" else "step-non-editable")
if (!label.isSubmittedType()) {
props.onNodeClick?.let { onClickCallback ->
onClick = { onClickCallback(dateTime, label) }
}

div {
className = ClassName("text-label")
+label
}
div {
className = ClassName("date-label")
+dateTime.date.toString()
}
}
div {
className = ClassName("line")
className = ClassName("text-label")
+label
}
div {
className = ClassName("date-label")
+dateTime.date.toString()
}
}
div {
className = ClassName("line-end")
div {
className = ClassName("line")
}
}
div {
className = ClassName("line-end")
}
}
}
Expand Down Expand Up @@ -97,4 +104,11 @@ external interface TimelineComponentProps : Props {
*/
@Suppress("TYPE_ALIAS")
var onNodeClick: ((LocalDateTime, String) -> Unit)?

/**
* Vulnerability dto of vulnerability
*/
var vulnerability: VulnerabilityDto
}

private fun String.isSubmittedType() = this == VulnerabilityDateType.SUBMITTED.value
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import web.cssom.*
import web.html.ButtonType
import web.html.InputType

import kotlinx.browser.window
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json

Expand Down Expand Up @@ -54,6 +55,7 @@ val userSettingsView: FC<SettingsProps> = FC { props ->
type = ButtonType.button
onClick = {
useNavigate(to = "/")
window.location.reload()
}
+"Proceed to login page"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.saveourtool.save.frontend.components.views.vuln

import com.saveourtool.save.entities.vulnerability.VulnerabilityDto
import com.saveourtool.save.entities.vulnerability.VulnerabilityStatus
import com.saveourtool.save.frontend.components.basic.renderAvatar
import com.saveourtool.save.frontend.components.basic.renderUserAvatarWithName
import com.saveourtool.save.frontend.components.basic.userBoard
Expand All @@ -9,14 +10,17 @@ import com.saveourtool.save.frontend.utils.*
import com.saveourtool.save.info.UserInfo
import com.saveourtool.save.utils.toUnixCalendarFormat

import js.core.jso
import react.*
import react.dom.html.ReactHTML.div
import react.dom.html.ReactHTML.h6
import react.dom.html.ReactHTML.hr
import react.dom.html.ReactHTML.label
import react.dom.html.ReactHTML.p
import react.dom.html.ReactHTML.textarea
import react.router.dom.Link
import web.cssom.ClassName
import web.cssom.TextDecoration.Companion.underline
import web.cssom.rem

import kotlinx.datetime.TimeZone
Expand All @@ -28,14 +32,12 @@ import kotlinx.serialization.json.Json
*/
@Suppress("EMPTY_BLOCK_STRUCTURE_ERROR", "MAGIC_NUMBER")
val vulnerabilityGeneralInfo: FC<VulnerabilityGeneralInfo> = FC { props ->
val (vulnerability, setVulnerability) = useStateFromProps(props.vulnerability)

val enrollRequest = useDeferredRequest {
post(
"$apiUrl/vulnerabilities/update",
jsonHeaders,
Json.encodeToString(vulnerability),
loadingHandler = ::noopLoadingHandler,
Json.encodeToString(props.vulnerability),
loadingHandler = ::loadingHandler,
)
}

Expand All @@ -55,13 +57,21 @@ val vulnerabilityGeneralInfo: FC<VulnerabilityGeneralInfo> = FC { props ->
}
}
if (props.isEditDisabled) {
if (props.userInfo?.isSuperAdmin() == true || props.userInfo?.name == userInfo.name) {
// only Super Users and owners of unapproved vuln. can edit it
if (props.userInfo?.isSuperAdmin() == true ||
(props.userInfo?.name == userInfo.name && props.vulnerability.status != VulnerabilityStatus.APPROVED)) {
buttonBuilder(
labelBuilder = {
+"Edit "
fontAwesomeIcon(icon = faEdit)
p {
className = ClassName("mb-0")
style = jso {
textDecoration = underline
}
+"Edit "
fontAwesomeIcon(icon = faEdit)
}
},
"link", isOutline = true, classes = "text-xs text-muted text-left ml-auto"
isOutline = true, classes = "text-xs text-left ml-auto"
) {
props.setIsEditDisabled(false)
}
Expand All @@ -72,33 +82,36 @@ val vulnerabilityGeneralInfo: FC<VulnerabilityGeneralInfo> = FC { props ->
props.setIsEditDisabled(true)
}
buttonBuilder(faTimesCircle, null, isOutline = true) {
setVulnerability(props.vulnerability)
props.setVulnerability(props.vulnerability)
props.setIsEditDisabled(true)
}
}
}
textarea {
className = ClassName("auto_height form-control-plaintext pt-0 pb-0 text-gray-900")
className = ClassName("auto_height form-control-plaintext px-2 pt-0 pb-0 text-gray-900")
value = shortDescription
disabled = props.isEditDisabled
rows = 2
if (!props.isEditDisabled) {
style = borderEditStyle()
}
onChange = { event ->
props.setVulnerability { vulnerability ->
vulnerability.copy(
shortDescription = event.target.value
)
}
}
}
hr { }
div {
className = ClassName("d-flex justify-content-between align-items-center")
label {
className = ClassName("m-0")
+"Creation time:"
}
label {
className = ClassName("m-0")
+creationDateTime?.toUnixCalendarFormat(TimeZone.currentSystemDefault())
}
}
div {
className = ClassName("d-flex justify-content-between align-items-center")
label {
className = ClassName("m-0")
+"Last updated time:"
+"Last update time:"
}
label {
className = ClassName("m-0")
Expand All @@ -111,12 +124,15 @@ val vulnerabilityGeneralInfo: FC<VulnerabilityGeneralInfo> = FC { props ->
+"Description"
}
textarea {
className = ClassName("auto_height form-control-plaintext pt-0 pb-0 text-gray-900")
className = ClassName("auto_height form-control-plaintext px-2 pt-0 pb-0 text-gray-900")
value = description
disabled = props.isEditDisabled
rows = 8
if (!props.isEditDisabled) {
style = borderEditStyle()
}
onChange = { event ->
setVulnerability { vulnerability ->
props.setVulnerability { vulnerability ->
vulnerability.copy(
description = event.target.value
)
Expand All @@ -136,6 +152,7 @@ val vulnerabilityGeneralInfo: FC<VulnerabilityGeneralInfo> = FC { props ->
this.vulnerability = props.vulnerability
fetchVulnerability = props.fetchVulnerability
canEditVulnerability = props.canEditVulnerability
isEditDisabled = props.isEditDisabled
}
}
}
Expand Down Expand Up @@ -202,6 +219,11 @@ external interface VulnerabilityGeneralInfo : Props {
*/
var vulnerability: VulnerabilityDto

/**
* Vulnerabilities setter
*/
var setVulnerability: StateSetter<VulnerabilityDto>

/**
* Callback to fetch updated vulnerability
*/
Expand Down
Loading
Loading