feat: add project-scoped operations
This commit is contained in:
@@ -13,6 +13,7 @@ class Identity:
|
||||
project_id: str
|
||||
user_id: str
|
||||
can_write: bool
|
||||
project_code: str = ""
|
||||
|
||||
|
||||
def next_get(request: Request, path: str, params=None):
|
||||
@@ -42,8 +43,9 @@ def identity(request: Request) -> Identity:
|
||||
user_id = str(UUID(context["user_id"]))
|
||||
project_id = str(UUID(context["project_id"]))
|
||||
ensure(project_id == str(UUID(project)), "PROJECT_MISMATCH", "项目身份不一致", 403)
|
||||
ensure(context["network"] == request.app.state.settings.project_code,
|
||||
"PROJECT_NOT_CONFIGURED", "该项目不是本外围样板的数据项目", 403)
|
||||
project_code = context["network"]
|
||||
ensure(isinstance(project_code, str) and bool(project_code.strip()),
|
||||
"INVALID_AUTH_CONTEXT", "Next 项目身份不完整", 502)
|
||||
permissions = context["permissions"]
|
||||
ensure(isinstance(permissions, list) and "simulation.view" in permissions,
|
||||
"PERMISSION_DENIED", "没有样板读取权限", 403)
|
||||
@@ -51,4 +53,4 @@ def identity(request: Request) -> Identity:
|
||||
ensure(request.method == "GET" or can_write, "PERMISSION_DENIED", "没有样板修改权限", 403)
|
||||
except (KeyError, TypeError, ValueError) as exc:
|
||||
raise SampleFailure("INVALID_AUTH_CONTEXT", "Next 身份响应不完整", 502) from exc
|
||||
return Identity(project_id, user_id, can_write)
|
||||
return Identity(project_id, user_id, can_write, project_code)
|
||||
|
||||
Reference in New Issue
Block a user