mirror of
https://github.com/langgenius/dify.git
synced 2026-06-17 06:21:07 +08:00
31 lines
931 B
Python
31 lines
931 B
Python
from collections.abc import Callable
|
|
from functools import wraps
|
|
|
|
from core.rbac import RBACPermission, RBACResourceScope
|
|
|
|
__all__ = ["RBACPermission", "RBACResourceScope", "rbac_permission_required"]
|
|
|
|
|
|
def rbac_permission_required[**P, R](
|
|
resource_type: RBACResourceScope,
|
|
scene: RBACPermission,
|
|
*,
|
|
resource_required: bool = True,
|
|
) -> Callable[[Callable[P, R]], Callable[P, R]]:
|
|
"""Check enterprise RBAC permissions for the current user.
|
|
|
|
Args:
|
|
resource_type: The :class:`RBACResourceScope` member (app/dataset/workspace).
|
|
scene: The :class:`RBACPermission` permission point.
|
|
resource_required: Whether a concrete resource ID is required.
|
|
"""
|
|
|
|
def decorator(view: Callable[P, R]) -> Callable[P, R]:
|
|
@wraps(view)
|
|
def decorated(*args: P.args, **kwargs: P.kwargs) -> R:
|
|
return view(*args, **kwargs)
|
|
|
|
return decorated
|
|
|
|
return decorator
|