Skip to content

Commit

Permalink
chore: format
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed-Hacene committed Dec 17, 2024
1 parent 2dd31a2 commit e32776b
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,91 @@


class Migration(migrations.Migration):

dependencies = [
('ebios_rm', '0006_alter_attackpath_stakeholders'),
('iam', '0010_user_preferences'),
("ebios_rm", "0006_alter_attackpath_stakeholders"),
("iam", "0010_user_preferences"),
]

operations = [
migrations.RemoveField(
model_name='attackpath',
name='ro_to_couple',
model_name="attackpath",
name="ro_to_couple",
),
migrations.CreateModel(
name='StrategicScenario',
name="StrategicScenario",
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created at')),
('updated_at', models.DateTimeField(auto_now=True, verbose_name='Updated at')),
('is_published', models.BooleanField(default=False, verbose_name='published')),
('name', models.CharField(max_length=200, verbose_name='Name')),
('description', models.TextField(blank=True, null=True, verbose_name='Description')),
('ref_id', models.CharField(blank=True, max_length=100)),
('ebios_rm_study', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='strategic_scenarios', to='ebios_rm.ebiosrmstudy', verbose_name='EBIOS RM study')),
('folder', models.ForeignKey(default=iam.models.Folder.get_root_folder_id, on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_folder', to='iam.folder')),
('ro_to_couple', models.ForeignKey(help_text='RO/TO couple from which the attach path is derived', on_delete=django.db.models.deletion.CASCADE, to='ebios_rm.roto', verbose_name='RO/TO couple')),
(
"id",
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
(
"created_at",
models.DateTimeField(auto_now_add=True, verbose_name="Created at"),
),
(
"updated_at",
models.DateTimeField(auto_now=True, verbose_name="Updated at"),
),
(
"is_published",
models.BooleanField(default=False, verbose_name="published"),
),
("name", models.CharField(max_length=200, verbose_name="Name")),
(
"description",
models.TextField(blank=True, null=True, verbose_name="Description"),
),
("ref_id", models.CharField(blank=True, max_length=100)),
(
"ebios_rm_study",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="strategic_scenarios",
to="ebios_rm.ebiosrmstudy",
verbose_name="EBIOS RM study",
),
),
(
"folder",
models.ForeignKey(
default=iam.models.Folder.get_root_folder_id,
on_delete=django.db.models.deletion.CASCADE,
related_name="%(class)s_folder",
to="iam.folder",
),
),
(
"ro_to_couple",
models.ForeignKey(
help_text="RO/TO couple from which the attach path is derived",
on_delete=django.db.models.deletion.CASCADE,
to="ebios_rm.roto",
verbose_name="RO/TO couple",
),
),
],
options={
'verbose_name': 'Strategic Scenario',
'verbose_name_plural': 'Strategic Scenarios',
'ordering': ['created_at'],
"verbose_name": "Strategic Scenario",
"verbose_name_plural": "Strategic Scenarios",
"ordering": ["created_at"],
},
),
migrations.AddField(
model_name='attackpath',
name='strategic_scenario',
field=models.ForeignKey(default='', help_text='Strategic scenario from which the attack path is derived', on_delete=django.db.models.deletion.CASCADE, related_name='attack_paths', to='ebios_rm.strategicscenario', verbose_name='Strategic scenario'),
model_name="attackpath",
name="strategic_scenario",
field=models.ForeignKey(
default="",
help_text="Strategic scenario from which the attack path is derived",
on_delete=django.db.models.deletion.CASCADE,
related_name="attack_paths",
to="ebios_rm.strategicscenario",
verbose_name="Strategic scenario",
),
preserve_default=False,
),
]
6 changes: 3 additions & 3 deletions backend/ebios_rm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,12 @@ class StrategicScenario(NameDescriptionMixin, FolderMixin):
help_text=_("RO/TO couple from which the attach path is derived"),
)
ref_id = models.CharField(max_length=100, blank=True)

class Meta:
verbose_name = _("Strategic Scenario")
verbose_name_plural = _("Strategic Scenarios")
ordering = ["created_at"]

def save(self, *args, **kwargs):
self.folder = self.ebios_rm_study.folder
super().save(*args, **kwargs)
Expand Down Expand Up @@ -433,7 +433,7 @@ def save(self, *args, **kwargs):
self.ebios_rm_study = self.strategic_scenario.ebios_rm_study
self.folder = self.ebios_rm_study.folder
super().save(*args, **kwargs)

