ForcePilot/backend/package/yuxi/channel/extensions/zoomchat/security.py

48 lines
1.6 KiB
Python
Raw Normal View History

import logging
logger = logging.getLogger(__name__)
class ZoomSecurity:
def __init__(self):
self._dm_allowlist: set[str] = set()
self._group_allowlist: set[str] = set()
def resolve_dm_policy(self) -> dict:
return {"mode": "open", "allow_from": []}
def resolve_dm_policy_for_account(self, account: dict) -> dict:
mode = account.get("dm_policy", "open")
return {"mode": mode, "allow_from": account.get("allow_from", [])}
def resolve_group_policy_for_account(self, account: dict) -> dict:
mode = account.get("group_policy", "mentioned")
return {"mode": mode, "allow_from": account.get("allow_from", [])}
async def check_allowlist(self, peer_id: str, channel_type: str) -> bool:
if channel_type == "direct":
if not self._dm_allowlist:
return True
return peer_id in self._dm_allowlist
if not self._group_allowlist:
return True
return peer_id in self._group_allowlist
def load_allowlists(self, account: dict) -> None:
allow_from = account.get("allow_from", [])
self._dm_allowlist = set(allow_from)
self._group_allowlist = set(allow_from)
def load_dm_allowlist(self, peer_ids: list[str]) -> None:
self._dm_allowlist = set(peer_ids)
def load_group_allowlist(self, peer_ids: list[str]) -> None:
self._group_allowlist = set(peer_ids)
def is_valid_peer_id(self, peer_id: str) -> bool:
if not peer_id:
return False
if "@" in peer_id and "." in peer_id.split("@")[0]:
return True
return len(peer_id) > 4