Skip to content

Commit

Permalink
Replace POST method for dislike by DELETE
Browse files Browse the repository at this point in the history
  • Loading branch information
pablosnt committed Mar 24, 2024
1 parent ee4bfdf commit 0cc8760
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 22 deletions.
10 changes: 5 additions & 5 deletions src/backend/findings/framework/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ class FindingViewSet(BaseViewSet):

@extend_schema(exclude=True)
def create(self, request: Request, *args, **kwargs):
return self._method_not_allowed("POST")
return self._method_not_allowed("POST") # pragma: no cover

@extend_schema(exclude=True)
def destroy(self, request: Request, *args: Any, **kwargs: Any) -> Response:
return self._method_not_allowed("DELETE") # pragma: no cover

@extend_schema(request=None, responses={200: FindingSerializer})
@action(detail=True, methods=["POST"], url_path="fix", url_name="fix")
Expand All @@ -41,10 +45,6 @@ def fix(self, request: Request, pk: str) -> Response:
self.get_serializer_class()(finding).data, status=status.HTTP_200_OK
)

@extend_schema(exclude=True)
def destroy(self, request: Request, *args: Any, **kwargs: Any) -> Response:
return self._method_not_allowed("DELETE")

@action(detail=True, methods=["DELETE"], url_path="fix", url_name="remove_fix")
def remove_fix(self, request: Request, pk: str) -> Response:
input("UNFIX")
Expand Down
3 changes: 1 addition & 2 deletions src/backend/findings/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from rest_framework.routers import SimpleRouter

from findings.views import (
CredentialViewSet,
ExploitViewSet,
Expand All @@ -10,6 +8,7 @@
TechnologyViewSet,
VulnerabilityViewSet,
)
from rest_framework.routers import SimpleRouter

# Register your views here.

Expand Down
4 changes: 2 additions & 2 deletions src/backend/framework/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ def like(self, request: Request, pk: str) -> Response:
# all auditors can make POST requests to resources like these.
@action(
detail=True,
methods=["POST"],
url_path="dislike",
methods=["DELETE"],
url_path="like",
url_name="dislike",
permission_classes=[IsAuthenticated, IsAuditor],
)
Expand Down
4 changes: 3 additions & 1 deletion src/backend/reporting/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,9 @@ def _get_findings_to_pdf_report(
)
.all(),
}
for host in Host.objects.filter(**{**target_filter, **serializer.validated_filter})
for host in Host.objects.filter(
**{**target_filter, **serializer.validated_filter}
)
],
}
if (
Expand Down
6 changes: 3 additions & 3 deletions src/backend/tests/test_processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class ProcessTest(ApiTest):
),
ApiTestCase(["reader1", "reader2"], "post", 403, endpoint="{endpoint}8/like/"),
ApiTestCase(
["reader1", "reader2"], "post", 403, endpoint="{endpoint}9/dislike/"
["reader1", "reader2"], "delete", 403, endpoint="{endpoint}9/like/"
),
ApiTestCase(
["admin1", "admin2", "auditor1", "auditor2"],
Expand Down Expand Up @@ -186,9 +186,9 @@ class ProcessTest(ApiTest):
),
ApiTestCase(
["admin1", "admin2", "auditor1", "auditor2"],
"post",
"delete",
204,
endpoint="{endpoint}8/dislike/",
endpoint="{endpoint}8/like/",
),
ApiTestCase(
["admin1", "admin2", "auditor1", "auditor2"],
Expand Down
6 changes: 3 additions & 3 deletions src/backend/tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ class ToolTest(ApiTest):
endpoint="{endpoint}3/",
),
ApiTestCase(
["reader1", "reader2"], "get", 403, endpoint="{endpoint}1/dislike/"
["reader1", "reader2"], "delete", 403, endpoint="{endpoint}1/like/"
),
ApiTestCase(
["admin1", "admin2", "auditor1", "auditor2"],
"post",
"delete",
204,
endpoint="{endpoint}1/dislike/",
endpoint="{endpoint}1/like/",
),
ApiTestCase(
["admin1", "admin2", "auditor1", "auditor2"],
Expand Down
6 changes: 3 additions & 3 deletions src/backend/tests/test_wordlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class WordlistTest(ApiTest):
),
ApiTestCase(["reader1", "reader2"], "post", 403, endpoint="{endpoint}29/like/"),
ApiTestCase(
["reader1", "reader2"], "post", 403, endpoint="{endpoint}30/dislike/"
["reader1", "reader2"], "delete", 403, endpoint="{endpoint}30/like/"
),
ApiTestCase(
["admin1", "admin2", "auditor1", "auditor2"],
Expand Down Expand Up @@ -167,9 +167,9 @@ class WordlistTest(ApiTest):
),
ApiTestCase(
["admin1", "admin2", "auditor1", "auditor2"],
"post",
"delete",
204,
endpoint="{endpoint}29/dislike/",
endpoint="{endpoint}29/like/",
),
ApiTestCase(
["admin1", "admin2", "auditor1", "auditor2"],
Expand Down
13 changes: 10 additions & 3 deletions src/backend/tools/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from typing import Any

from drf_spectacular.utils import extend_schema
from framework.views import BaseViewSet, LikeViewSet
from rest_framework.permissions import IsAuthenticated
from rest_framework.request import Request
from rest_framework.response import Response
from security.authorization.permissions import RekonoModelPermission
from tools.filters import ConfigurationFilter, ToolFilter
from tools.models import Configuration, Tool
Expand All @@ -17,13 +20,17 @@ class ToolViewSet(LikeViewSet):
permission_classes = [IsAuthenticated, RekonoModelPermission]
search_fields = ["name", "command"]
ordering_fields = ["id", "name", "command"]
# "post" is needed to allow POST requests to like and dislike tools
http_method_names = ["get", "post"]
# "post" and "delete" are needed to allow POST requests to like and dislike tools
http_method_names = ["get", "post", "delete"]

@extend_schema(exclude=True)
def create(self, request: Request, *args, **kwargs):
def create(self, request: Request, *args, **kwargs) -> Response:
return self._method_not_allowed("POST") # pragma: no cover

@extend_schema(exclude=True)
def destroy(self, request: Request, *args: Any, **kwargs: Any) -> Response:
return self._method_not_allowed("DELETE") # pragma: no cover


class ConfigurationViewSet(BaseViewSet):
"""Configuration ViewSet that includes: get and retrieve features."""
Expand Down

0 comments on commit 0cc8760

Please sign in to comment.