Skip to content

Commit adddebb

Browse files
fpintoppbDDuarte
andauthored
feat: extend search to look into the obj.dependencies and adds eol link (#239)
* feat: extend search to look into the obj.dependencies and adds eol link * return * feat: dependencies search improvements * fix: post_save * fix: dependencies list * fix: dep.id * feat: download icon * fix * Update surface/sca/management/commands/resync_vulns_counters.py Co-authored-by: Duarte Duarte <duarte.duarte@blip.pt> Signed-off-by: Fábio Pinto <67961647+fpintoppb@users.noreply.github.com> --------- Signed-off-by: Fábio Pinto <67961647+fpintoppb@users.noreply.github.com> Co-authored-by: Duarte Duarte <duarte.duarte@blip.pt>
1 parent cda0d24 commit adddebb

6 files changed

Lines changed: 48 additions & 6 deletions

File tree

surface/sca/admin.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,17 @@ class EndOfLifeDependencyAdmin(DefaultModelAdmin, DefaultFilterMixin, EndOfLifeD
7575
"no_support",
7676
"is_discontinued",
7777
"is_lts",
78-
"link",
78+
"get_link",
7979
]
8080
list_filter = ["product", EndOfLifeDependencyBoolFilter, LTSFilter, DiscontinuedFilter, SupportFilter]
8181
search_fields = ["product"]
8282

83+
@admin.display(description="Link")
84+
def get_link(self, obj):
85+
if obj.link:
86+
return format_html(f'<a target="_blank" href="{obj.link}">{obj.link}</a>')
87+
return ""
88+
8389

8490
class SCADependencyForm(forms.ModelForm):
8591
class Meta:
@@ -248,7 +254,16 @@ class SCAProjectAdmin(DefaultModelAdmin):
248254
"git_source",
249255
("git_source__apps", RelatedFieldAjaxListFilter),
250256
]
251-
search_fields = ["name", "purl", "depends_on__name", "depends_on__purl", "git_source__repo_url"]
257+
search_fields = [
258+
"name",
259+
"purl",
260+
"depends_on__name",
261+
"depends_on__purl",
262+
"git_source__repo_url",
263+
"dependencies_list",
264+
]
265+
266+
readonly_fields = []
252267

253268
def change_view(self, request, object_id, form_url="", extra_context=None):
254269
extra_context = extra_context or {}
@@ -276,7 +291,11 @@ def change_view(self, request, object_id, form_url="", extra_context=None):
276291

277292
vulnerabilities = self.get_vulnerabilities(obj)
278293
# set fixed_in as True by default if not passed in the request
279-
if "fixed_in" not in request.GET:
294+
if (
295+
"fixed_in" not in request.GET
296+
and int(request.GET.get("finding_type", models.SCAFinding.FindingType.VULN))
297+
!= models.SCAFinding.FindingType.EOL
298+
):
280299
request.GET = request.GET.copy()
281300
request.GET["fixed_in"] = "true"
282301
extra_context["vulns_filter"] = SCAFindingFilter(request.GET, queryset=vulnerabilities)
@@ -372,7 +391,7 @@ def get_git_source(self, obj):
372391
def get_sbom_link(self, obj):
373392
if obj.sbom_uuid:
374393
return format_html(
375-
'<a href="{}" target="_blank">Download sbom json</a>',
394+
'<a href="{}" target="_blank" title="Download SBOM JSON" aria-label="Download SBOM JSON"><span class="material-symbols-outlined text-lg">download</span></a>',
376395
reverse("sca:download_sbom_as_json", args=[obj.sbom_uuid, obj.name]),
377396
)
378397

surface/sca/management/commands/resync_sbom_repo.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ def handle_sbom(self, sbom: str) -> bool:
238238

239239
if project:
240240
project.update_vulnerability_counters()
241+
project.dependencies_list = project.dependencies
242+
project.save()
241243

242244
self.processed += 1
243245
return True

surface/sca/management/commands/resync_vulns_counters.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66

77

88
class Command(LogBaseCommand):
9-
help = "Re-sync SCA Projects Vulnerabilities Counters"
9+
help = "Re-sync SCA Projects Vulnerabilities Counters and dependencies list."
1010

1111
processed_projects = 0
1212

1313
def handle(self, *args, **options):
1414
self.sync_time = timezone.now()
1515
for project in tqdm.tqdm(SCADependency.objects.filter(is_project=True)):
1616
project.update_vulnerability_counters()
17+
project.dependencies_list = project.dependencies
18+
project.save(update_fields=["dependencies_list"])
1719
self.processed_projects += 1
1820

1921
SCAFindingCounter.objects.filter(last_sync__lt=self.sync_time).update(
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 5.2.8 on 2025-11-11 16:31
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('sca', '0003_scadependency_sbom_uuid_and_more'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='scadependency',
15+
name='dependencies_list',
16+
field=models.JSONField(default=list),
17+
),
18+
]

surface/sca/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class SCADependency(models.Model):
7070
updated_at = models.DateTimeField(auto_now=True)
7171
last_scan = models.DateTimeField()
7272
sbom_uuid = models.CharField(max_length=255, default=None, null=True)
73+
dependencies_list = models.JSONField(default=list)
7374

7475
@staticmethod
7576
def get_dependencies_recursively(

surface/sca/templates/views/dependencies.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
<form method="post" action="">
111111
{% csrf_token %}
112112
<input type="hidden" name="action" value="run_renovate_dependency">
113-
<input type="hidden" name="dependency_id" value="{{ dep.pk }}">
113+
<input type="hidden" name="dependency_id" value="{{ dep.id }}">
114114
<button class="ui circular icon basic tertiary green button" title="Renovate Dependency">
115115
<i class="recycle icon"></i>
116116
</button>

0 commit comments

Comments
 (0)