@property
def ro_to_couple(self):
return self.strategic_scenario.ro_to_couple
Expand Down
4 changes: 3 additions & 1 deletion backend/ebios_rm/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
router.register(r"feared-events", FearedEventViewSet, basename="feared-events")
router.register(r"ro-to", RoToViewSet, basename="ro-to")
router.register(r"stakeholders", StakeholderViewSet, basename="stakeholders")
router.register(r"strategic-scenarios", StrategicScenarioViewSet, basename="strategic-scenarios")
router.register(
r"strategic-scenarios", StrategicScenarioViewSet, basename="strategic-scenarios"
)
router.register(r"attack-paths", AttackPathViewSet, basename="attack-paths")
router.register(
r"operational-scenarios",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
export let cacheLocks: Record<string, CacheLock> = {};
export let formDataCache: Record<string, any> = {};
export let initialData: Record<string, any> = {};
export let context: string;
export let context: string;
</script>

{#if context !== 'edit'}
<AutocompleteSelect
{form}
options={getOptions({ objects: model.foreignKeys['ro_to_couple'], label: 'str' })}
field="ro_to_couple"
cacheLock={cacheLocks['ro_to_couple']}
bind:cachedValue={formDataCache['ro_to_couple']}
label={m.roToCouple()}
hidden={initialData.ro_to_couple}
/>
<AutocompleteSelect
{form}
options={getOptions({ objects: model.foreignKeys['ro_to_couple'], label: 'str' })}
field="ro_to_couple"
cacheLock={cacheLocks['ro_to_couple']}
bind:cachedValue={formDataCache['ro_to_couple']}
label={m.roToCouple()}
hidden={initialData.ro_to_couple}
/>
{/if}
<TextField
{form}
Expand Down
24 changes: 21 additions & 3 deletions frontend/src/lib/utils/crud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -678,10 +678,22 @@ export const URL_MODEL_MAP: ModelMap = {
verboseNamePlural: 'Strategic scenarios',
foreignKeyFields: [
{ field: 'ebios_rm_study', urlModel: 'ebios-rm', endpointUrl: 'ebios-rm/studies' },
{ field: 'ro_to_couple', urlModel: 'ro-to', endpointUrl: 'ebios-rm/ro-to', urlParams: 'ebios_rm_study=', detail: true },
{
field: 'ro_to_couple',
urlModel: 'ro-to',
endpointUrl: 'ebios-rm/ro-to',
urlParams: 'ebios_rm_study=',
detail: true
},
{ field: 'folder', urlModel: 'folders', urlParams: 'content_type=DO' }
],
reverseForeignKeyFields: [{ field: 'strategic_scenario', urlModel: 'attack-paths', endpointUrl: 'ebios-rm/attack-paths' }],
reverseForeignKeyFields: [
{
field: 'strategic_scenario',
urlModel: 'attack-paths',
endpointUrl: 'ebios-rm/attack-paths'
}
]
},
'attack-paths': {
endpointUrl: 'ebios-rm/attack-paths',
Expand All @@ -694,7 +706,13 @@ export const URL_MODEL_MAP: ModelMap = {
{ field: 'stakeholders', urlModel: 'stakeholders', endpointUrl: 'ebios-rm/stakeholders' },
{ field: 'ebios_rm_study', urlModel: 'ebios-rm', endpointUrl: 'ebios-rm/studies' },
{ field: 'folder', urlModel: 'folders', urlParams: 'content_type=DO' },
{ field: 'strategic_scenario', urlModel: 'strategic-scenarios', endpointUrl: 'ebios-rm/strategic-scenarios', urlParams: 'ebios_rm_study=', detail: true }
{
field: 'strategic_scenario',
urlModel: 'strategic-scenarios',
endpointUrl: 'ebios-rm/strategic-scenarios',
urlParams: 'ebios_rm_study=',
detail: true
}
]
},
'operational-scenarios': {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/lib/utils/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,8 @@ export const StakeholderSchema = z.object({
export const StrategicScenarioSchema = z.object({
...NameDescriptionMixin,
ro_to_couple: z.string().uuid(),
ref_id: z.string().optional(),
})
ref_id: z.string().optional()
});

export const AttackPathSchema = z.object({
...NameDescriptionMixin,
Expand Down

0 comments on commit e32776b

Please sign in to comment.