wbcompliance 1.59.11__py2.py3-none-any.whl → 1.59.13__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -117,18 +117,26 @@ class AbstractRuleBackend:
117
117
  """
118
118
  raise NotImplementedError()
119
119
 
120
- def check_rule(self, *dto_args, **kwargs) -> Generator[IncidentResult, None, None]:
120
+ def check_rule(
121
+ self, *dto_args, ignore_breached_objects: Iterable[models.Model] | None = None, **kwargs
122
+ ) -> Generator[IncidentResult, None, None]:
121
123
  """
122
124
  Build and Check the rule against the instantiated backend given its attributes
123
125
 
124
126
  Returns:
125
127
  yield the breach object, its string representation, the incident report and the severity as IncidentResult
126
128
  """
129
+ if not ignore_breached_objects:
130
+ ignore_breached_objects = []
127
131
  if not dto_args:
128
132
  # We build the data transfer object if it is not provided.
129
133
  dto_args = self._build_dto_args()
130
134
  if any(dto_args):
131
- yield from self._process_dto(*dto_args, **kwargs)
135
+ incident = list(self._process_dto(*dto_args, **kwargs))
136
+ yield from filter(
137
+ lambda incident: incident.breached_object not in ignore_breached_objects,
138
+ incident,
139
+ )
132
140
 
133
141
  def is_passive_evaluation_valid(self) -> bool:
134
142
  """
@@ -159,7 +159,7 @@ class RiskCheck(ComplexToStringMixin, WBModel):
159
159
  )
160
160
 
161
161
  def evaluate(
162
- self, *explicit_dto, override_incident: bool = False, ignore_informational_threshold: bool = False
162
+ self, *explicit_dto, override_incident: bool = False, ignore_informational_threshold: bool = False, **kwargs
163
163
  ) -> list[models.Model]:
