Skip to content

Commit

Permalink
Move the VulnerabilityAnalysisViewSet in the vulnerabilities module #103
Browse files Browse the repository at this point in the history


Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez committed Dec 11, 2024
1 parent bc0f992 commit bdd0fe2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 33 deletions.
2 changes: 1 addition & 1 deletion dejacode/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
from product_portfolio.api import ProductDependencyViewSet
from product_portfolio.api import ProductPackageViewSet
from product_portfolio.api import ProductViewSet
from product_portfolio.api import VulnerabilityAnalysisViewSet
from reporting.api import ReportViewSet
from vulnerabilities.api import VulnerabilityAnalysisViewSet
from vulnerabilities.api import VulnerabilityViewSet
from workflow.api import RequestTemplateViewSet
from workflow.api import RequestViewSet
Expand Down
12 changes: 12 additions & 0 deletions dje/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,18 @@ def to_internal_value(self, data):
self.fail("does_not_exist")


class ProductRelatedViewSet(ExtraPermissionsViewSetMixin, CreateRetrieveUpdateListViewSet):
lookup_field = "uuid"
extra_permissions = (TabPermission,)

def get_queryset(self):
perms = ["view_product"]
if self.request.method not in SAFE_METHODS:
perms.append("change_product")

return self.queryset.model.objects.product_secured(self.request.user, perms)


class ExternalReferenceSerializer(DataspacedSerializer):
external_source = DataspacedSlugRelatedField(slug_field="label")
content_type = serializers.StringRelatedField(source="content_type.model")
Expand Down
33 changes: 1 addition & 32 deletions product_portfolio/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@
from dje.api import DataspacedHyperlinkedRelatedField
from dje.api import DataspacedSerializer
from dje.api import DataspacedSlugRelatedField
from dje.api import ExtraPermissionsViewSetMixin
from dje.api import NameVersionHyperlinkedRelatedField
from dje.api import ProductRelatedViewSet
from dje.api import SPDXDocumentActionMixin
from dje.api_custom import TabPermission
from dje.filters import LastModifiedDateFilter
from dje.filters import MultipleCharFilter
from dje.filters import MultipleUUIDFilter
Expand All @@ -48,8 +47,6 @@
from product_portfolio.models import ProductComponent
from product_portfolio.models import ProductDependency
from product_portfolio.models import ProductPackage
from vulnerabilities.api import VulnerabilityAnalysis
from vulnerabilities.api import VulnerabilityAnalysisFilterSet
from vulnerabilities.api import VulnerabilityAnalysisSerializer

base_extra_kwargs = {
Expand Down Expand Up @@ -569,18 +566,6 @@ class Meta:
)


class ProductRelatedViewSet(ExtraPermissionsViewSetMixin, CreateRetrieveUpdateListViewSet):
lookup_field = "uuid"
extra_permissions = (TabPermission,)

def get_queryset(self):
perms = ["view_product"]
if self.request.method not in SAFE_METHODS:
perms.append("change_product")

return self.queryset.model.objects.product_secured(self.request.user, perms)


class ProductRelationViewSet(ProductRelatedViewSet):
relation_fk_field = None

Expand Down Expand Up @@ -935,19 +920,3 @@ def get_queryset(self):
"resolved_to_package__dataspace",
)
)


class VulnerabilityAnalysisViewSet(ProductRelatedViewSet):
queryset = VulnerabilityAnalysis.objects.none()
serializer_class = VulnerabilityAnalysisSerializer
filterset_class = VulnerabilityAnalysisFilterSet

def get_queryset(self):
return (
super()
.get_queryset()
.select_related(
"vulnerability",
"product_package",
)
)
17 changes: 17 additions & 0 deletions vulnerabilities/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from dje.api import DataspacedAPIFilterSet
from dje.api import DataspacedSerializer
from dje.api import ExtraPermissionsViewSetMixin
from dje.api import ProductRelatedViewSet
from dje.api_custom import TabPermission
from dje.filters import LastModifiedDateFilter
from dje.filters import MultipleUUIDFilter
Expand Down Expand Up @@ -173,3 +174,19 @@ class Meta:
"first_issued",
"last_updated",
)


class VulnerabilityAnalysisViewSet(ProductRelatedViewSet):
queryset = VulnerabilityAnalysis.objects.none()
serializer_class = VulnerabilityAnalysisSerializer
filterset_class = VulnerabilityAnalysisFilterSet

def get_queryset(self):
return (
super()
.get_queryset()
.select_related(
"vulnerability",
"product_package",
)
)

0 comments on commit bdd0fe2

Please sign in to comment.