First commit to the code repository

This commit is contained in:
Liujian committed 2025-07-20 22:38:52 +08:00
1 parent 692cdee407
commit 0c0dd1cb56
323 files changed
+45712

No files matched your search

@@ -0,0 +1,22 @@
from services.common.models.user import User
class UserUtils:
@staticmethod
def get_request_user(request) -> User:
"""Get user object from request"""
return request.scope.get("user")
@staticmethod
def get_request_user_id(request) -> str:
"""Get user ID from request"""
user = UserUtils.get_request_user(request)
if not user or not getattr(user, "id", None):
raise ValueError("User not found in request or user_id missing")
return user.id
@staticmethod
def is_admin(request) -> bool:
"""Check if current user is admin"""
user = UserUtils.get_request_user(request)
return user and user.role_id == 1 if user else False