Skip to content

Commit

Permalink
Update AttackPath and OperationalScenario models (#1196)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed-Hacene authored Dec 16, 2024
2 parents 711daf5 + f9c769b commit 3ae5fc6
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Generated by Django 5.1.4 on 2024-12-16 11:59

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("ebios_rm", "0004_remove_roto_pertinence_alter_roto_feared_events"),
]

operations = [
migrations.RemoveField(
model_name="operationalscenario",
name="attack_paths",
),
migrations.RemoveField(
model_name="operationalscenario",
name="description",
),
migrations.AddField(
model_name="attackpath",
name="name",
field=models.CharField(default="", max_length=200, verbose_name="Name"),
preserve_default=False,
),
migrations.AddField(
model_name="attackpath",
name="ref_id",
field=models.CharField(blank=True, max_length=100),
),
migrations.AddField(
model_name="operationalscenario",
name="attack_path",
field=models.OneToOneField(
default="",
on_delete=django.db.models.deletion.CASCADE,
related_name="operational_scenario",
to="ebios_rm.attackpath",
verbose_name="Attack path",
),
preserve_default=False,
),
migrations.AddField(
model_name="operationalscenario",
name="operating_modes_description",
field=models.TextField(
default="",
help_text="Description of the operating modes of the operational scenario",
verbose_name="Operating modes description",
),
preserve_default=False,
),
migrations.AlterField(
model_name="attackpath",
name="description",
field=models.TextField(blank=True, null=True, verbose_name="Description"),
),
]
18 changes: 11 additions & 7 deletions backend/ebios_rm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def residual_criticality(self):
)


class AttackPath(AbstractBaseModel, FolderMixin):
class AttackPath(NameDescriptionMixin, FolderMixin):
ebios_rm_study = models.ForeignKey(
EbiosRMStudy,
verbose_name=_("EBIOS RM study"),
Expand All @@ -382,7 +382,7 @@ class AttackPath(AbstractBaseModel, FolderMixin):
help_text=_("Stakeholders leveraged by the attack path"),
)

description = models.TextField(verbose_name=_("Description"))
ref_id = models.CharField(max_length=100, blank=True)
is_selected = models.BooleanField(verbose_name=_("Is selected"), default=False)
justification = models.TextField(verbose_name=_("Justification"), blank=True)

Expand All @@ -406,11 +406,12 @@ class OperationalScenario(AbstractBaseModel, FolderMixin):
related_name="operational_scenarios",
on_delete=models.CASCADE,
)
attack_paths = models.ManyToManyField(
attack_path = models.OneToOneField(
AttackPath,
verbose_name=_("Attack paths"),
related_name="operational_scenarios",
help_text=_("Attack paths that are pertinent to the operational scenario"),
verbose_name=_("Attack path"),
on_delete=models.CASCADE,
related_name="operational_scenario",
blank=False,
)
threats = models.ManyToManyField(
Threat,
Expand All @@ -420,7 +421,10 @@ class OperationalScenario(AbstractBaseModel, FolderMixin):
help_text=_("Threats leveraged by the operational scenario"),
)

description = models.TextField(verbose_name=_("Description"))
operating_modes_description = models.TextField(
verbose_name=_("Operating modes description"),
help_text=_("Description of the operating modes of the operational scenario"),
)
likelihood = models.SmallIntegerField(default=-1, verbose_name=_("Likelihood"))
is_selected = models.BooleanField(verbose_name=_("Is selected"), default=False)
justification = models.TextField(verbose_name=_("Justification"), blank=True)
Expand Down
2 changes: 1 addition & 1 deletion backend/ebios_rm/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class OperationalScenarioReadSerializer(BaseModelSerializer):
str = serializers.CharField(source="__str__")
ebios_rm_study = FieldsRelatedField()
folder = FieldsRelatedField()
attack_paths = FieldsRelatedField(many=True)
attack_path = FieldsRelatedField()
threats = FieldsRelatedField(many=True)
likelihood = serializers.JSONField(source="get_likelihood_display")

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/utils/crud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ export const URL_MODEL_MAP: ModelMap = {
foreignKeyFields: [
{ field: 'ebios_rm_study', urlModel: 'ebios-rm' },
{ field: 'threats', urlModel: 'threats' },
{ field: 'attack_paths', urlModel: 'attack-paths' }
{ field: 'attack_path', urlModel: 'attack-paths' }
],
selectFields: [{ field: 'likelihood', valueType: 'number' }]
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/utils/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ export const AttackPathSchema = z.object({

export const operationalScenarioSchema = z.object({
ebios_rm_study: z.string(),
attack_paths: z.string().uuid().array(),
attack_path: z.string().uuid(),
threats: z.string().uuid().optional().array().optional(),
description: z.string(),
likelihood: z.number().optional().default(-1),
Expand Down

0 comments on commit 3ae5fc6

Please sign in to comment.