Skip to content

Commit

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

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

router = routers.DefaultRouter()
Expand All @@ -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)),
Expand Down
6 changes: 5 additions & 1 deletion backend/ebios_rm/views.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

0 comments on commit d709119

Please sign in to comment.