新增了完整的Confluence集成插件,包含以下核心功能: 1. 基础认证与配置管理,支持API Token和OAuth2两种认证方式 2. 评论去重、权限控制与提及解析 3. 知识库检索与页面内容处理 4. 评论收发、编辑删除与流式回复支持 5. 附件与页面标签管理 6. 内容属性存储与AI元数据管理 7. Webhook事件接收与处理 8. 完整的插件配置与状态检查
37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class ConfluenceCommentPolicy:
|
|
VALID_POLICIES = frozenset({"open", "pairing", "allowlist", "disabled"})
|
|
|
|
def __init__(self, policy: str = "open", allow_from: list[str] | None = None):
|
|
self._policy = policy if policy in self.VALID_POLICIES else "open"
|
|
self._allowlist: set[str] = set(allow_from or [])
|
|
|
|
def is_allowed(self, author_id: str) -> bool:
|
|
if self._policy == "disabled":
|
|
return False
|
|
if self._policy == "open":
|
|
return True
|
|
if self._policy == "allowlist":
|
|
if not self._allowlist:
|
|
logger.warning("Comment policy is 'allowlist' but allowlist is empty")
|
|
return False
|
|
return author_id in self._allowlist
|
|
return True
|
|
|
|
def add_to_allowlist(self, account_id: str):
|
|
self._allowlist.add(account_id)
|
|
|
|
def remove_from_allowlist(self, account_id: str):
|
|
self._allowlist.discard(account_id)
|
|
|
|
@property
|
|
def policy(self) -> str:
|
|
return self._policy
|
|
|
|
@property
|
|
def allowlist(self) -> frozenset[str]:
|
|
return frozenset(self._allowlist) |