新增 Zalo OA、Zoom Chat、Zulip 三个渠道扩展。 Zalo OA 渠道扩展主要模块:sidecar_client, config, gateway, outbound, streaming, pairing, security, auth, dedupe, directory, monitor, status, session, reactions, tools Zoom Chat 渠道扩展主要模块:config, gateway, webhook, outbound, streaming, pairing, security, crypto, dedupe, actions, media, mentions, monitor, status, session, reactions, threading Zulip 渠道扩展主要模块:client, config, gateway, outbound, streaming, pairing, security, monitor, status
48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
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
|