Skip to content

Commit 1e79866

Browse files
authored
Product Grade: Configuration Removal (#14075)
* Remove product grade configuration and related management command * Remove product_grade field from system_settings model * Update expected query counts in performance tests for importer
1 parent bd29cf2 commit 1e79866

9 files changed

Lines changed: 46 additions & 65 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Generated by Django 5.2.9 on 2026-01-09 23:56
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('dojo', '0254_remove_vulnerability_id_template_model'),
10+
]
11+
12+
operations = [
13+
migrations.RemoveField(
14+
model_name='system_settings',
15+
name='product_grade',
16+
),
17+
]

dojo/fixtures/defect_dojo_sample_data.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,6 @@
814814
"url_prefix": "",
815815
"team_name": "",
816816
"enable_product_grade": true,
817-
"product_grade": "def grade_product(crit, high, med, low):\r\n health=100\r\n if crit > 0:\r\n health = 40\r\n health = health - ((crit - 1) * 5)\r\n if high > 0:\r\n if health == 100:\r\n health = 60\r\n health = health - ((high - 1) * 3)\r\n if med > 0:\r\n if health == 100:\r\n health = 80\r\n health = health - ((med - 1) * 2)\r\n if low > 0:\r\n if health == 100:\r\n health = 95\r\n health = health - low\r\n\r\n if health < 5:\r\n health = 5\r\n\r\n return health",
818817
"product_grade_a": 90,
819818
"product_grade_b": 80,
820819
"product_grade_c": 70,

dojo/fixtures/dojo_testdata.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@
242242
"mail_notifications_to": "",
243243
"enable_jira": false,
244244
"enable_product_grade": true,
245-
"product_grade": "def grade_product(crit, high, med, low):\r\n health=100\r\n if crit > 0:\r\n health = 40\r\n health = health - ((crit - 1) * 5)\r\n if high > 0:\r\n if health == 100:\r\n health = 60\r\n health = health - ((high - 1) * 3)\r\n if med > 0:\r\n if health == 100:\r\n health = 80\r\n health = health - ((med - 1) * 2)\r\n if low > 0:\r\n if health == 100:\r\n health = 95\r\n health = health - low\r\n\r\n if health < 5:\r\n health = 5\r\n\r\n return health",
246245
"product_grade_a": 90,
247246
"product_grade_b": 80,
248247
"product_grade_c": 70,

dojo/fixtures/system_settings.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"enable_deduplication": false,
77
"enable_jira": false,
88
"url_prefix": "",
9-
"product_grade": "def grade_product(crit, high, med, low):\r\n health=100\r\n if crit > 0:\r\n health = 40\r\n health = health - ((crit - 1) * 5)\r\n if high > 0:\r\n if health == 100:\r\n health = 60\r\n health = health - ((high - 1) * 3)\r\n if med > 0:\r\n if health == 100:\r\n health = 80\r\n health = health - ((med - 1) * 2)\r\n if low > 0:\r\n if health == 100:\r\n health = 95\r\n health = health - low\r\n\r\n if health < 5:\r\n health = 5\r\n\r\n return health",
109
"product_grade_a": 90,
1110
"product_grade_b": 80,
1211
"product_grade_c": 70,

dojo/forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3129,7 +3129,7 @@ def clean(self):
31293129

31303130
class Meta:
31313131
model = System_Settings
3132-
exclude = ["product_grade"]
3132+
fields = "__all__"
31333133

31343134

31353135
class BenchmarkForm(forms.ModelForm):

dojo/management/commands/system_settings.py

Lines changed: 0 additions & 35 deletions
This file was deleted.

dojo/models.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,6 @@ class System_Settings(models.Model):
441441
url_prefix = models.CharField(max_length=300, default="", blank=True, help_text=_("URL prefix if DefectDojo is installed in it's own virtual subdirectory."))
442442
team_name = models.CharField(max_length=100, default="", blank=True)
443443
enable_product_grade = models.BooleanField(default=False, verbose_name=_("Enable Product Grading"), help_text=_("Displays a grade letter next to a product to show the overall health."))
444-
product_grade = models.CharField(max_length=800, blank=True)
445444
product_grade_a = models.IntegerField(default=90,
446445
verbose_name=_("Grade A"),
447446
help_text=_("Percentage score for an "
@@ -685,19 +684,6 @@ def clean(self):
685684
})
686685

