Skip to content

Commit d774ac7

Browse files
cleanup model deletes
1 parent 4de0f60 commit d774ac7

5 files changed

Lines changed: 19 additions & 20 deletions

File tree

dojo/importers/base_importer.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
Endpoint,
2525
FileUpload,
2626
Finding,
27-
System_Settings,
2827
Test,
2928
Test_Import,
3029
Test_Import_Finding_Action,
@@ -34,7 +33,7 @@
3433
from dojo.notifications.helper import create_notification
3534
from dojo.tools.factory import get_parser
3635
from dojo.tools.parser_test import ParserTest
37-
from dojo.utils import calculate_grade, max_safe
36+
from dojo.utils import max_safe
3837

3938
logger = logging.getLogger(__name__)
4039

@@ -812,9 +811,3 @@ def notify_scan_added(
812811
url=reverse("view_test", args=(test.id,)),
813812
url_api=reverse("test-detail", args=(test.id,)),
814813
)
815-
816-
def perform_product_grading(self):
817-
product = self.test.engagement.product
818-
system_settings = System_Settings.objects.get()
819-
if system_settings.enable_product_grade:
820-
calculate_grade(product)

dojo/importers/default_importer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
Test_Import,
2121
)
2222
from dojo.notifications.helper import create_notification
23+
from dojo.utils import perform_product_grading
2324
from dojo.validators import clean_tags
2425

2526
logger = logging.getLogger(__name__)
@@ -297,7 +298,7 @@ def process_findings(
297298
# Note: All chord batching is now handled within the loop above
298299

299300
# Always perform an initial grading, even though it might get overwritten later.
300-
self.perform_product_grading()
301+
perform_product_grading(self.test.engagement.product)
301302

302303
sync = kwargs.get("sync", True)
303304
if not sync:
@@ -385,7 +386,7 @@ def close_old_findings(
385386

386387
# Calculate grade once after all findings have been closed
387388
if old_findings:
388-
self.perform_product_grading()
389+
perform_product_grading(self.test.engagement.product)
389390

390391
return old_findings
391392

dojo/importers/default_reimporter.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
Test,
2020
Test_Import,
2121
)
22+
from dojo.utils import perform_product_grading
2223
from dojo.validators import clean_tags
2324

2425
logger = logging.getLogger(__name__)
@@ -311,7 +312,7 @@ def process_findings(
311312
# Note: All chord batching is now handled within the loop above
312313

313314
# Synchronous tasks were already executed during processing, just calculate grade
314-
self.perform_product_grading()
315+
perform_product_grading(self.test.engagement.product)
315316

316317
# Process the results and return them back
317318
return self.process_results(**kwargs)
@@ -357,7 +358,7 @@ def close_old_findings(
357358

358359
# Calculate grade once after all findings have been closed
359360
if mitigated_findings:
360-
self.perform_product_grading()
361+
perform_product_grading(self.test.engagement.product)
361362

362363
return mitigated_findings
363364

dojo/models.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,7 +1652,8 @@ def delete(self, *args, **kwargs):
16521652
with suppress(Engagement.DoesNotExist, Product.DoesNotExist):
16531653
# Suppressing a potential issue created from async delete removing
16541654
# related objects in a separate task
1655-
calculate_grade(self.product)
1655+
from dojo.utils import perform_product_grading # noqa: PLC0415 circular import
1656+
perform_product_grading(self.test.engagement.product)
16561657

16571658
def inherit_tags(self, potentially_existing_tags):
16581659
# get a copy of the tags to be inherited
@@ -2258,9 +2259,8 @@ def delete(self, *args, product_grading_option=True, **kwargs):
22582259
with suppress(Test.DoesNotExist, Engagement.DoesNotExist, Product.DoesNotExist):
22592260
# Suppressing a potential issue created from async delete removing
22602261
# related objects in a separate task
2261-
system_settings = System_Settings.objects.get()
2262-
if system_settings.enable_product_grade:
2263-
calculate_grade(self.engagement.product)
2262+
from dojo.utils import perform_product_grading # noqa: PLC0415 circular import
2263+
perform_product_grading(self.test.engagement.product)
22642264

22652265
@property
22662266
def statistics(self):
@@ -2868,9 +2868,8 @@ def delete(self, *args, product_grading_option=True, **kwargs):
28682868
with suppress(Finding.DoesNotExist, Test.DoesNotExist, Engagement.DoesNotExist, Product.DoesNotExist):
28692869
# Suppressing a potential issue created from async delete removing
28702870
# related objects in a separate task
2871-
system_settings = System_Settings.objects.get()
2872-
if system_settings.enable_product_grade:
2873-
calculate_grade(self.test.engagement.product)
2871+
from dojo.utils import perform_product_grading # noqa: PLC0415 circular import
2872+
perform_product_grading(self.test.engagement.product)
28742873

28752874
# only used by bulk risk acceptance api
28762875
@classmethod
@@ -4713,7 +4712,6 @@ def __str__(self):
47134712

47144713

47154714
from dojo.utils import ( # noqa: E402 # there is issue due to a circular import
4716-
calculate_grade,
47174715
parse_cvss_data,
47184716
to_str_typed,
47194717
)

dojo/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,6 +1619,12 @@ def calculate_grade_internal(product, *args, **kwargs):
16191619
logger.debug("Product %s grade %i is up to date", product.id, prod_numeric_grade)
16201620

16211621

1622+
def perform_product_grading(product):
1623+
system_settings = System_Settings.objects.get()
1624+
if system_settings.enable_product_grade:
1625+
calculate_grade(product)
1626+
1627+
16221628
def get_celery_worker_status():
16231629
from .tasks import celery_status # noqa: PLC0415 circular import
16241630
res = celery_status.apply_async()

0 commit comments

Comments
 (0)