Skip to content

Commit cdf075f

Browse files
committed
🐛 Remove unselected parsers from filters and test types
1 parent 3a2f66a commit cdf075f

4 files changed

Lines changed: 30 additions & 4 deletions

File tree

dojo/filters.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
from dojo.risk_acceptance.queries import get_authorized_risk_acceptances
9494
from dojo.test.queries import get_authorized_tests
9595
from dojo.user.queries import get_authorized_users
96-
from dojo.utils import get_system_setting, is_finding_groups_enabled, truncate_timezone_aware
96+
from dojo.utils import get_system_setting, get_visible_scan_types, is_finding_groups_enabled, truncate_timezone_aware
9797

9898
logger = logging.getLogger(__name__)
9999

@@ -2030,6 +2030,9 @@ def __init__(self, *args, **kwargs):
20302030
# Don't show the product filter on the product finding view
20312031
self.set_related_object_fields(*args, **kwargs)
20322032

2033+
if "test__test_type" in self.form.fields:
2034+
self.form.fields["test__test_type"].queryset = get_visible_scan_types()
2035+
20332036
def set_related_object_fields(self, *args: list, **kwargs: dict):
20342037
finding_group_query = Finding_Group.objects.all()
20352038
if self.pid is not None:

dojo/finding/views.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
get_page_items_and_count,
119119
get_return_url,
120120
get_system_setting,
121+
get_visible_scan_types,
121122
get_words_for_field,
122123
match_finding_to_existing_findings,
123124
process_tag_notifications,
@@ -302,6 +303,7 @@ def get_initial_context(self, request: HttpRequest):
302303
"enable_table_filtering": get_system_setting("enable_ui_table_based_searching"),
303304
"title_words": get_words_for_field(Finding, "title"),
304305
"component_words": get_words_for_field(Finding, "component_name"),
306+
"visible_test_types": get_visible_scan_types(),
305307
}
306308
# Look to see if the product was used
307309
if product_id := self.get_product_id():

dojo/test_type/views.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from dojo.filters import TestTypeFilter
1212
from dojo.forms import Test_TypeForm
1313
from dojo.models import Test_Type
14-
from dojo.utils import add_breadcrumb, get_page_items
14+
from dojo.utils import add_breadcrumb, get_page_items, get_visible_scan_types
1515

1616
logger = logging.getLogger(__name__)
1717

@@ -24,7 +24,7 @@
2424

2525
@login_required
2626
def test_type(request):
27-
initial_queryset = Test_Type.objects.all().order_by("name")
27+
initial_queryset = get_visible_scan_types().order_by("name")
2828
name_words = initial_queryset.values_list("name", flat=True)
2929
test_types = TestTypeFilter(request.GET, queryset=initial_queryset)
3030
tts = get_page_items(request, test_types.qs, 25)
@@ -35,7 +35,8 @@ def test_type(request):
3535
"user": request.user,
3636
"tts": tts,
3737
"test_types": test_types,
38-
"name_words": name_words})
38+
"name_words": name_words,
39+
})
3940

4041

4142
@user_is_configuration_authorized("dojo.add_test_type")

dojo/utils.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
Product,
7070
System_Settings,
7171
Test,
72+
Test_Type,
7273
User,
7374
)
7475
from dojo.notifications.helper import create_notification
@@ -84,6 +85,25 @@
8485
"""
8586

8687

88+
def get_visible_scan_types():
89+
"""
90+
Returns a QuerySet of active, non-excluded Test_Type objects.
91+
Supports comma or pipe-separated names in PARSER_EXCLUDE.
92+
"""
93+
exclude_raw = (getattr(settings, "PARSER_EXCLUDE", "") or "").strip()
94+
if exclude_raw:
95+
# Support both ',' and '|' separators
96+
parts = [p.strip() for sep in (",", "|") for p in exclude_raw.split(sep)]
97+
excluded_names = {p for p in parts if p}
98+
else:
99+
excluded_names = set()
100+
101+
qs = Test_Type.objects.filter(active=True)
102+
if excluded_names:
103+
qs = qs.exclude(name__in=excluded_names)
104+
return qs
105+
106+
87107
def do_false_positive_history(finding, *args, **kwargs):
88108
"""
89109
Replicate false positives across product.

0 commit comments

Comments
 (0)