Skip to content

Commit 97bb661

Browse files
committed
refinements
Signed-off-by: tdruez <tdruez@aboutcode.org>
1 parent ca67643 commit 97bb661

3 files changed

Lines changed: 6 additions & 23 deletions

File tree

product_portfolio/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ def attach_triage_data(self, product, page_obj):
13441344
product=product,
13451345
vulnerability_id__in=vulnerability_ids,
13461346
)
1347-
.primary_actions()
1347+
.highest_precedence()
13481348
.select_related("ruleset", "request")
13491349
)
13501350
for record in triage_records:

vulnerabilities/triage/admin.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,7 @@ def get_enabled_rules(self, obj):
126126
def get_changes_details(self, form):
127127
model_field_names = {field.name for field in TriageRuleset._meta.get_fields()}
128128
form.__dict__["changed_data"] = [
129-
field_name
130-
for field_name in form.changed_data
131-
if field_name in model_field_names
129+
field_name for field_name in form.changed_data if field_name in model_field_names
132130
]
133131
return super().get_changes_details(form)
134132

vulnerabilities/triage/models.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# See https://aboutcode.org for more information about AboutCode FOSS projects.
77
#
88

9-
from django.apps import apps
109
from django.db import models
1110
from django.db.models import OuterRef
1211
from django.db.models import Subquery
@@ -57,14 +56,9 @@ def __str__(self):
5756

5857
def apply_to_analysis(self, analysis):
5958
"""Copy non-blank preset fields onto the analysis instance (does not save)."""
60-
if self.state:
61-
analysis.state = self.state
62-
if self.justification:
63-
analysis.justification = self.justification
64-
if self.responses:
65-
analysis.responses = self.responses
66-
if self.detail:
67-
analysis.detail = self.detail
59+
for field_name in ("state", "justification", "responses", "detail"):
60+
if value := getattr(self, field_name):
61+
setattr(analysis, field_name, value)
6862
if self.is_reachable is not None:
6963
analysis.is_reachable = self.is_reachable
7064

@@ -84,7 +78,6 @@ class TriageRuleset(DataspacedModel):
8478
help_text=_("Action recommended when this ruleset's conditions are met."),
8579
)
8680
precedence = models.PositiveIntegerField(
87-
default=100,
8881
help_text=_(
8982
"When multiple rulesets are assigned to a product and produce different"
9083
" actions, the one with the highest precedence takes effect."
@@ -139,15 +132,7 @@ def __str__(self):
139132

140133

141134
class TriageRecordQuerySet(ProductSecuredQuerySet):
142-
def product_secured(self, user=None, perms="view_product"):
143-
"""Filter by product object permission through the direct product FK."""
144-
if not user:
145-
return self.none()
146-
Product = apps.get_model("product_portfolio", "Product")
147-
product_qs = Product.objects.get_queryset(user, perms)
148-
return self.filter(product__in=product_qs)
149-
150-
def primary_actions(self):
135+
def highest_precedence(self):
151136
"""
152137
Return one record per (vulnerability, product): the highest-precedence active ruleset
153138
that is explicitly assigned to the product via ProductTriageRuleset.

0 commit comments

Comments
 (0)