-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: list issues and filter by referenced CVEs in REST API
- Loading branch information
1 parent
4f4baad
commit 6d23bcc
Showing
5 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from django.urls import include, path | ||
from rest_framework import routers | ||
|
||
from shared.views import NixpkgsIssueViewSet | ||
|
||
v1_router = routers.DefaultRouter() | ||
v1_router.register(r"issues", NixpkgsIssueViewSet) | ||
|
||
urlpatterns = [ | ||
path("v1/", include(v1_router.urls)), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,35 @@ | ||
# Create your views here. | ||
from django_filters import rest_framework as filters | ||
from rest_framework import serializers, viewsets | ||
from rest_framework.permissions import AllowAny | ||
|
||
from shared.models import NixpkgsIssue | ||
|
||
|
||
class StringInFilter(filters.BaseInFilter, filters.CharFilter): | ||
pass | ||
|
||
|
||
class NixpkgsIssueViewSet(viewsets.ReadOnlyModelViewSet): | ||
class Filter(filters.FilterSet): | ||
cve = StringInFilter( | ||
label="Filter by CVEs referenced", | ||
field_name="cve__cve_id", | ||
lookup_expr="in", | ||
) | ||
|
||
class Meta: | ||
model = NixpkgsIssue | ||
fields = ["cve"] | ||
|
||
class Serializer(serializers.ModelSerializer): | ||
status = serializers.CharField(source="get_status_display") | ||
|
||
class Meta: | ||
model = NixpkgsIssue | ||
fields = ["code", "status"] | ||
|
||
filterset_class = Filter | ||
|
||
permission_classes = [AllowAny] | ||
queryset = NixpkgsIssue.objects.all() | ||
serializer_class = Serializer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters