from __future__ import annotations import logging logger = logging.getLogger(__name__) class RingCentralSecurityAdapter: def resolve_dm_policy(self) -> dict: return {"mode": "pairing", "allow_from": []} def check_allowlist(self, sender_id: str, account) -> bool: if not account: return True allow_from = account.dm_allow_from if hasattr(account, "dm_allow_from") else [] if not allow_from: return True return sender_id in allow_from def evaluate(self, chat_type: str, sender_id: str, text: str, account) -> tuple[bool, str]: if chat_type == "direct": if not account: return True, "ok" if not getattr(account, "dm_enabled", True): return False, "dm_disabled" dm_policy = getattr(account, "dm_policy", "pairing") if dm_policy == "disabled": return False, "dm_disabled" if dm_policy == "allowlist" and not self.check_allowlist(sender_id, account): return False, "sender_not_in_allowlist" if dm_policy == "pairing": return True, "pairing_check" elif chat_type in ("group", "team"): if not account: return True, "ok" group_policy = getattr(account, "group_policy", "allowlist") if group_policy == "disabled": return False, "group_disabled" if getattr(account, "require_mention", True) and "@!" not in text: return False, "mention_required" return True, "ok" def collect_warnings(self, config: dict, account_id: str | None = None) -> list[str]: warnings = [] rc_config = config.get("channels", {}).get("ringcentral", {}) group_policy = rc_config.get("group_policy", "allowlist") if group_policy == "open": warnings.append( "Group policy is 'open' - any RingCentral group can trigger the bot. " "Consider using 'allowlist' for production." ) dm_policy = rc_config.get("dm_policy", "pairing") if dm_policy == "open": warnings.append( "DM policy is 'open' - anyone can DM the bot. Consider using 'pairing' or 'allowlist' for production." ) return warnings