fix: add return type annotation to auth decorators (#32699)

Co-authored-by: root <root@DESKTOP-KQLO90N>
Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
tda
2026-03-01 16:19:33 +08:00
committed by GitHub
parent cfdf16c49e
commit 4b8a02cf25
2 changed files with 8 additions and 6 deletions

View File

@ -36,9 +36,9 @@ ERROR_MSG_INVALID_ENCRYPTED_DATA = "Invalid encrypted data"
ERROR_MSG_INVALID_ENCRYPTED_CODE = "Invalid encrypted code" ERROR_MSG_INVALID_ENCRYPTED_CODE = "Invalid encrypted code"
def account_initialization_required(view: Callable[P, R]): def account_initialization_required(view: Callable[P, R]) -> Callable[P, R]:
@wraps(view) @wraps(view)
def decorated(*args: P.args, **kwargs: P.kwargs): def decorated(*args: P.args, **kwargs: P.kwargs) -> R:
# check account initialization # check account initialization
current_user, _ = current_account_with_tenant() current_user, _ = current_account_with_tenant()
if current_user.status == AccountStatus.UNINITIALIZED: if current_user.status == AccountStatus.UNINITIALIZED:
@ -214,9 +214,9 @@ def cloud_utm_record(view: Callable[P, R]):
return decorated return decorated
def setup_required(view: Callable[P, R]): def setup_required(view: Callable[P, R]) -> Callable[P, R]:
@wraps(view) @wraps(view)
def decorated(*args: P.args, **kwargs: P.kwargs): def decorated(*args: P.args, **kwargs: P.kwargs) -> R:
# check setup # check setup
if ( if (
dify_config.EDITION == "SELF_HOSTED" dify_config.EDITION == "SELF_HOSTED"

View File

@ -13,6 +13,8 @@ from libs.token import check_csrf_token
from models import Account from models import Account
if TYPE_CHECKING: if TYPE_CHECKING:
from flask.typing import ResponseReturnValue
from models.model import EndUser from models.model import EndUser
@ -38,7 +40,7 @@ P = ParamSpec("P")
R = TypeVar("R") R = TypeVar("R")
def login_required(func: Callable[P, R]): def login_required(func: Callable[P, R]) -> Callable[P, R | ResponseReturnValue]:
""" """
If you decorate a view with this, it will ensure that the current user is If you decorate a view with this, it will ensure that the current user is
logged in and authenticated before calling the actual view. (If they are logged in and authenticated before calling the actual view. (If they are
@ -73,7 +75,7 @@ def login_required(func: Callable[P, R]):
""" """
@wraps(func) @wraps(func)
def decorated_view(*args: P.args, **kwargs: P.kwargs): def decorated_view(*args: P.args, **kwargs: P.kwargs) -> R | ResponseReturnValue:
if request.method in EXEMPT_METHODS or dify_config.LOGIN_DISABLED: if request.method in EXEMPT_METHODS or dify_config.LOGIN_DISABLED:
pass pass
elif current_user is not None and not current_user.is_authenticated: elif current_user is not None and not current_user.is_authenticated: