From 910bc8dd8ca0df63d2cfb48308a96d6d8b14aa38 Mon Sep 17 00:00:00 2001 From: andrii-hantkovskyi <131773947+andrii-hantkovskyi@users.noreply.github.com> Date: Wed, 15 May 2024 18:47:51 +0300 Subject: [PATCH] refactor: [ACI-976] upgrade boolean values check in datarules (#169) Co-authored-by: Andrii --- credentials/apps/badges/models.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/credentials/apps/badges/models.py b/credentials/apps/badges/models.py index e79a01f4c..897b9e723 100644 --- a/credentials/apps/badges/models.py +++ b/credentials/apps/badges/models.py @@ -297,10 +297,25 @@ def apply(self, data: dict) -> bool: """ comparison_func = getattr(operator, self.operator, None) + if comparison_func: data_value = str(keypath(data, self.data_path)) - return comparison_func(data_value, self.value) + return comparison_func(data_value, self._value_to_bool()) return False + + def _value_to_bool(self): + """ + Converts the value to a boolean or returns the original value if it is not a boolean string. + """ + + TRUE_VALUES = ["True", "true", "Yes", "yes", "+"] + FALSE_VALUES = ["False", "false", "No", "no", "-"] + + if self.value in TRUE_VALUES: + return "True" + if self.value in FALSE_VALUES: + return "False" + return self.value class DataRule(AbstractDataRule):