Skip to content

Commit

Permalink
Create OperationalScenario endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
nas-tabchiche committed Dec 4, 2024
1 parent d709119 commit e16a1f6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
27 changes: 26 additions & 1 deletion backend/ebios_rm/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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__"
6 changes: 6 additions & 0 deletions backend/ebios_rm/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
RoToViewSet,
StakeholderViewSet,
AttackPathViewSet,
OperationalScenarioViewSet,
)

router = routers.DefaultRouter()
Expand All @@ -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)),
Expand Down
13 changes: 12 additions & 1 deletion backend/ebios_rm/views.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -59,3 +66,7 @@ def category(self, request):

class AttackPathViewSet(BaseModelViewSet):
model = AttackPath


class OperationalScenarioViewSet(BaseModelViewSet):
model = OperationalScenario

0 comments on commit e16a1f6

Please sign in to comment.