Skip to content

Commit

Permalink
Add fixed packages in packages endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Tushar Goel <[email protected]>
  • Loading branch information
TG1999 committed Jun 27, 2022
1 parent c94ed57 commit b2507c5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions vulnerabilities/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def to_representation(self, instance):
fixing_vulnerabilities = MinimalVulnerabilitySerializer(
many=True, source="resolved_to", read_only=True
)
fixed_packages = MinimalPackageSerializer(many=True, read_only=True)

class Meta:
model = Package
Expand All @@ -119,6 +120,7 @@ class Meta:
"qualifiers",
"subpath",
"affected_by_vulnerabilities",
"fixed_packages",
"fixing_vulnerabilities",
]

Expand Down
17 changes: 17 additions & 0 deletions vulnerabilities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,23 @@ def resolved_to(self):
"""
return self.vulnerabilities.filter(packagerelatedvulnerability__fix=True)

@property
def fixed_packages(self):
"""
Returns vulnerabilities which are affecting this package.
"""
return (
Package.objects.filter(
name=self.name,
namespace=self.namespace,
type=self.type,
qualifiers=self.qualifiers,
subpath=self.subpath,
)
.filter(packagerelatedvulnerability__fix=True)
.distinct()
)

def set_package_url(self, package_url):
"""
Set each field values to the values of the provided `package_url` string
Expand Down
1 change: 1 addition & 0 deletions vulnerabilities/tests/test_fix_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def test_api_with_single_vulnerability(self):
"unresolved_vulnerabilities": [],
"qualifiers": {},
"subpath": "",
"fixed_packages": [],
"affected_by_vulnerabilities": [],
"fixing_vulnerabilities": [],
}
Expand Down

0 comments on commit b2507c5

Please sign in to comment.