-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
215 additions
and
6 deletions.
There are no files selected for viewing
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
98 changes: 98 additions & 0 deletions
98
assets/frontend/pages/VulnerabilityAnalyses/EditComponent.tsx
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,98 @@ | ||
import { Head, usePage, router } from '@inertiajs/react' | ||
import { useState } from 'react' | ||
import { SeverityOrder, VulnerablityAnalysisJustificationList, VulnerablityAnalysisResponseList, VulnerablityAnalysisStateList } from '../../cyclonedx/models' | ||
import React from 'react' | ||
import "./NewComponent.css"; | ||
|
||
|
||
export default function EditComponent({ vulnerability_analysis, update_url}) { | ||
const { errors } = usePage().props | ||
|
||
const [values, setValues] = useState({ | ||
id: vulnerability_analysis.id, | ||
state: vulnerability_analysis.state, | ||
justification: vulnerability_analysis.justification, | ||
response: vulnerability_analysis.response, | ||
detail: vulnerability_analysis.detail, | ||
adjusted_severity: vulnerability_analysis.adjusted_severity | ||
}); | ||
|
||
function handleChange(e) { | ||
setValues(values => ({ | ||
...values, | ||
[e.target.id]: e.target.value, | ||
})) | ||
} | ||
|
||
function optionsForState() { | ||
return VulnerablityAnalysisStateList.map(vas => <option key={vas} value={vas}>{vas}</option>); | ||
} | ||
|
||
function optionsForJustification() { | ||
return ( | ||
[<option key="nada" value={undefined}>None</option>].concat(VulnerablityAnalysisJustificationList.map(vas => <option key={vas} value={vas}>{vas}</option>)) | ||
); | ||
} | ||
|
||
function optionsForResponse() { | ||
return ( | ||
[<option key="nada" value={undefined}>None</option>].concat(VulnerablityAnalysisResponseList.map(vas => <option key={vas} value={vas}>{vas}</option>)) | ||
); | ||
} | ||
|
||
function optionsForSeverity() { | ||
return ( | ||
[<option key="nada" value={undefined}>None</option>].concat(SeverityOrder.map(vas => <option key={vas} value={vas}>{vas}</option>)) | ||
); | ||
} | ||
|
||
function handleSubmit(e) { | ||
e.preventDefault() | ||
router.put(update_url, values) | ||
} | ||
|
||
return ( | ||
<> | ||
<Head title="Vulnerability Analysis" /> | ||
<h2>{vulnerability_analysis.vulnerability_identifier}</h2> | ||
<form onSubmit={handleSubmit} className="vulnerability-analysis-form-new"> | ||
<div className='form-horizontal'> | ||
<label htmlFor="state"> | ||
State | ||
</label> | ||
<select id="state" name="state" onChange={handleChange} value={values.state}> | ||
{optionsForState()} | ||
</select> | ||
{errors.state && <div className="errors">{errors.state}</div>} | ||
<label htmlFor="justification"> | ||
Justification | ||
</label> | ||
<select id="justification" name="justification" onChange={handleChange} value={values.justification}> | ||
{optionsForJustification()} | ||
</select> | ||
{errors.justification && <div className="errors">{errors.justification}</div>} | ||
<label htmlFor="response"> | ||
Response | ||
</label> | ||
<select id="response" name="response" onChange={handleChange} value={values.response}> | ||
{optionsForResponse()} | ||
</select> | ||
{errors.response && <div className="errors">{errors.response}</div>} | ||
<label htmlFor="adjusted_severity"> | ||
Adjusted Severity | ||
</label> | ||
<select id="adjusted_severity" name="adjusted_severity" onChange={handleChange} value={values.adjusted_severity}> | ||
{optionsForSeverity()} | ||
</select> | ||
{errors.adjusted_severity && <div className="errors">{errors.adjusted_severity}</div>} | ||
<label htmlFor="detail"> | ||
Details | ||
</label> | ||
<textarea id="detail" name="detail" onChange={handleChange} value={values.detail}></textarea> | ||
{errors.detail && <div className="errors">{errors.detail}</div>} | ||
<input type='submit' value="Submit" className="btn btn-primary" /> | ||
</div> | ||
</form> | ||
</> | ||
) | ||
} |
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
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,70 @@ | ||
defmodule Sectory.Builders.EditVulnerabilityAnalysis do | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
|
||
@moduledoc """ | ||
Validate, and update existing analysis data presented by a user. | ||
""" | ||
|
||
schema "sectory_builders.edit_vulnerability_analysis" do | ||
field :state, :string | ||
field :justification, :string | ||
field :response, :string | ||
field :adjusted_severity, :string | ||
field :detail, :string | ||
end | ||
|
||
def changeset(vulnerability_analysis, params \\ %{}) do | ||
vulnerability_analysis | ||
|> cast(params, [ | ||
:state, | ||
:justification, | ||
:response, | ||
:adjusted_severity, | ||
:detail | ||
]) | ||
|> validate_required([ | ||
:detail, | ||
:state, | ||
:adjusted_severity | ||
]) | ||
|> validate_length(:state, min: 1, max: 128) | ||
|> validate_length(:justification, max: 128) | ||
|> validate_length(:response, max: 128) | ||
|> validate_length(:adjusted_severity, max: 128) | ||
|> validate_length(:detail, min: 5) | ||
end | ||
|
||
def edit(params) do | ||
record = Sectory.Repo.get!(Sectory.Records.VulnerabilityAnalysis, params["id"]) | ||
%{ | ||
id: record.id, | ||
state: record.state, | ||
justification: record.justification, | ||
response: record.response, | ||
adjusted_severity: record.adjusted_severity, | ||
detail: record.detail | ||
} | ||
end | ||
|
||
def update(params) do | ||
record = Sectory.Repo.get!(Sectory.Records.VulnerabilityAnalysis, params["id"]) | ||
changeset(record, params) | ||
end | ||
|
||
def save(changeset) do | ||
data = Ecto.Changeset.apply_changes(changeset) | ||
record = Sectory.Repo.get!(Sectory.Records.VulnerabilityAnalysis, data.id) | ||
va_cs = Sectory.Records.VulnerabilityAnalysis.changeset( | ||
record, | ||
%{ | ||
state: data.state, | ||
detail: data.detail, | ||
response: data.response, | ||
adjusted_severity: data.adjusted_severity, | ||
justification: data.justification | ||
} | ||
) | ||
{:ok, _va_record} = Sectory.Repo.update(va_cs) | ||
end | ||
end |
4 changes: 2 additions & 2 deletions
4
...ectory/builders/vulnerability_analysis.ex → ...ry/builders/new_vulnerability_analysis.ex
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
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
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