-
-
Notifications
You must be signed in to change notification settings - Fork 525
feat: 插件权限控制精细到群聊 #1301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat: 插件权限控制精细到群聊 #1301
Conversation
## Sourcery 评审员指南
此 Pull Request 引入了组聊天级别的细粒度插件权限控制。它扩展了现有的平台兼容性设置,以包含特定于组的配置,允许管理员为单个组聊天启用或禁用插件。该实现涉及前端、API 端点、插件元数据和兼容性逻辑的更改。实施了缓存机制来优化权限检查过程。
#### 更新插件兼容性的顺序图
```mermaid
sequenceDiagram
participant PluginManager
participant StarMetadata
participant Config
PluginManager->>Config: Get plugin_enable_config
Config-->>PluginManager: Returns plugin_enable_config
loop For each plugin
PluginManager->>StarMetadata: update_plugin_compatibility(plugin_enable_config)
StarMetadata->>StarMetadata: Clear supported_platforms and group_permissions
StarMetadata->>StarMetadata: Update supported_platforms from plugin_enable_config
StarMetadata->>StarMetadata: Update group_permissions from config
end 事件处理期间检查插件权限的顺序图sequenceDiagram
participant Event
participant StarHandlerMetadata
participant StarMetadata
Event->>StarHandlerMetadata: is_enabled_for_platform(platform_id, group_id)
StarHandlerMetadata->>StarMetadata: Get plugin metadata
alt group_id is present
StarMetadata->>StarMetadata: Check group_permissions for group_id
alt group_id in group_permissions
StarMetadata-->>StarHandlerMetadata: Return group_permissions[group_id]
else group_id not in group_permissions
StarMetadata->>StarMetadata: Check supported_platforms for platform_id
StarMetadata-->>StarHandlerMetadata: Return supported_platforms[platform_id]
end
else group_id is not present
StarMetadata->>StarMetadata: Check supported_platforms for platform_id
StarMetadata-->>StarHandlerMetadata: Return supported_platforms[platform_id]
end
StarMetadata 的更新类图classDiagram
class StarMetadata {
name: str
desc: str
version: str
repo: str
supported_platforms: Dict[str, bool]
group_permissions: Dict[str, bool]
+update_plugin_compatibility(plugin_enable_config: dict) : None
}
note for StarMetadata "存储插件元数据,包括特定于组的权限。"
文件级别更改
提示和命令与 Sourcery 互动
自定义您的体验访问您的 仪表板 以:
获得帮助Original review guide in EnglishReviewer's Guide by SourceryThis pull request introduces fine-grained plugin permission control at the group chat level. It extends the existing platform compatibility settings to include group-specific configurations, allowing administrators to enable or disable plugins for individual group chats. The implementation involves changes to the frontend, API endpoints, plugin metadata, and compatibility logic. Caching mechanisms are implemented to optimize the permission checking process. Sequence Diagram for Updating Plugin CompatibilitysequenceDiagram
participant PluginManager
participant StarMetadata
participant Config
PluginManager->>Config: Get plugin_enable_config
Config-->>PluginManager: Returns plugin_enable_config
loop For each plugin
PluginManager->>StarMetadata: update_plugin_compatibility(plugin_enable_config)
StarMetadata->>StarMetadata: Clear supported_platforms and group_permissions
StarMetadata->>StarMetadata: Update supported_platforms from plugin_enable_config
StarMetadata->>StarMetadata: Update group_permissions from config
end
Sequence Diagram for Checking Plugin Permissions during Event ProcessingsequenceDiagram
participant Event
participant StarHandlerMetadata
participant StarMetadata
Event->>StarHandlerMetadata: is_enabled_for_platform(platform_id, group_id)
StarHandlerMetadata->>StarMetadata: Get plugin metadata
alt group_id is present
StarMetadata->>StarMetadata: Check group_permissions for group_id
alt group_id in group_permissions
StarMetadata-->>StarHandlerMetadata: Return group_permissions[group_id]
else group_id not in group_permissions
StarMetadata->>StarMetadata: Check supported_platforms for platform_id
StarMetadata-->>StarHandlerMetadata: Return supported_platforms[platform_id]
end
else group_id is not present
StarMetadata->>StarMetadata: Check supported_platforms for platform_id
StarMetadata-->>StarHandlerMetadata: Return supported_platforms[platform_id]
end
Updated Class Diagram for StarMetadataclassDiagram
class StarMetadata {
name: str
desc: str
version: str
repo: str
supported_platforms: Dict[str, bool]
group_permissions: Dict[str, bool]
+update_plugin_compatibility(plugin_enable_config: dict) : None
}
note for StarMetadata "Stores plugin metadata, including group-specific permissions."
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嘿 @zhx8702 - 我已经审查了你的更改 - 这里有一些反馈:
总体评论:
- 考虑添加更具体的错误处理和日志记录,以帮助调试权限问题。
- 前端代码引入了大量新代码 - 考虑将其分解为更小的组件。
以下是我在审查期间查看的内容
- 🟢 一般问题:一切看起来都很好
- 🟢 安全性:一切看起来都很好
- 🟢 测试:一切看起来都很好
- 🟡 复杂性:发现 1 个问题
- 🟢 文档:一切看起来都很好
帮助我更有用!请点击每个评论上的 👍 或 👎,我将使用反馈来改进你的评论。
Original comment in English
Hey @zhx8702 - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider adding more specific error handling and logging to help debug permission issues.
- The frontend code introduces a lot of new code - consider breaking it down into smaller components.
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
d3a122f
to
a34df84
Compare
修复了 #1281
Motivation
插件开关控制到群聊
Modifications
基于原先PlatformCompatibilityStage 扩展插件对于群聊的控制
前端配置入口设置在对话数据库的列表中,群聊类型有权限按钮。
platform_compatibility
重命名为plugin_compatibility
. 处理activated_handlers 调用is_enabled_for_platform
方法添加 platform_compatible Tag在
StarMetadata
新增group_permissions
字典 缓存插件 黑名单机制{group_id: bool}
,key为群聊ID,value为插件是否启用在处理链路中的过滤逻辑:
activated_handlers 过滤带了platform_compatible 的 tag
get_handlers_by_event_type
方法:集中过滤特定事件类型的处理器platform_id
或group_id
时,会调用is_enabled_for_platform
方法过滤不兼容的处理器only_activated=True
),会检查插件的activated
状态OnAstrBotLoadedEvent
事件类型会跳过平台兼容性检查is_enabled_for_platform
方法 新增group_id参数当平台配置或群聊插件权限配置更新时:
update_plugin_compatibility
方法会遍历所有插件,更新其平台兼容性设置 以及清除group_permissions
重新生成插件黑名单Check
Sourcery 总结
为群聊实现细粒度的插件权限控制,允许管理员为单个群聊启用或禁用特定插件。
新功能:
增强功能:
杂项:
platform_compatibility
重命名为plugin_compatibility
Original summary in English
Summary by Sourcery
Implement fine-grained plugin permission control for group chats, allowing administrators to enable or disable specific plugins for individual group chats
New Features:
Enhancements:
Chores: