Skip to content

Commit

Permalink
Merge branch 'CA-674-Step-1.4' of github.com:intuitem/ciso-assistant-…
Browse files Browse the repository at this point in the history
…community into CA-674-Step-1.4
  • Loading branch information
Mohamed-Hacene committed Dec 6, 2024
2 parents 1bfca6e + 4db984a commit 76f84ef
Show file tree
Hide file tree
Showing 21 changed files with 61 additions and 22 deletions.
8 changes: 8 additions & 0 deletions backend/ebios_rm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ def save(self, *args, **kwargs):
self.folder = self.ebios_rm_study.folder
super().save(*args, **kwargs)

@property
def risk_matrix(self):
return self.ebios_rm_study.risk_matrix

@property
def parsed_matrix(self):
return self.risk_matrix.parse_json_translated()


class RoTo(AbstractBaseModel, FolderMixin):
class RiskOrigin(models.TextChoices):
Expand Down
20 changes: 20 additions & 0 deletions backend/ebios_rm/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from core.serializers import RiskMatrixReadSerializer
from core.views import BaseModelViewSet as AbstractBaseModelViewSet
from .models import (
EbiosRMStudy,
Expand Down Expand Up @@ -39,6 +40,25 @@ class FearedEventViewSet(BaseModelViewSet):
"ebios_rm_study",
]

@action(detail=True, name="Get risk matrix", url_path="risk-matrix")
def risk_matrix(self, request, pk=None):
feared_event = self.get_object()
return Response(RiskMatrixReadSerializer(feared_event.risk_matrix).data)

@method_decorator(cache_page(60 * LONG_CACHE_TTL))
@action(detail=True, name="Get gravity choices")
def gravity(self, request, pk):
feared_event: FearedEvent = self.get_object()
undefined = dict([(-1, "--")])
_choices = dict(
zip(
list(range(0, 64)),
[x["name"] for x in feared_event.parsed_matrix["impact"]],
)
)
choices = undefined | _choices
return Response(choices)


