Skip to content

Commit baac171

Browse files
respect system settings product grading enabled
1 parent 930792d commit baac171

3 files changed

Lines changed: 39 additions & 19 deletions

File tree

dojo/importers/default_importer.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22

3-
from celery import chord
3+
from celery import chord, group
44
from django.core.files.uploadedfile import TemporaryUploadedFile
55
from django.core.serializers import serialize
66
from django.db.models.query_utils import Q
@@ -15,6 +15,7 @@
1515
from dojo.models import (
1616
Engagement,
1717
Finding,
18+
System_Settings,
1819
Test,
1920
Test_Import,
2021
)
@@ -274,8 +275,13 @@ def process_findings(
274275
if batch_full or is_final:
275276
# Launch chord with current batch of signatures
276277
product = self.test.engagement.product
277-
calculate_grade_signature = utils.calculate_grade_signature(product)
278-
chord(post_processing_task_signatures)(calculate_grade_signature)
278+
system_settings = System_Settings.objects.get()
279+
if system_settings.enable_product_grade:
280+
calculate_grade_signature = utils.calculate_grade_signature(product)
281+
chord(post_processing_task_signatures)(calculate_grade_signature)
282+
# If product grading is disabled, just run the post-processing tasks without the grade calculation callback
283+
elif post_processing_task_signatures:
284+
group(post_processing_task_signatures).apply_async()
279285

280286
logger.debug(f"Launched chord with {len(post_processing_task_signatures)} tasks (batch #{current_batch_number}, size: {len(post_processing_task_signatures)})")
281287

@@ -305,7 +311,9 @@ def process_findings(
305311

306312
# Always perform an initial grading, even though it might get overwritten later.
307313
product = self.test.engagement.product
308-
calculate_grade(product)
314+
system_settings = System_Settings.objects.get()
315+
if system_settings.enable_product_grade:
316+
calculate_grade(product)
309317

310318
sync = kwargs.get("sync", True)
311319
if not sync:
@@ -394,7 +402,9 @@ def close_old_findings(
394402
# Calculate grade once after all findings have been closed
395403
if old_findings:
396404
product = self.test.engagement.product
397-
calculate_grade(product)
405+
system_settings = System_Settings.objects.get()
406+
if system_settings.enable_product_grade:
407+
calculate_grade(product)
398408

399409
return old_findings
400410

dojo/importers/default_reimporter.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22

3-
from celery import chord
3+
from celery import chord, group
44
from django.core.files.uploadedfile import TemporaryUploadedFile
55
from django.core.serializers import serialize
66
from django.db.models.query_utils import Q
@@ -15,6 +15,7 @@
1515
Development_Environment,
1616
Finding,
1717
Notes,
18+
System_Settings,
1819
Test,
1920
Test_Import,
2021
)
@@ -279,8 +280,13 @@ def process_findings(
279280
if batch_full or is_final:
280281
# Launch chord with current batch of signatures
281282
product = self.test.engagement.product
282-
calculate_grade_signature = utils.calculate_grade_signature(product)
283-
chord(post_processing_task_signatures)(calculate_grade_signature)
283+
system_settings = System_Settings.objects.get()
284+
if system_settings.enable_product_grade:
285+
calculate_grade_signature = utils.calculate_grade_signature(product)
286+
chord(post_processing_task_signatures)(calculate_grade_signature)
287+
# If product grading is disabled, just run the post-processing tasks without the grade calculation callback
288+
elif post_processing_task_signatures:
289+
group(post_processing_task_signatures).apply_async()
284290

285291
logger.debug(f"Launched chord with {len(post_processing_task_signatures)} tasks (batch #{current_batch_number}, size: {len(post_processing_task_signatures)})")
286292

@@ -306,7 +312,9 @@ def process_findings(
306312

307313
# Synchronous tasks were already executed during processing, just calculate grade
308314
product = self.test.engagement.product
309-
calculate_grade(product)
315+
system_settings = System_Settings.objects.get()
316+
if system_settings.enable_product_grade:
317+
calculate_grade(product)
310318

311319
# Process the results and return them back
312320
return self.process_results(**kwargs)
@@ -353,7 +361,9 @@ def close_old_findings(
353361
# Calculate grade once after all findings have been closed
354362
if mitigated_findings:
355363
product = self.test.engagement.product
356-
calculate_grade(product)
364+
system_settings = System_Settings.objects.get()
365+
if system_settings.enable_product_grade:
366+
calculate_grade(product)
357367

358368
return mitigated_findings
359369

unittests/test_importers_performance.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,12 @@ def import_reimport_performance(self, expected_num_queries1, expected_num_async_
176176
# def test_import_reimport_reimport_performance_async(self, mock):
177177
def test_import_reimport_reimport_performance_async(self):
178178
self.import_reimport_performance(
179-
expected_num_queries1=715,
180-
expected_num_async_tasks1=13,
181-
expected_num_queries2=612,
182-
expected_num_async_tasks2=25,
183-
expected_num_queries3=294,
184-
expected_num_async_tasks3=23,
179+
expected_num_queries1=713,
180+
expected_num_async_tasks1=10,
181+
expected_num_queries2=610,
182+
expected_num_async_tasks2=22,
183+
expected_num_queries3=292,
184+
expected_num_async_tasks3=20,
185185
)
186186

187187
# @patch("dojo.decorators.we_want_async", return_value=False)
@@ -199,11 +199,11 @@ def test_import_reimport_reimport_performance_no_async(self):
199199
testuser.usercontactinfo.save()
200200
self.import_reimport_performance(
201201
expected_num_queries1=713,
202-
expected_num_async_tasks1=11,
202+
expected_num_async_tasks1=10,
203203
expected_num_queries2=615,
204-
expected_num_async_tasks2=23,
204+
expected_num_async_tasks2=22,
205205
expected_num_queries3=297,
206-
expected_num_async_tasks3=21,
206+
expected_num_async_tasks3=20,
207207
)
208208

209209
# @patch("dojo.decorators.we_want_async", return_value=False)

0 commit comments

Comments
 (0)