From d7091197404810f43b4faaec3a0995fa919f52fd Mon Sep 17 00:00:00 2001 From: Nassim Tabchiche Date: Wed, 4 Dec 2024 15:45:10 +0100 Subject: [PATCH] Create AttackPath endpoints --- backend/ebios_rm/serializers.py | 20 +++++++++++++++++++- backend/ebios_rm/urls.py | 2 ++ backend/ebios_rm/views.py | 6 +++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/backend/ebios_rm/serializers.py b/backend/ebios_rm/serializers.py index f60204853..462a35d75 100644 --- a/backend/ebios_rm/serializers.py +++ b/backend/ebios_rm/serializers.py @@ -3,7 +3,7 @@ FieldsRelatedField, ) from core.models import StoredLibrary, RiskMatrix -from .models import EbiosRMStudy, FearedEvent, RoTo, Stakeholder +from .models import EbiosRMStudy, FearedEvent, RoTo, Stakeholder, AttackPath from rest_framework import serializers import logging @@ -112,3 +112,21 @@ class StakeholderReadSerializer(BaseModelSerializer): class Meta: model = Stakeholder fields = "__all__" + + +class AttackPathWriteSerializer(BaseModelSerializer): + class Meta: + model = AttackPath + exclude = ["created_at", "updated_at", "folder"] + + +class AttackPathReadSerializer(BaseModelSerializer): + str = serializers.CharField(source="__str__") + ebios_rm_study = FieldsRelatedField() + folder = FieldsRelatedField() + ro_to_couple = FieldsRelatedField() + stakeholders = FieldsRelatedField(many=True) + + class Meta: + model = AttackPath + fields = "__all__" diff --git a/backend/ebios_rm/urls.py b/backend/ebios_rm/urls.py index 9e5ec6454..8214b799e 100644 --- a/backend/ebios_rm/urls.py +++ b/backend/ebios_rm/urls.py @@ -6,6 +6,7 @@ FearedEventViewSet, RoToViewSet, StakeholderViewSet, + AttackPathViewSet, ) router = routers.DefaultRouter() @@ -14,6 +15,7 @@ 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"attack-paths", AttackPathViewSet, basename="attack-paths") urlpatterns = [ path("", include(router.urls)), diff --git a/backend/ebios_rm/views.py b/backend/ebios_rm/views.py index f7e01ddaf..6237f6c86 100644 --- a/backend/ebios_rm/views.py +++ b/backend/ebios_rm/views.py @@ -1,5 +1,5 @@ from core.views import BaseModelViewSet as AbstractBaseModelViewSet -from .models import EbiosRMStudy, FearedEvent, RoTo, Stakeholder +from .models import EbiosRMStudy, FearedEvent, RoTo, Stakeholder, AttackPath from django.utils.decorators import method_decorator from django.views.decorators.cache import cache_page from rest_framework.decorators import action @@ -55,3 +55,7 @@ class StakeholderViewSet(BaseModelViewSet): @action(detail=False, name="Get category choices") def category(self, request): return Response(dict(Stakeholder.Category.choices)) + + +class AttackPathViewSet(BaseModelViewSet): + model = AttackPath