class RoToViewSet(BaseModelViewSet):
model = RoTo
Expand Down
3 changes: 2 additions & 1 deletion frontend/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -929,5 +929,6 @@
"impacts": "Impacts",
"ebiosRmStudies": "Ebios RM studies",
"bringTheEvidences": "Bring the evidences",
"bringTheEvidencesHelpText": "If disabled, the object will be duplicated without its evidences"
"bringTheEvidencesHelpText": "If disabled, the object will be duplicated without its evidences",
"gravity": "Gravity"
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@
cacheLock={cacheLocks['ref_id']}
bind:cachedValue={formDataCache['ref_id']}
/>
<Select
{form}
options={model.selectOptions['gravity']}
field="gravity"
label={m.gravity()}
cacheLock={cacheLocks['gravity']}
bind:cachedValue={formDataCache['gravity']}
/>
<TextArea
{form}
field="justification"
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/lib/utils/crud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ interface Field {
interface SelectField {
field: string;
detail?: boolean;
valueType?: 'string' | 'number';
}

export interface ModelMapEntry {
Expand Down Expand Up @@ -620,7 +621,8 @@ export const URL_MODEL_MAP: ModelMap = {
{ field: 'ebios_rm_study', urlModel: 'ebios-rm' },
{ field: 'assets', urlModel: 'assets' },
{ field: 'qualifications', urlModel: 'qualifications' }
]
],
selectFields: [{ field: 'gravity', valueType: 'number', detail: true }]
}
};

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/utils/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const loadDetail = async ({ event, model, id }) => {
selectOptions[selectField.field] = await response.json().then((data) =>
Object.entries(data).map(([key, value]) => ({
label: value,
value: key
value: selectField.valueType === 'number' ? parseInt(key) : key
}))
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const load: PageServerLoad = async ({ params, fetch }) => {
selectOptions[selectField.field] = await response.json().then((data) =>
Object.entries(data).map(([key, value]) => ({
label: value,
value: key
value: selectField.valueType === 'number' ? parseInt(key) : key
}))
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ export const load: LayoutServerLoad = async (event) => {

if (selectFields) {
for (const selectField of selectFields) {
const url = `${BASE_API_URL}/${event.params.model}/${
const url = `${BASE_API_URL}/${model.endpointUrl ?? event.params.model}/${
selectField.detail ? event.params.id + '/' : ''
}${selectField.field}/`;
const response = await event.fetch(url);
if (response.ok) {
selectOptions[selectField.field] = await response.json().then((data) =>
Object.entries(data).map(([key, value]) => ({
label: value,
value: key
value: selectField.valueType === 'number' ? parseInt(key) : key
}))
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const load: PageServerLoad = async ({ params, fetch }) => {
selectOptions[selectField.field] = await response.json().then((data) =>
Object.entries(data).map(([key, value]) => ({
label: value,
value: key
value: selectField.valueType === 'number' ? parseInt(key) : key
}))
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
{
title: safeTranslate(m.ebiosWs1_4()),
status: 'to_do',
href: `${$page.url.pathname}/workshop-one/base?next=${$page.url.pathname}`
href: `${$page.url.pathname}/workshop-one/baseline?next=${$page.url.pathname}`
}
],
ws2: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const load: PageServerLoad = async ({ params, fetch }) => {
selectOptions[selectField.field] = await response.json().then((data) =>
Object.entries(data).map(([key, value]) => ({
label: value,
value: key
value: selectField.valueType === 'number' ? parseInt(key) : key
}))
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const load: PageServerLoad = async (event) => {
selectOptions[selectField.field] = await response.json().then((data) =>
Object.entries(data).map(([key, value]) => ({
label: value,
value: key
value: selectField.valueType === 'number' ? parseInt(key) : key
}))
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const load: LayoutServerLoad = async ({ fetch, params }) => {
selectOptions[selectField.field] = await response.json().then((data) =>
Object.entries(data).map(([key, value]) => ({
label: value,
value: key
value: selectField.valueType === 'number' ? parseInt(key) : key
}))
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const load: LayoutServerLoad = async ({ fetch, params }) => {
selectOptions[selectField.field] = await response.json().then((data) =>
Object.entries(data).map(([key, value]) => ({
label: value,
value: key
value: selectField.valueType === 'number' ? parseInt(key) : key
}))
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const load: PageServerLoad = async ({ params, fetch }) => {
selectOptions[selectField.field] = await response.json().then((data) =>
Object.entries(data).map(([key, value]) => ({
label: value,
value: key
value: selectField.valueType === 'number' ? parseInt(key) : key
}))
);
} else {
Expand Down Expand Up @@ -152,7 +152,7 @@ export const load: PageServerLoad = async ({ params, fetch }) => {
measureSelectOptions[selectField.field] = await response.json().then((data) =>
Object.entries(data).map(([key, value]) => ({
label: value,
value: key
value: selectField.valueType === 'number' ? parseInt(key) : key
}))
);
} else {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/routes/(app)/(internal)/settings/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const load: PageServerLoad = async ({ fetch }) => {
selectOptions[selectField.field] = await response.json().then((data) =>
Object.entries(data).map(([key, value]) => ({
label: value,
value: key
value: selectField.valueType === 'number' ? parseInt(key) : key
}))
);
} else {
Expand All @@ -47,7 +47,7 @@ export const load: PageServerLoad = async ({ fetch }) => {
selectOptions[selectField.field] = await response.json().then((data) =>
Object.entries(data).map(([key, value]) => ({
label: value,
value: key
value: selectField.valueType === 'number' ? parseInt(key) : key
}))
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const load: PageServerLoad = async ({ params, fetch }) => {
selectOptions[selectField.field] = await response.json().then((data) =>
Object.entries(data).map(([key, value]) => ({
label: value,
value: key
value: selectField.valueType === 'number' ? parseInt(key) : key
}))
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const load: LayoutServerLoad = async (event) => {
selectOptions[selectField.field] = await response.json().then((data) =>
Object.entries(data).map(([key, value]) => ({
label: value,
value: key
value: selectField.valueType === 'number' ? parseInt(key) : key
}))
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const load = (async ({ fetch, params }) => {
selectOptions[selectField.field] = await response.json().then((data) =>
Object.entries(data).map(([key, value]) => ({
label: value,
value: key
value: selectField.valueType === 'number' ? parseInt(key) : key
}))
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const load = (async ({ fetch, params }) => {
if (data) {
selectOptions[selectField.field] = Object.entries(data).map(([key, value]) => ({
label: value,
value: key
value: selectField.valueType === 'number' ? parseInt(key) : key
}));
}
})
Expand All @@ -98,7 +98,7 @@ export const load = (async ({ fetch, params }) => {
if (data) {
measureSelectOptions[selectField.field] = Object.entries(data).map(([key, value]) => ({
label: value,
value: key
value: selectField.valueType === 'number' ? parseInt(key) : key
}));
} else {
console.error(`Failed to fetch data for ${selectField.field}: ${response.statusText}`);
Expand Down Expand Up @@ -169,7 +169,7 @@ export const load = (async ({ fetch, params }) => {
if (data) {
evidenceSelectOptions[selectField.field] = Object.entries(data).map(([key, value]) => ({
label: value,
value: key
value: selectField.valueType === 'number' ? parseInt(key) : key
}));
}
})
Expand Down

0 comments on commit 76f84ef

Please sign in to comment.