File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -50,13 +50,13 @@ def evaluate_rule(policy_rule, product):
5050 return None
5151
5252
53- def evaluate_rules (dataspace , product ):
53+ def evaluate_rules (product ):
5454 """
5555 Evaluate all active PolicyRules for the given product.
5656 Returns the list of active ProductPolicyViolation instances.
5757 """
5858 violations = []
59- for policy_rule in PolicyRule .objects .scope (dataspace ).active ():
59+ for policy_rule in PolicyRule .objects .scope (product . dataspace ).active ():
6060 violation = evaluate_rule (policy_rule , product )
6161 if violation :
6262 violations .append (violation )
Original file line number Diff line number Diff line change 1+ #
2+ # Copyright (c) nexB Inc. and others. All rights reserved.
3+ # DejaCode is a trademark of nexB Inc.
4+ # SPDX-License-Identifier: AGPL-3.0-only
5+ # See https://github.com/aboutcode-org/dejacode for support or download.
6+ # See https://aboutcode.org for more information about AboutCode FOSS projects.
7+ #
8+
9+ from django .apps import apps
10+
11+ from django_rq import job
12+
13+ from policy .engine import evaluate_rules
14+
15+
16+ @job
17+ def evaluate_product_rules_task (product_uuid ):
18+ """Evaluate all active PolicyRules for the given product UUID."""
19+ Product = apps .get_model ("product_portfolio" , "product" )
20+
21+ try :
22+ product = Product .objects .select_related ("dataspace" ).get (uuid = product_uuid )
23+ except Product .DoesNotExist :
24+ return
25+
26+ evaluate_rules (product )
27+
28+
29+ @job
30+ def evaluate_all_products_rules_task ():
31+ """Enqueue evaluate_product_rules_task for every product."""
32+ Product = apps .get_model ("product_portfolio" , "product" )
33+
34+ for product in Product .objects .select_related ("dataspace" ).all ():
35+ evaluate_product_rules_task .delay (product_uuid = product .uuid )
You can’t perform that action at this time.
0 commit comments