164
164
  """
165
165
  Evaluate the check and returns tuple of incidents information
@@ -177,7 +177,7 @@ class RiskCheck(ComplexToStringMixin, WBModel):
177
177
  self.status = self.CheckStatus.SUCCESS
178
178
  incidents = []
179
179
  report_template = Template(self.rule.rule_backend.incident_report_template)
180
- for incident_result in rule_backend.check_rule(*explicit_dto):
180
+ for incident_result in rule_backend.check_rule(*explicit_dto, **kwargs):
181
181
  if (
182
182
  ignore_informational_threshold
183
183
  and incident_result.severity.is_ignorable
@@ -296,11 +296,25 @@ class RiskCheck(ComplexToStringMixin, WBModel):
296
296
  return "id"
297
297
 
298
298
 
299
- @shared_task(queue=Queue.BACKGROUND.value)
299
+ @shared_task(queue=Queue.HIGH_PRIORITY.value)
300
300
  def evaluate_as_task(
301
- check_id: int, *dto, override_incident: bool = False, ignore_informational_threshold: bool = False
301
+ check_id: int,
302
+ *dto,
303
+ override_incident: bool = False,
304
+ ignore_informational_threshold: bool = False,
305
+ ignore_breached_object_content_types: list[tuple[int, int]] | None = None,
302
306
  ):
307
+ if ignore_breached_object_content_types:
308
+ ignore_breached_objects = [
309
+ ContentType.objects.get(id=r[1]).get_object_for_this_type(id=r[0])
310
+ for r in ignore_breached_object_content_types
311
+ ]
312
+ else:
313
+ ignore_breached_objects = []
303
314
  check = RiskCheck.all_objects.get(id=check_id)
304
315
  check.evaluate(
305
- *dto, override_incident=override_incident, ignore_informational_threshold=ignore_informational_threshold
316
+ *dto,
317
+ override_incident=override_incident,
318
+ ignore_informational_threshold=ignore_informational_threshold,
319
+ ignore_breached_objects=ignore_breached_objects,
306
320
  )
@@ -1,5 +1,5 @@
1
1
  from datetime import date
2
- from typing import Any
2
+ from typing import Any, Iterable
3
3
 
4
4
  from django.contrib.contenttypes.models import ContentType
5
5
  from django.db import models, transaction
@@ -84,7 +84,17 @@ class RiskCheckMixin(models.Model):
84
84
  return status
85
85
  return RiskCheck.CheckStatus.SUCCESS
86
86
 
87
- def evaluate_active_rules(self, evaluation_date: date, *dto, asynchronously: bool = True):
87
+ def evaluate_active_rules(
88
+ self,
89
+ evaluation_date: date,
90
+ *dto,
91
+ asynchronously: bool = True,
92
+ ignore_breached_objects: Iterable[models.Model] | None = None,
93
+ ):
94
+ # serialize the ignore breached object list into a (id, content_type.id) list of tuple
95
+ ignore_breached_object_content_types = [
96
+ (o.id, ContentType.objects.get_for_model(o).id) for o in ignore_breached_objects
97
+ ]
88
98
  for rule in RiskRule.objects.get_active_rules_for_object(self.checked_object):
89
99
  check = RiskCheck.all_objects.update_or_create(
90
100
  rule=rule,
@@ -98,11 +108,20 @@ class RiskCheckMixin(models.Model):
98
108
  if asynchronously:
99
109
  transaction.on_commit(
100
110
  lambda check_id=check.id: evaluate_as_task.delay(
101
- check_id, *dto, override_incident=True, ignore_informational_threshold=True
111
+ check_id,
112
+ *dto,
113
+ override_incident=True,
114
+ ignore_informational_threshold=True,
115
+ ignore_breached_object_content_types=ignore_breached_object_content_types,
102
116
  )
103
117
  )
104
118
  else:
105
- check.evaluate(*dto, override_incident=True, ignore_informational_threshold=True)
119
+ check.evaluate(
120
+ *dto,
121
+ override_incident=True,
122
+ ignore_informational_threshold=True,
123
+ ignore_breached_objects=ignore_breached_objects,
124
+ )
106
125
 
107
126
  class Meta:
108
127
  abstract = True
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: wbcompliance
3
- Version: 1.59.11
3
+ Version: 1.59.13
4
4
  Summary: A workbench module for managing compliance.
5
5
  Author-email: Christopher Wittlinger <c.wittlinger@stainly.com>
6
6
  Requires-Dist: wbcore
@@ -56,11 +56,11 @@ wbcompliance/models/compliance_task.py,sha256=V0gFzkmBlLk2lA0CuMbvObn31M1QL11fZG
56
56
  wbcompliance/models/compliance_type.py,sha256=uf48Nl-dqyXOse8pAO7Rq7uzPNvtk955HPHRCKX4m-c,4830
57
57
  wbcompliance/models/enums.py,sha256=id1m8trG7b6Sw3Sa9VrLgD104GC2nG9A8ngJzaRqIIQ,424
58
58
  wbcompliance/models/risk_management/__init__.py,sha256=DJXoHheA5REDpPYP0uyRmFWyNKP-ir_z5YB61CN6N-E,247
59
- wbcompliance/models/risk_management/backend.py,sha256=pbszChXMxA36JjK0nIkrz0k7w9ImKUTGMVlokgA1R-w,4736
60
- wbcompliance/models/risk_management/checks.py,sha256=8puXRaVzmerF1tkWHi1MIxNewe-Io0Ux0iU7EleYOdY,12206
59
+ wbcompliance/models/risk_management/backend.py,sha256=EsGOlBIDTVJdZzCYtFmRiL8sUc0LDQJebHq9mwR_Xm4,5061
60
+ wbcompliance/models/risk_management/checks.py,sha256=drBNhT7kj7TA1EclKX9jpPp-IycNcHvjj3xZsbKqB2E,12670
61
61
  wbcompliance/models/risk_management/dispatch.py,sha256=cLi63vSGbk9xhCoVgr4UmVk2kfYmGiyohKINSvCodb0,1423
62
62
  wbcompliance/models/risk_management/incidents.py,sha256=9BJP6N2Qbpach7ObymZ1Pz5ih0cLqrzXI9fLfYGb-d4,24382
63
- wbcompliance/models/risk_management/mixins.py,sha256=KsdjpM1Cl235z8h57USVcYSBKtO2VRH1S0FCuJOEMH0,3762
63
+ wbcompliance/models/risk_management/mixins.py,sha256=vitLClx1QwmhooXselB_MqNoLbxMRp-uNQKsvHDooj8,4449
64
64
  wbcompliance/models/risk_management/rules.py,sha256=26zanw7maoi-ODJoDj2FLu8PCN5i2dI9J6RU5QsJ9uU,25917
65
65
  wbcompliance/serializers/__init__.py,sha256=OhRIuUrexqQePCISpu-BKry9dfioYGfpO8RwlcwhHtI,1122
66
66
  wbcompliance/serializers/compliance_form.py,sha256=OxPILlup_CP4Qwvu864oMqz7QUZsk2QOkOGFifWP3gM,11615
@@ -139,6 +139,6 @@ wbcompliance/viewsets/titles/risk_managment/checks.py,sha256=47DEQpj8HBSa-_TImW-
139
139
  wbcompliance/viewsets/titles/risk_managment/incidents.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
140
140
  wbcompliance/viewsets/titles/risk_managment/rules.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
141
141
  wbcompliance/viewsets/titles/risk_managment/tables.py,sha256=x_9mr6JWZ9GVNAEvfdNCeFZtGGYSG0-sXrR9pwTyocU,256
142
- wbcompliance-1.59.11.dist-info/METADATA,sha256=Jdb0_bQcN5TPdYdbRL2OQYcpUWaTgCNLydKytv_s8w4,197
143
- wbcompliance-1.59.11.dist-info/WHEEL,sha256=aha0VrrYvgDJ3Xxl3db_g_MDIW-ZexDdrc_m-Hk8YY4,105
144
- wbcompliance-1.59.11.dist-info/RECORD,,
142
+ wbcompliance-1.59.13.dist-info/METADATA,sha256=mabQUpEGTu2bqj1jYwN2kx8USHcQNJq9qG1cmNzyq3c,197
143
+ wbcompliance-1.59.13.dist-info/WHEEL,sha256=aha0VrrYvgDJ3Xxl3db_g_MDIW-ZexDdrc_m-Hk8YY4,105
144
+ wbcompliance-1.59.13.dist-info/RECORD,,