687686

688-
class SystemSettingsFormAdmin(forms.ModelForm):
689-
product_grade = forms.CharField(widget=forms.Textarea)
690-
691-
class Meta:
692-
model = System_Settings
693-
fields = ["product_grade"]
694-
695-
696-
class System_SettingsAdmin(admin.ModelAdmin):
697-
form = SystemSettingsFormAdmin
698-
fields = ("product_grade",)
699-
700-
701687
def get_current_date():
702688
return timezone.now().date()
703689

@@ -4854,7 +4840,7 @@ def __str__(self):
48544840
admin.site.register(Tool_Type)
48554841
admin.site.register(Cred_User)
48564842
admin.site.register(Cred_Mapping)
4857-
admin.site.register(System_Settings, System_SettingsAdmin)
4843+
admin.site.register(System_Settings)
48584844
admin.site.register(SLA_Configuration)
48594845
admin.site.register(CWE)
48604846
admin.site.register(Regulation)

dojo/utils.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import crum
2121
import cvss
2222
import vobject
23-
from asteval import Interpreter
2423
from auditlog.models import LogEntry
2524
from cryptography.hazmat.backends import default_backend
2625
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
@@ -1224,6 +1223,26 @@ def get_setting(setting):
12241223
return getattr(settings, setting)
12251224

12261225

1226+
def grade_product(crit, high, med, low):
1227+
health = 100
1228+
if crit > 0:
1229+
health = 40
1230+
health -= ((crit - 1) * 5)
1231+
if high > 0:
1232+
if health == 100:
1233+
health = 60
1234+
health -= ((high - 1) * 3)
1235+
if med > 0:
1236+
if health == 100:
1237+
health = 80
1238+
health -= ((med - 1) * 2)
1239+
if low > 0:
1240+
if health == 100:
1241+
health = 95
1242+
health -= low
1243+
return max(health, 5)
1244+
1245+
12271246
@dojo_model_to_id
12281247
@dojo_async_task(signature=True)
12291248
@app.task
@@ -1276,17 +1295,14 @@ def calculate_grade_internal(product, *args, **kwargs):
12761295
medium = severity_count["numerical_severity__count"]
12771296
elif severity_count["severity"] == "Low":
12781297
low = severity_count["numerical_severity__count"]
1279-
aeval = Interpreter()
1280-
aeval(system_settings.product_grade)
1281-
grade_product = f"grade_product({critical}, {high}, {medium}, {low})"
1282-
prod_numeric_grade = aeval(grade_product)
1283-
if prod_numeric_grade != product.prod_numeric_grade:
1284-
logger.debug("Updating product %s grade from %s to %s", product.id, product.prod_numeric_grade, prod_numeric_grade)
1285-
product.prod_numeric_grade = prod_numeric_grade
1298+
grade = grade_product(critical, high, medium, low)
1299+
if grade != product.prod_numeric_grade:
1300+
logger.debug("Updating product %s grade from %s to %s", product.id, product.prod_numeric_grade, grade)
1301+
product.prod_numeric_grade = grade
12861302
super(Product, product).save()
12871303
else:
12881304
# Use %s to safely handle None grades without formatter errors
1289-
logger.debug("Product %s grade %s is up to date", product.id, prod_numeric_grade)
1305+
logger.debug("Product %s grade %s is up to date", product.id, product.prod_numeric_grade)
12901306

12911307

12921308
def perform_product_grading(product):

unittests/test_importers_performance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,9 @@ def test_import_reimport_reimport_performance_pghistory_no_async_with_product_gr
310310
self.system_settings(enable_product_grade=True)
311311

312312
self._import_reimport_performance(
313-
expected_num_queries1=315,
313+
expected_num_queries1=320,
314314
expected_num_async_tasks1=8,
315-
expected_num_queries2=241,
315+
expected_num_queries2=246,
316316
expected_num_async_tasks2=19,
317317
expected_num_queries3=123,
318318
expected_num_async_tasks3=18,

0 commit comments

Comments
 (0)