fix(agent-assets): allow admin access to platform rules
This commit is contained in:
@@ -33,11 +33,19 @@ class AgentAssetAccessScope:
|
||||
@classmethod
|
||||
def from_user(cls, current_user: CurrentUserContext) -> AgentAssetAccessScope:
|
||||
tenant_id = str(current_user.tenant_id or "").strip()
|
||||
if not tenant_id or tenant_id == AGENT_ASSET_PLATFORM_TENANT_ID:
|
||||
is_platform_admin = bool(current_user.is_admin)
|
||||
if not tenant_id or (
|
||||
tenant_id == AGENT_ASSET_PLATFORM_TENANT_ID and not is_platform_admin
|
||||
):
|
||||
raise PermissionError("当前登录会话缺少有效租户。")
|
||||
return cls(tenant_id=tenant_id, is_platform_admin=bool(current_user.is_admin))
|
||||
return cls(tenant_id=tenant_id, is_platform_admin=is_platform_admin)
|
||||
|
||||
def visibility_clause(self, model: Any) -> Any:
|
||||
if self.tenant_id == AGENT_ASSET_PLATFORM_TENANT_ID:
|
||||
return and_(
|
||||
model.scope == AGENT_ASSET_PLATFORM_SCOPE,
|
||||
model.tenant_id == AGENT_ASSET_PLATFORM_TENANT_ID,
|
||||
)
|
||||
return or_(
|
||||
and_(
|
||||
model.scope == AGENT_ASSET_PLATFORM_SCOPE,
|
||||
|
||||
Reference in New Issue
Block a user