diff --git a/backend/ebios_rm/serializers.py b/backend/ebios_rm/serializers.py index 462a35d75..e77c5c153 100644 --- a/backend/ebios_rm/serializers.py +++ b/backend/ebios_rm/serializers.py @@ -3,7 +3,14 @@ FieldsRelatedField, ) from core.models import StoredLibrary, RiskMatrix -from .models import EbiosRMStudy, FearedEvent, RoTo, Stakeholder, AttackPath +from .models import ( + EbiosRMStudy, + FearedEvent, + RoTo, + Stakeholder, + AttackPath, + OperationalScenario, +) from rest_framework import serializers import logging @@ -130,3 +137,21 @@ class AttackPathReadSerializer(BaseModelSerializer): class Meta: model = AttackPath fields = "__all__" + + +class OperationalScenarioWriteSerializer(BaseModelSerializer): + class Meta: + model = OperationalScenario + exclude = ["created_at", "updated_at", "folder"] + + +class OperationalScenarioReadSerializer(BaseModelSerializer): + str = serializers.CharField(source="__str__") + ebios_rm_study = FieldsRelatedField() + folder = FieldsRelatedField() + attack_paths = FieldsRelatedField(many=True) + threats = FieldsRelatedField(many=True) + + class Meta: + model = OperationalScenario + fields = "__all__" diff --git a/backend/ebios_rm/urls.py b/backend/ebios_rm/urls.py index 8214b799e..76f7b3e2e 100644 --- a/backend/ebios_rm/urls.py +++ b/backend/ebios_rm/urls.py @@ -7,6 +7,7 @@ RoToViewSet, StakeholderViewSet, AttackPathViewSet, + OperationalScenarioViewSet, ) router = routers.DefaultRouter() @@ -16,6 +17,11 @@ router.register(r"ro-to", RoToViewSet, basename="ro-to") router.register(r"stakeholders", StakeholderViewSet, basename="stakeholders") router.register(r"attack-paths", AttackPathViewSet, basename="attack-paths") +router.register( + r"operational-scenarios", + OperationalScenarioViewSet, + basename="operational-scenarios", +) urlpatterns = [ path("", include(router.urls)), diff --git a/backend/ebios_rm/views.py b/backend/ebios_rm/views.py index 6237f6c86..ca0d048dd 100644 --- a/backend/ebios_rm/views.py +++ b/backend/ebios_rm/views.py @@ -1,5 +1,12 @@ from core.views import BaseModelViewSet as AbstractBaseModelViewSet -from .models import EbiosRMStudy, FearedEvent, RoTo, Stakeholder, AttackPath +from .models import ( + EbiosRMStudy, + FearedEvent, + RoTo, + Stakeholder, + AttackPath, + OperationalScenario, +) from django.utils.decorators import method_decorator from django.views.decorators.cache import cache_page from rest_framework.decorators import action @@ -59,3 +66,7 @@ def category(self, request): class AttackPathViewSet(BaseModelViewSet): model = AttackPath + + +class OperationalScenarioViewSet(BaseModelViewSet): + model = OperationalScenario