@@ -743,6 +743,7 @@ def add_ssvc(ssvc):
743743 "advisory" : advisory ,
744744 "severities" : list (advisory .severities .all ()),
745745 "references" : list (advisory .references .all ()),
746+ "patches" : list (advisory .patches .all ()),
746747 "aliases" : list (advisory .aliases .all ()),
747748 "severity_vectors" : severity_vectors ,
748749 "weaknesses" : weaknesses_present_in_db ,
@@ -940,6 +941,57 @@ def get_queryset(self):
940941 )
941942
942943
944+ class AdvisoryPackageCommitPatchDetails (DetailView ):
945+ """
946+ View to display all packages introduce by or fixing a specific vulnerability.
947+ URL: /advisories/{id}/commits
948+ """
949+
950+ model = models .AdvisoryV2
951+ template_name = "advisory_package_commit_details.html"
952+ slug_url_kwarg = "avid"
953+
954+ def get_object (self , queryset = None ):
955+ avid = self .kwargs .get (self .slug_url_kwarg )
956+ if not avid :
957+ raise Http404 ("Missing advisory identifier" )
958+
959+ advisory = models .AdvisoryV2 .objects .latest_for_avid (avid )
960+
961+ if not advisory :
962+ raise Http404 (f"No advisory found for avid: { avid } " )
963+
964+ return advisory
965+
966+ def get_queryset (self ):
967+ """
968+ Prefetch and optimize related data to minimize database hits.
969+ """
970+ return (
971+ super ()
972+ .get_queryset ()
973+ .prefetch_related (
974+ Prefetch (
975+ "impacted_packages" ,
976+ queryset = models .ImpactedPackage .objects .order_by ("base_purl" ).prefetch_related (
977+ Prefetch (
978+ "introduced_by_package_commit_patches" ,
979+ queryset = models .PackageCommitPatch .objects .only (
980+ "commit_hash" , "vcs_url" , "patch_url" , "commit_url"
981+ ),
982+ ),
983+ Prefetch (
984+ "fixed_by_package_commit_patches" ,
985+ queryset = models .PackageCommitPatch .objects .only (
986+ "commit_hash" , "vcs_url" , "patch_url" , "commit_url"
987+ ),
988+ ),
989+ ),
990+ )
991+ )
992+ )
993+
994+
943995class PipelineScheduleListView (VulnerableCodeListView , FormMixin ):
944996 model = PipelineSchedule
945997 context_object_name = "schedule_list"
0 commit comments