diff --git a/scanpipe/filters.py b/scanpipe/filters.py index 1a063d730d..f446b1b51c 100644 --- a/scanpipe/filters.py +++ b/scanpipe/filters.py @@ -522,6 +522,15 @@ def filter(self, qs, value): class ResourceFilterSet(FilterSetUtilsMixin, django_filters.FilterSet): + detected_license_expression = django_filters.ChoiceFilter( + label="Detected license expression", + choices=[ + (EMPTY_VAR, "None"), + (ANY_VAR, "Any"), + ], + widget=HasValueDropdownWidget(), + ) + dropdown_widget_fields = [ "status", "type", @@ -529,6 +538,7 @@ class ResourceFilterSet(FilterSetUtilsMixin, django_filters.FilterSet): "compliance_alert", "in_package", "relation_map_type", + "detected_license_expression", ] search = QuerySearchFilter( diff --git a/scanpipe/models.py b/scanpipe/models.py index 0ecd8e6392..126f85f550 100644 --- a/scanpipe/models.py +++ b/scanpipe/models.py @@ -46,6 +46,7 @@ from django.db import transaction from django.db.models import Case from django.db.models import Count +from django.db.models import Exists from django.db.models import IntegerField from django.db.models import OuterRef from django.db.models import Prefetch @@ -231,7 +232,7 @@ def delete(self, *args, **kwargs): Note that projects with queued or running pipeline runs cannot be deleted. See the `_raise_if_run_in_progress` method. The following if statements should not be triggered unless the `.delete()` - method is directly call from an instance of this class. + method is directly call from a instance of this class. """ with suppress(redis.exceptions.ConnectionError, AttributeError): if self.status == self.Status.RUNNING: @@ -2425,6 +2426,17 @@ def macho_binaries(self): def executable_binaries(self): return self.union(self.win_exes(), self.macho_binaries(), self.elfs()) + def with_has_children(self): + """ + Annotate the QuerySet with has_children field based on whether + each resource has any children (subdirectories/files). + """ + children_qs = CodebaseResource.objects.filter( + parent_path=OuterRef("path"), + ) + + return self.annotate(has_children=Exists(children_qs)) + class ScanFieldsModelMixin(models.Model): """Fields returned by the ScanCode-toolkit scans.""" diff --git a/scanpipe/templates/scanpipe/dropdowns/filter_dropdown_choices_field.html b/scanpipe/templates/scanpipe/dropdowns/filter_dropdown_choices_field.html index 60f4ed24cb..9b42e384a4 100644 --- a/scanpipe/templates/scanpipe/dropdowns/filter_dropdown_choices_field.html +++ b/scanpipe/templates/scanpipe/dropdowns/filter_dropdown_choices_field.html @@ -1,12 +1,28 @@ -