from __future__ import annotations import logging from yuxi.channel.protocols import SecurityProtocol logger = logging.getLogger(__name__) class JiraSecurity(SecurityProtocol): def __init__(self): self._allowed_projects: set[str] = set() def configure(self, allowed_projects: list[str]): self._allowed_projects = set(p.upper() for p in allowed_projects) def is_project_allowed(self, project_key: str) -> bool: if not self._allowed_projects: return True return project_key.upper() in self._allowed_projects def is_self_authored(self, author_account_id: str, bot_account_id: str) -> bool: return author_account_id == bot_account_id def is_ai_comment(self, properties: list[dict]) -> bool: for prop in properties: if prop.get("key") == "ai.agent": return True return False def is_self_changelog(self, changelog_items: list[dict], bot_account_id: str) -> bool: for item in changelog_items: author = item.get("author", {}) if author.get("accountId") == bot_account_id: return True return False async def check_allowlist(self, peer_id: str, channel_type: str) -> bool: return True def resolve_dm_policy(self) -> dict: return {"mode": "open", "allow_from": []} def apply_config_fixes(self, config: dict) -> dict: return config def collect_warnings(self, config: dict, account_id: str | None = None, account: dict | None = None) -> list[str]: warnings = [] if not account: return warnings if not account.get("allowed_projects"): warnings.append("未设置 allowedProjects — Bot 将响应所有项目的 Issue") return warnings def collect_audit_findings( self, config: dict, account_id: str | None = None, account: dict | None = None, source_config: dict | None = None, ordered_account_ids: list[str] | None = None, has_explicit_account_path: bool = False, ) -> list[dict]: return []