66# See https://aboutcode.org for more information about AboutCode FOSS projects.
77#
88
9- from django .apps import apps
109from django .db import models
1110from django .db .models import OuterRef
1211from 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
141134class 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