Skip to content

Commit

Permalink
feat: change operational scenario/attack path relationship
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed-Hacene committed Dec 16, 2024
1 parent 293070b commit 2fb6202
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
9 changes: 5 additions & 4 deletions backend/ebios_rm/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,13 @@ class Migration(migrations.Migration):
models.TextField(blank=True, verbose_name="Justification"),
),
(
"attack_paths",
models.ManyToManyField(
help_text="Attack paths that are pertinent to the operational scenario",
related_name="operational_scenarios",
"attack_path",
models.OneToOneField(
help_text="Attack path that is pertinent to the operational scenario",
related_name="operational_scenario",
to="ebios_rm.attackpath",
verbose_name="Attack paths",
on_delete=django.db.models.deletion.CASCADE,
),
),
(
Expand Down
14 changes: 6 additions & 8 deletions backend/ebios_rm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,11 +418,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"),
related_name="operational_scenario",
help_text=_("Attack path that is pertinent to the operational scenario"),
on_delete=models.CASCADE,
)
threats = models.ManyToManyField(
Threat,
Expand Down Expand Up @@ -465,11 +466,7 @@ def ref_id(self):

@property
def gravity(self):
gravity = -1
for attack_path in self.attack_paths.all():
if attack_path.gravity > gravity:
gravity = attack_path.gravity
return gravity
return self.attack_path.gravity

def get_likelihood_display(self):
if self.likelihood < 0:
Expand All @@ -478,6 +475,7 @@ def get_likelihood_display(self):
"name": "--",
"description": "not rated",
"value": -1,
"hexcolor": "#f9fafb",
}
risk_matrix = self.parsed_matrix
return {
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")
gravity = serializers.JSONField(source="get_gravity_display")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,17 @@
bind:cachedValue={formDataCache['threats']}
label={m.threats()}
/>
<AutocompleteSelect
multiple
{form}
options={getOptions({
objects: model.foreignKeys['attack_paths'],
label: 'str'
})}
field="attack_paths"
label={m.attackPaths()}
/>
{#if context !== 'edit'}
<AutocompleteSelect
{form}
options={getOptions({
objects: model.foreignKeys['attack_path'],
label: 'str'
})}
field="attack_path"
label={m.attackPath()}
/>
{/if}
</div>
<div
class="relative p-2 space-y-2 rounded-md {activeActivity === 'two'
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 @@ -693,7 +693,7 @@ export const URL_MODEL_MAP: ModelMap = {
{ field: 'ebios_rm_study', urlModel: 'ebios-rm' },
{ field: 'threats', urlModel: 'threats' },
{
field: 'attack_paths',
field: 'attack_path',
urlModel: 'attack-paths',
endpointUrl: 'ebios-rm/attack-paths',
urlParams: 'ebios_rm_study=',
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
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
<div class="w-full p-4 bg-gray-50 border rounded-md shadow-sm">
<h3 class="font-semibold text-lg text-gray-700 flex items-center space-x-2">
<i class="fa-solid fa-table text-gray-500 opacity-75"></i>
<span>{m.attackPaths()}</span>
<span>{m.attackPath()}</span>
</h3>
<ModelTable
backgroundColor="bg-gray-50"
Expand Down

0 comments on commit 2fb6202

Please sign in to comment.