refactor: unify service configuration boundary

This commit is contained in:
jxxghp
2026-08-24 05:12:21 +08:00
parent 52c5c14f87
commit cb3c5f008f
19 changed files with 174 additions and 53 deletions
+23 -3
View File
@@ -1,9 +1,9 @@
from typing import Optional
from app.application.service import ServiceBaseHelper
from app.schemas.system import NotificationConf
from app.application.service import ServiceBaseHelper, get_service_configs
from app.schemas.system import NotificationConf, NotificationSwitchConf
from app.schemas.system import ServiceInfo
from app.schemas.types import ModuleType, SystemConfigKey
from app.schemas.types import MessageType, ModuleType, SystemConfigKey
class NotificationHelper(ServiceBaseHelper[NotificationConf]):
@@ -33,3 +33,23 @@ class NotificationHelper(ServiceBaseHelper[NotificationConf]):
"""
service = service or self.get_service(name=name)
return bool(service and service.type == service_type)
def get_notification_configs(
include_disabled: bool = False,
) -> list[NotificationConf]:
"""返回通知配置列表,并按调用方需要决定是否包含禁用项。"""
return list(
NotificationHelper().get_configs(include_disabled=include_disabled).values()
)
def get_notification_switch(mtype: MessageType) -> Optional[str]:
"""返回指定通知场景的目标范围。"""
for switch in get_service_configs(
SystemConfigKey.NotificationSwitchs,
NotificationSwitchConf,
):
if switch.type == mtype.value:
return switch.action
return None