@@ -172,41 +172,12 @@ def cve(self):
172172 return alias
173173
174174 def add_affected (self , instances ):
175- """
176- Assign the ``instances`` (Package, Component, or Product) as affected by this
177- vulnerability.
178- """
179- from component_catalog .models import Component
180- from component_catalog .models import Package
181- from product_portfolio .models import Product
182-
183- if not isinstance (instances , list ):
175+ """Assign the ``instances`` (Package or Product) as affected by this vulnerability."""
176+ if not isinstance (instances , (list , tuple , models .QuerySet )):
184177 instances = [instances ]
185178
186179 for instance in instances :
187- if isinstance (instance , Package ):
188- self .add_affected_packages ([instance ])
189- if isinstance (instance , Component ):
190- self .add_affected_components ([instance ])
191- if isinstance (instance , Product ):
192- self .add_affected_products ([instance ])
193-
194- def add_affected_packages (self , packages ):
195- """Assign the ``packages`` as affected by this vulnerability."""
196- through_defaults = {"dataspace_id" : self .dataspace_id }
197- self .affected_packages .add (* packages , through_defaults = through_defaults )
198-
199- def add_affected_components (self , components ):
200- """Assign the ``components`` as affected by this vulnerability."""
201- through_defaults = {"dataspace_id" : self .dataspace_id }
202- self .affected_components .add (* components , through_defaults = through_defaults )
203-
204- def add_affected_products (self , products ):
205- """Assign the ``products`` as affected by this vulnerability."""
206- through_defaults = {"dataspace_id" : self .dataspace_id }
207- self .affected_products .add (* products , through_defaults = through_defaults )
208- for product in products :
209- product .update_risk_score ()
180+ instance .add_affected_by (vulnerability = self )
210181
211182 @classmethod
212183 def create_from_data (cls , dataspace , data , validate = False , affecting = None ):
0 commit comments