Skip to content

Commit

Permalink
fix: set catalog ids on imports for comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
somehowchris committed Oct 29, 2024
1 parent 47dd71d commit 6a06cd7
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/riskmatrix/scripts/seantis_import_risk_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def parse_args(argv: list[str]) -> argparse.Namespace:
def get_or_create_asset(
asset_name: str,
organization: Organization,
risk_catalog: RiskCatalog,
session: 'Session'
) -> Asset:

Expand All @@ -77,8 +78,10 @@ def get_or_create_asset(
if asset := session.scalars(q).one_or_none():
return asset

asset = Asset(asset_name, organization)
asset = Asset(asset_name, organization, meta={"catalogs": [risk_catalog.id]})
asset.organization_id = organization.id
asset.meta = {"catalogs": [risk_catalog.id]}

session.add(asset)
return asset

Expand Down Expand Up @@ -151,7 +154,7 @@ def populate_catalog(

for risk_details in risks:
asset = get_or_create_asset(
risk_details['asset_name'], catalog.organization, session
risk_details['asset_name'], catalog.organization, catalog, session
)

risk = get_or_create_risk(
Expand Down
1 change: 1 addition & 0 deletions src/riskmatrix/views/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ def assets_view(
data_table_id=table.id,
)],
'edit_form': AssetForm(context, request),
"helper_text": Markup("Assets can be attached to multiple Risk catalogs, looking to manage your <a href=\"/risk_catalog\">risks</a>? Are you ready for your <a href=\"/assessment\">assessment</a>?")
}


Expand Down
9 changes: 7 additions & 2 deletions src/riskmatrix/views/risk_assessment.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ def compare_assessments_view(context: "Organization", request: "IRequest") -> "R
risk.diff_impact = (risk.impact - comp_risk.impact)
else:
risk.diff_impact = None
else:
risk.diff_likelihood = None
risk.diff_impact = None

comp_table = AssessmentComparisonTable(context, request, all_risks)

Expand Down Expand Up @@ -159,7 +162,7 @@ def total_records(self) -> int:
def query(self) -> "Query[RiskAssessment]":
session = self.request.dbsession
query = session.query(RiskAssessmentInfo)
query = query.order_by(RiskAssessmentInfo.created.desc())
query = query.order_by(RiskAssessmentInfo.created.asc())
return query

def current_open_assessment(self) -> RiskAssessmentInfo | None:
Expand All @@ -184,7 +187,7 @@ def buttons(self, assessment: RiskAssessmentInfo | None = None) -> list[Button]:
]
class AssessmentBaseTable(AJAXDataTable[RiskAssessment]):
default_options = {
"length_menu": [[25, 50, 100, -1], [25, 50, 100, "All"]],
"length_menu": [[-1], ["All"]],
"order": [[0, "asc"]], # corresponds to column name
}

Expand Down Expand Up @@ -606,6 +609,8 @@ def finish_risk_assessment_view(context: "Organization", request: "IRequest") ->

# add a riskassessment object per risk and asset to the new assessment info object
for asset in context.assets:
print("asset", asset.id)
print("catalog_ids", asset.catalog_ids)
for risk_catalog in [cat for cat in context.risk_catalogs if cat.id in asset.catalog_ids]:
for risk in risk_catalog.risks:
new_risk_assessment = RiskAssessment(
Expand Down
3 changes: 2 additions & 1 deletion src/riskmatrix/views/risk_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ def risk_catalog_view(
data_table_id=table.id,
)],
'edit_form': RiskCatalogForm(None, request),
'generate_form': RiskCatalogGenerationForm(None, request)
'generate_form': RiskCatalogGenerationForm(None, request),
'helper_text': Markup("Risk catalogs are collections of risks to be combined with multiple different assets, looking for <a href=\"/assets\">assets</a>?")
}


Expand Down
5 changes: 4 additions & 1 deletion src/riskmatrix/views/templates/compare.pt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
</div>
</div>
<div class="col col-6">
<h5 style="margin-left:2px; color: #ADADAD; font-weight: 800; font-style: italic; font-family: serif; margin-bottom: 0px;">${comparison_assessment.name} (${comparison_assessment.finished_at})</h5>
<h5 style="margin-left:2px; color: #ADADAD; font-weight: 800; font-style: italic; font-family: serif; margin-bottom: 0px;">
${comparison_assessment.name} (${comparison_assessment.finished_at.strftime('%d.%m.%Y %H:%M')})
</h5>

<br/>
<div style="width: 100%">
${right_plot}
Expand Down
8 changes: 8 additions & 0 deletions src/riskmatrix/views/templates/table.pt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@
<tal:block metal:fill-slot="content">

<h5 tal:condition="exists:supertitle" style="margin-left:2px; color: #ADADAD; font-weight: 800; font-style: italic; font-family: serif; margin-bottom: 0px;">${supertitle}</h5>

<h1>${title}</h1>
<h6 tal:condition="exists:helper_text" style="margin-left:0px; color: #0d6efdBB; font-weight: 800; font-style: italic; font-family: serif; margin-bottom: 4px;margin-top:-16px">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" class="bi bi-info" viewBox="0 0 17 17">
<path d="M14 1a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1zM2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2z"/>
<path d="m8.93 6.588-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.808 1.319.545 0 1.178-.252 1.465-.598l.088-.416c-.2.176-.492.246-.686.246-.275 0-.375-.193-.304-.533zM9 4.5a1 1 0 1 1-2 0 1 1 0 0 1 2 0"/>
</svg>
${helper_text}
</h6>

<p tal:condition="exists:description" style="color: #5C5C5C;">${description}</p>

Expand Down

0 comments on commit 6a06cd7

Please sign in to comment.