Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ordering to Test_Import API Endpoint #11448

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading