ForcePilot/backend/package/yuxi/channel/extensions/workplace/security.py
Kris 7215418610 feat(channel): 添加企业微信、微博、WhatsApp 和 Workplace 渠道扩展
新增企业微信、微博、WhatsApp、Workplace 四个渠道扩展。

企业微信渠道扩展主要模块:config, gateway, webhook, webhook_bot, outbound, streaming, pairing, security, crypto, dedupe, persistent_dedupe, card, directory, events, externalcontact, media, mentions, menu, message, oauth, status

微博渠道扩展主要模块:config, gateway, webhook, outbound, streaming, pairing, security, dedupe, passive_reply, broadcast, message, menu, media, subscription, template, status

WhatsApp 渠道扩展主要模块:config, gateway, webhook, outbound, streaming, pairing, security, dedupe, actions, monitor, status

Workplace 渠道扩展主要模块:config, gateway, webhook, outbound, streaming, pairing, security, dedupe, actions, challenge, groups, media, mentions, menu, monitor, persona, quick_reply, signature, subscriptions, template, threading, users, status
2026-05-21 12:01:56 +08:00

46 lines
1.3 KiB
Python

import logging
logger = logging.getLogger(__name__)
POLICY_OPEN = "open"
POLICY_PAIRING = "pairing"
POLICY_ALLOWLIST = "allowlist"
POLICY_DISABLED = "disabled"
VALID_POLICIES = {POLICY_OPEN, POLICY_PAIRING, POLICY_ALLOWLIST, POLICY_DISABLED}
class WorkplaceSecurity:
DM_POLICIES = frozenset(["open", "pairing", "allowlist", "disabled"])
@staticmethod
def resolve_dm_policy() -> dict:
return {"mode": "pairing", "allow_from": []}
@staticmethod
async def check_allowlist(peer_id: str, channel_type: str) -> bool:
from yuxi.channel.extensions.workplace.config import WorkplaceConfigAdapter
adapter = WorkplaceConfigAdapter()
account = await adapter.resolve_account("default")
policy = account.get("dm_policy", POLICY_PAIRING)
if policy == POLICY_OPEN:
return True
if policy == POLICY_DISABLED:
logger.info("Workplace DM disabled, rejecting peer_id=%s", peer_id)
return False
allow_from = account.get("allow_from", [])
if not allow_from:
if policy == POLICY_ALLOWLIST:
return False
return True
if peer_id in allow_from:
return True
logger.info("Workplace allowlist check failed for peer_id=%s", peer_id)
return False