32 lines
979 B
Python
32 lines
979 B
Python
|
|
from yuxi.channel.extensions.wecom.types import WeComAccount
|
||
|
|
|
||
|
|
|
||
|
|
class WeComSecurity:
|
||
|
|
def __init__(self, account: WeComAccount):
|
||
|
|
self._account = account
|
||
|
|
self._allowlist: list[str] = list(account.allow_from or [])
|
||
|
|
|
||
|
|
def resolve_dm_policy(self) -> dict:
|
||
|
|
return {
|
||
|
|
"mode": self._account.dm_policy,
|
||
|
|
"allow_from": self._allowlist,
|
||
|
|
}
|
||
|
|
|
||
|
|
def resolve_group_policy(self) -> dict:
|
||
|
|
return {
|
||
|
|
"mode": self._account.group_policy,
|
||
|
|
}
|
||
|
|
|
||
|
|
def check_allowlist(self, peer_id: str, channel_type: str = "direct") -> bool:
|
||
|
|
if channel_type == "group":
|
||
|
|
return True
|
||
|
|
return peer_id in self._allowlist
|
||
|
|
|
||
|
|
def add_to_allowlist(self, peer_id: str) -> None:
|
||
|
|
if peer_id not in self._allowlist:
|
||
|
|
self._allowlist.append(peer_id)
|
||
|
|
|
||
|
|
def remove_from_allowlist(self, peer_id: str) -> None:
|
||
|
|
if peer_id in self._allowlist:
|
||
|
|
self._allowlist.remove(peer_id)
|