feat: workspace CRUD at platform scope + drop audit_logs
新增系统管理模块 /api/v1/platform/*: - workspace 实体 CRUD(创建/列表/详情/更新/软删除) - workspace 成员 CRUD(添加/列表/更新/移除) - SystemAdminContext 依赖,仅 platform_role_id 指向 admin 角色的用户可访问 - /api/v1/auth/me 与 /auth/login 增 is_system_admin 派生字段 - 不变量:每个 workspace 至少保留一个 admin;系统管理员无法自我移除成员 - 软删除 workspace 级联软删除其成员 清理 audit_logs(无运行时写入,纯死特性): - baseline 移除 audit_logs 建表与三索引(20 → 19 tables) - 删除 AuditLogs 模型定义与 __init__.py 导出 - 清理 migrate_system_json / migrate_legacy_workspaces 中的 audit 写入与回填代码 API.md 增 §七系统管理,§七/§八/§九 顺延为 §八/§九/§十,附录 A/B 同步更新。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
c263ae6a5f
commit
45f0ff534f
@@ -1,5 +1,4 @@
|
||||
from common.db.base import Base
|
||||
from common.db.models.audit import AuditLogs
|
||||
from common.db.models.events import ConsumerInbox, OutboxEvents
|
||||
from common.db.models.identity import Permissions, RolePermissions, Roles, Users
|
||||
from common.db.models.runtime import WorkspaceOperations
|
||||
@@ -16,7 +15,6 @@ from common.db.models.workspaces import WorkspaceMembers, Workspaces
|
||||
|
||||
__all__ = [
|
||||
"Base",
|
||||
"AuditLogs",
|
||||
"ConsumerInbox",
|
||||
"DataResources",
|
||||
"OutboxEvents",
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
import datetime
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import Index, JSON, String, text
|
||||
from sqlalchemy.dialects.mysql import BIGINT, CHAR, DATETIME, TINYINT
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from common.db.base import Base
|
||||
|
||||
|
||||
class AuditLogs(Base):
|
||||
__tablename__ = "audit_logs"
|
||||
__table_args__ = (
|
||||
Index("idx_audit_action_time", "action_code", "created_at"),
|
||||
Index("idx_audit_actor_time", "actor_user_id", "created_at"),
|
||||
Index("idx_audit_workspace_time", "workspace_id", "created_at"),
|
||||
{"comment": "操作审计日志"},
|
||||
)
|
||||
|
||||
audit_id: Mapped[int] = mapped_column(BIGINT, primary_key=True)
|
||||
action_code: Mapped[str] = mapped_column(String(128), nullable=False)
|
||||
target_type: Mapped[str] = mapped_column(String(64), nullable=False)
|
||||
operation_status: Mapped[str] = mapped_column(
|
||||
String(16), nullable=False, server_default=text("'success'")
|
||||
)
|
||||
created_at: Mapped[datetime.datetime] = mapped_column(
|
||||
DATETIME(fsp=3), nullable=False, server_default=text("CURRENT_TIMESTAMP(3)")
|
||||
)
|
||||
workspace_id: Mapped[Optional[str]] = mapped_column(CHAR(26))
|
||||
actor_user_id: Mapped[Optional[str]] = mapped_column(CHAR(26))
|
||||
target_id: Mapped[Optional[str]] = mapped_column(String(128))
|
||||
client_ip: Mapped[Optional[str]] = mapped_column(String(45))
|
||||
user_agent: Mapped[Optional[str]] = mapped_column(String(1000))
|
||||
detail_json: Mapped[Optional[dict]] = mapped_column(JSON)
|
||||
is_deleted: Mapped[int] = mapped_column(
|
||||
TINYINT(1), nullable=False, server_default=text("0")
|
||||
)
|
||||
deleted_at: Mapped[Optional[datetime.datetime]] = mapped_column(DATETIME(fsp=3))
|
||||
Reference in New Issue
Block a user