Files
aiagent/backend/app/models/workflow_template.py
renjianbo 876789fac1 feat: multi-tenant workspace isolation, RBAC, sidebar nav, billing, and Android enhancements
- Backend: workspace_id isolation for 14 model tables + safe migration/backfill
- Backend: RBAC system with 4 roles and 23 permissions, seeded on startup
- Backend: workspace admin endpoints (list/manage all workspaces)
- Backend: admin user management API (CRUD, reset password)
- Backend: billing API with subscription plans, usage tracking, rate limiting
- Backend: fix system_logs.py UNION query and wrong column references
- Backend: WebSocket JWT auth and workspace enforcement
- Frontend: sidebar navigation replacing top dropdown menu
- Frontend: user management page (Users.vue) for admins
- Frontend: enhanced Workspaces.vue with admin table view
- Frontend: workspace RBAC computed properties in user store
- Android: agent marketplace, billing/subscription UI, onboarding wizard
- Android: phone login, analytics tracker, crash handler, network diagnostics
- Android: splash screen, encrypted token storage, app update enhancements
- Docs: multi-tenant RBAC guide with 8 sections and role-permission matrix

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-07-04 01:00:22 +08:00

84 lines
4.1 KiB
Python

"""
工作流模板市场模型
"""
from sqlalchemy import Column, String, Text, Integer, DateTime, JSON, ForeignKey, Boolean, Float, Index, func
from sqlalchemy.dialects.mysql import CHAR
from sqlalchemy.orm import relationship
from app.core.database import Base
import uuid
class WorkflowTemplate(Base):
"""工作流模板表(用户分享的模板)"""
__tablename__ = "workflow_templates"
id = Column(CHAR(36), primary_key=True, default=lambda: str(uuid.uuid4()), comment="模板ID")
name = Column(String(100), nullable=False, comment="模板名称")
description = Column(Text, comment="模板描述")
category = Column(String(50), comment="分类: llm/data_processing/automation/integration/other")
tags = Column(JSON, comment="标签列表")
nodes = Column(JSON, nullable=False, comment="节点配置")
edges = Column(JSON, nullable=False, comment="边配置")
thumbnail = Column(String(500), comment="缩略图URL")
is_public = Column(Boolean, default=True, comment="是否公开")
is_featured = Column(Boolean, default=False, comment="是否精选")
view_count = Column(Integer, default=0, comment="查看次数")
use_count = Column(Integer, default=0, comment="使用次数")
rating_count = Column(Integer, default=0, comment="评分次数")
rating_avg = Column(Float, default=0.0, comment="平均评分")
user_id = Column(CHAR(36), ForeignKey("users.id"), nullable=False, comment="创建者ID")
workspace_id = Column(CHAR(36), ForeignKey("workspaces.id"), nullable=True, comment="所属工作区ID")
created_at = Column(DateTime, default=func.now(), comment="创建时间")
updated_at = Column(DateTime, default=func.now(), onupdate=func.now(), comment="更新时间")
# 关系
user = relationship("User", backref="shared_templates")
__table_args__ = (
Index("ix_workflow_templates_workspace", "workspace_id"),
)
ratings = relationship("TemplateRating", back_populates="template", cascade="all, delete-orphan")
favorites = relationship("TemplateFavorite", back_populates="template", cascade="all, delete-orphan")
def __repr__(self):
return f"<WorkflowTemplate(id={self.id}, name={self.name})>"
class TemplateRating(Base):
"""模板评分表"""
__tablename__ = "template_ratings"
id = Column(CHAR(36), primary_key=True, default=lambda: str(uuid.uuid4()), comment="评分ID")
template_id = Column(CHAR(36), ForeignKey("workflow_templates.id"), nullable=False, comment="模板ID")
user_id = Column(CHAR(36), ForeignKey("users.id"), nullable=False, comment="用户ID")
workspace_id = Column(CHAR(36), ForeignKey("workspaces.id"), nullable=True, index=True, comment="工作区ID")
rating = Column(Integer, nullable=False, comment="评分: 1-5")
comment = Column(Text, comment="评论")
created_at = Column(DateTime, default=func.now(), comment="创建时间")
updated_at = Column(DateTime, default=func.now(), onupdate=func.now(), comment="更新时间")
# 关系
template = relationship("WorkflowTemplate", back_populates="ratings")
user = relationship("User", backref="template_ratings")
def __repr__(self):
return f"<TemplateRating(id={self.id}, template_id={self.template_id}, rating={self.rating})>"
class TemplateFavorite(Base):
"""模板收藏表"""
__tablename__ = "template_favorites"
id = Column(CHAR(36), primary_key=True, default=lambda: str(uuid.uuid4()), comment="收藏ID")
template_id = Column(CHAR(36), ForeignKey("workflow_templates.id"), nullable=False, comment="模板ID")
user_id = Column(CHAR(36), ForeignKey("users.id"), nullable=False, comment="用户ID")
workspace_id = Column(CHAR(36), ForeignKey("workspaces.id"), nullable=True, index=True, comment="工作区ID")
created_at = Column(DateTime, default=func.now(), comment="创建时间")
# 关系
template = relationship("WorkflowTemplate", back_populates="favorites")
user = relationship("User", backref="template_favorites")
def __repr__(self):
return f"<TemplateFavorite(id={self.id}, template_id={self.template_id}, user_id={self.user_id})>"