from __future__ import annotations import logging from enum import StrEnum logger = logging.getLogger(__name__) class DmPolicyMode(StrEnum): OPEN = "open" PAIRING = "pairing" ALLOWLIST = "allowlist" DISABLED = "disabled" class GroupPolicyMode(StrEnum): OPEN = "open" ALLOWLIST = "allowlist" DISABLED = "disabled" def check_dm_access(peer_id: str, policy: str, allowlist: list[str]) -> bool: if policy == DmPolicyMode.OPEN: return True if policy == DmPolicyMode.DISABLED: return False if policy == DmPolicyMode.ALLOWLIST or policy == DmPolicyMode.PAIRING: return peer_id in allowlist or "*" in allowlist return True def check_group_access(group_id: str, policy: str, allowlist: list[str]) -> bool: if policy == GroupPolicyMode.OPEN: return True if policy == GroupPolicyMode.DISABLED: return False if policy == GroupPolicyMode.ALLOWLIST: return group_id in allowlist or "*" in allowlist return True