refactor: unify user chain data port access

This commit is contained in:
jxxghp
2026-08-24 04:16:09 +08:00
parent 48e796cab7
commit a13c96d30b
6 changed files with 54 additions and 15 deletions
+3 -3
View File
@@ -8,7 +8,7 @@ import copy
from datetime import datetime
from typing import Any, Dict, List, Optional, Union
from app.application.chain.data import UserPortProxy as UserOper
from app.application.chain.data import get_chain_user_port
from app.domain.context import Context, MediaInfo, MusicInfo, TorrentInfo
from app.domain.meta.metabase import MetaBase
from app.foundation.identity import normalize_internal_user_id
@@ -168,7 +168,7 @@ class NotificationMixin:
# 是否已发送管理员标志
admin_sended = False
send_orignal = False
useroper = UserOper()
useroper = get_chain_user_port()
for action in actions:
send_message = copy.deepcopy(dispatch_message)
if action == "admin" and not admin_sended:
@@ -286,7 +286,7 @@ class NotificationMixin:
# 是否已发送管理员标志
admin_sended = False
send_orignal = False
useroper = UserOper()
useroper = get_chain_user_port()
for action in actions:
send_message = copy.deepcopy(dispatch_message)
if action == "admin" and not admin_sended:
+7 -3
View File
@@ -13,7 +13,7 @@ from app.application.messaging.media import (
media_interaction_manager,
)
from app.application.torrent import TorrentHelper
from app.application.chain.data import UserPortProxy as UserOper
from app.application.chain.data import get_chain_user_port
from app.domain import episode as episode_rules
from app.domain import title as title_rules
from app.domain.context import Context, MediaInfo
@@ -669,7 +669,9 @@ class MediaInteractionChain(ChainBase):
return
mp_name = (
UserOper().get_name(**{f"{channel.name.lower()}_userid": userid})
get_chain_user_port().get_name(
**{f"{channel.name.lower()}_userid": userid}
)
if channel
else None
)
@@ -980,7 +982,9 @@ class MediaInteractionChain(ChainBase):
note = None
mp_name = (
UserOper().get_name(**{f"{channel.name.lower()}_userid": userid})
get_chain_user_port().get_name(
**{f"{channel.name.lower()}_userid": userid}
)
if channel
else None
)
+4 -4
View File
@@ -4,7 +4,7 @@ from typing import Any, Literal, Optional, Tuple, Union
from app.chain import ChainBase
from app.application.security.token import get_password_hash, verify_password
from app.application.chain.data import UserPortProxy as UserOper
from app.application.chain.data import get_chain_user_port
from app.runtime.log import logger
from app.schemas.event import AuthCredentials
from app.schemas.event import AuthInterceptCredentials
@@ -116,7 +116,7 @@ class UserChain(ChainBase):
logger.info("密码认证失败,认证类型不匹配")
return False, PASSWORD_INVALID_CREDENTIALS_MESSAGE
user = UserOper().get_by_name(name=credentials.username)
user = get_chain_user_port().get_by_name(name=credentials.username)
if not user:
logger.info(f"密码认证失败,用户 {credentials.username} 不存在")
return False, PASSWORD_INVALID_CREDENTIALS_MESSAGE
@@ -144,7 +144,7 @@ class UserChain(ChainBase):
return False, "认证凭证无效"
# 检查是否因为用户被禁用
useroper = UserOper()
useroper = get_chain_user_port()
if credentials.username:
user = useroper.get_by_name(name=credentials.username)
if user and not user.is_active:
@@ -232,7 +232,7 @@ class UserChain(ChainBase):
return False
# 检查用户是否存在,如果不存在且当前为密码认证时则创建新用户
useroper = UserOper()
useroper = get_chain_user_port()
user = useroper.get_by_name(name=username)
if user:
# 如果用户存在,但是已经被禁用,则直接响应