Skip to content

Commit

Permalink
feat: add activity choices
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed-Hacene committed Dec 20, 2024
1 parent b4abf53 commit 1dff57d
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 12 deletions.
19 changes: 19 additions & 0 deletions backend/ebios_rm/migrations/0009_alter_roto_activity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 5.1.4 on 2024-12-20 12:16

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('ebios_rm', '0008_remove_attackpath_ro_to_couple_strategicscenario_and_more'),
]

operations = [
migrations.AlterField(
model_name='roto',
name='activity',
field=models.PositiveSmallIntegerField(choices=[(0, 'undefined'), (1, 'very_low'), (2, 'low'), (3, 'moderate'), (4, 'important')], default=0, validators=[django.core.validators.MaxValueValidator(4)], verbose_name='Activity'),
),
]
12 changes: 11 additions & 1 deletion backend/ebios_rm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,13 @@ class Resources(models.IntegerChoices):
IMPORTANT = 3, "important"
UNLIMITED = 4, "unlimited"

class Activity(models.IntegerChoices):
UNDEFINED = 0, "undefined"
VERY_LOW = 1, "very_low"
LOW = 2, "low"
MODERATE = 3, "moderate"
IMPORTANT = 4, "important"

class Pertinence(models.IntegerChoices):
UNDEFINED = 0, "undefined"
IRRELAVANT = 1, "irrelevant"
Expand Down Expand Up @@ -306,7 +313,10 @@ class Pertinence(models.IntegerChoices):
default=Resources.UNDEFINED,
)
activity = models.PositiveSmallIntegerField(
verbose_name=_("Activity"), default=0, validators=[MaxValueValidator(4)]
verbose_name=_("Activity"),
choices=Activity.choices,
default=Activity.UNDEFINED,
validators=[MaxValueValidator(4)],
)
is_selected = models.BooleanField(verbose_name=_("Is selected"), default=False)
justification = models.TextField(verbose_name=_("Justification"), blank=True)
Expand Down
1 change: 1 addition & 0 deletions backend/ebios_rm/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class RoToReadSerializer(BaseModelSerializer):

motivation = serializers.CharField(source="get_motivation_display")
resources = serializers.CharField(source="get_resources_display")
activity = serializers.CharField(source="get_activity_display")
pertinence = serializers.CharField(source="get_pertinence")

class Meta:
Expand Down
4 changes: 4 additions & 0 deletions backend/ebios_rm/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ def motivation(self, request):
@action(detail=False, name="Get resources choices")
def resources(self, request):
return Response(dict(RoTo.Resources.choices))

@action(detail=False, name="Get activity choices")
def activity(self, request):
return Response(dict(RoTo.Activity.choices))


class StakeholderViewSet(BaseModelViewSet):
Expand Down
11 changes: 2 additions & 9 deletions frontend/src/lib/components/Forms/ModelForm/RoToForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,9 @@
cacheLock={cacheLocks['resources']}
bind:cachedValue={formDataCache['resources']}
/>
<!-- <Select
{form}
options={model.selectOptions['pertinence']}
field="pertinence"
label={m.pertinence()}
cacheLock={cacheLocks['pertinence']}
bind:cachedValue={formDataCache['pertinence']}
/> -->
<NumberField
<Select
{form}
options={model.selectOptions['activity']}
field="activity"
label={m.activity()}
cacheLock={cacheLocks['activity']}
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/lib/utils/crud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,8 @@ export const URL_MODEL_MAP: ModelMap = {
selectFields: [
{ field: 'risk-origin' },
{ field: 'motivation', valueType: 'number' },
{ field: 'resources', valueType: 'number' }
{ field: 'resources', valueType: 'number' },
{ field: 'activity', valueType: 'number' },
]
},
stakeholders: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<p>
<span class="badge bg-violet-200 text-violet-700">{m.activity()}</span>
<span>=</span>
<span class="font-bold">{roto.activity}</span>
<span class="font-bold">{safeTranslate(roto.activity)}</span>
</p>
</div>
<div
Expand Down

0 comments on commit 1dff57d

Please sign in to comment.