mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-20 20:39:55 +00:00
fix(中间件): 修复演示环境中间件的权限检查逻辑
修改演示环境中间件的权限检查流程,先执行请求再检查用户权限,避免误拦截合法请求
This commit is contained in:
@@ -88,8 +88,21 @@ class DemoEnvMiddleware(BaseHTTPMiddleware):
|
||||
path in settings.DEMO_WHITE_LIST_PATH or
|
||||
(user_username and user_username in settings.DEMO_USER_WHITE_LIST)):
|
||||
return await call_next(request)
|
||||
|
||||
else:
|
||||
return ErrorResponse(msg="演示环境,禁止操作")
|
||||
try:
|
||||
response = await call_next(request)
|
||||
|
||||
# 现在检查用户是否有权限执行操作
|
||||
user_username = request.scope.get("user_username")
|
||||
if user_username and user_username not in settings.DEMO_USER_WHITE_LIST:
|
||||
# 如果用户没有权限,返回错误响应
|
||||
return ErrorResponse(msg="演示环境,禁止操作")
|
||||
|
||||
return response
|
||||
except Exception as e:
|
||||
# 处理可能的异常
|
||||
raise e
|
||||
|
||||
return await call_next(request)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user