Skip to content

Commit

Permalink
refactor: [ACI-976] upgrade boolean values check in datarules
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii committed May 15, 2024
1 parent b557499 commit acd21b2
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion credentials/apps/badges/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "+", "1"]
FALSE_VALUES = ["False", "false", "No", "no", "-", "0"]

if self.value in TRUE_VALUES:
return "True"
if self.value in FALSE_VALUES:
return "False"
return self.value


class DataRule(AbstractDataRule):
Expand Down

0 comments on commit acd21b2

Please sign in to comment.