Skip to content

Commit

Permalink
add ordering to test_import API endpoint (#11448)
Browse files Browse the repository at this point in the history
  • Loading branch information
hblankenship authored Jan 2, 2025
1 parent 5678d55 commit e7f9f24
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
15 changes: 4 additions & 11 deletions dojo/api_v2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
ApiTestFilter,
ReportFindingFilter,
ReportFindingFilterWithoutObjectLookups,
TestImportAPIFilter,
)
from dojo.finding.queries import (
get_authorized_findings,
Expand Down Expand Up @@ -2259,17 +2260,9 @@ class TestImportViewSet(
serializer_class = serializers.TestImportSerializer
queryset = Test_Import.objects.none()
filter_backends = (DjangoFilterBackend,)
filterset_fields = [
"test",
"findings_affected",
"version",
"branch_tag",
"build_id",
"commit_hash",
"test_import_finding_action__action",
"test_import_finding_action__finding",
"test_import_finding_action__created",
]

filterset_class = TestImportAPIFilter

permission_classes = (
IsAuthenticated,
permissions.UserHasTestImportPermission,
Expand Down
31 changes: 31 additions & 0 deletions dojo/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3212,6 +3212,7 @@ class Meta:
exclude = ["users"]


# This class is used exclusively by Findings
class TestImportFilter(DojoFilter):
version = CharFilter(field_name="version", lookup_expr="icontains")
version_exact = CharFilter(field_name="version", lookup_expr="iexact", label="Version Exact")
Expand All @@ -3238,6 +3239,7 @@ class Meta:
fields = []


# This class is used exclusively by Findings
class TestImportFindingActionFilter(DojoFilter):
action = MultipleChoiceFilter(choices=IMPORT_ACTIONS)
o = OrderingFilter(
Expand All @@ -3252,6 +3254,35 @@ class Meta:
fields = []


# Used within the TestImport API
class TestImportAPIFilter(DojoFilter):
o = OrderingFilter(
# tuple-mapping retains order
fields=(
("id", "id"),
("created", "created"),
("modified", "modified"),
("version", "version"),
("branch_tag", "branch_tag"),
("build_id", "build_id"),
("commit_hash", "commit_hash"),

),
)

class Meta:
model = Test_Import
fields = ["test",
"findings_affected",
"version",
"branch_tag",
"build_id",
"commit_hash",
"test_import_finding_action__action",
"test_import_finding_action__finding",
"test_import_finding_action__created"]


class LogEntryFilter(DojoFilter):
from auditlog.models import LogEntry

Expand Down

0 comments on commit e7f9f24

Please sign in to comment.