Evaluate notification conditions for a user. All conditions must pass (AND logic).
(conditions: list[str] | str | None, user)
| 158 | # ───────────────────────────── |
| 159 | |
| 160 | def evaluate_conditions(conditions: list[str] | str | None, user) -> bool: |
| 161 | """ |
| 162 | Evaluate notification conditions for a user. |
| 163 | All conditions must pass (AND logic). |
| 164 | """ |
| 165 | if not conditions: |
| 166 | return True |
| 167 | |
| 168 | # Normalize to list |
| 169 | if isinstance(conditions, str): |
| 170 | conditions = [conditions] |
| 171 | |
| 172 | for condition in conditions: |
| 173 | if condition not in CONDITION_CHECKS: |
| 174 | logger.warning(f"Unknown condition: {condition}") |
| 175 | continue |
| 176 | |
| 177 | try: |
| 178 | if not CONDITION_CHECKS[condition](user): |
| 179 | return False |
| 180 | except Exception as e: |
| 181 | logger.error(f"Error evaluating condition {condition}: {e}") |
| 182 | # On error, skip this condition (fail open) |
| 183 | continue |
| 184 | |
| 185 | return True |
| 186 | |
| 187 | |
| 188 | def should_show_notification(notification_data: dict, user) -> bool: |
no outgoing calls
no test coverage detected