116 lines
4.0 KiB
Python
116 lines
4.0 KiB
Python
from sqlalchemy import Column, String, Boolean, Index
|
|
from sqlalchemy.dialects.postgresql import JSONB
|
|
from sqlalchemy import JSON
|
|
|
|
from app.base_model import BaseModel
|
|
|
|
PermJSON = JSON().with_variant(JSONB(), "postgresql")
|
|
|
|
|
|
SYSTEM_CAPABILITIES = {
|
|
"owner": {
|
|
"manage_table": True,
|
|
"manage_permission": True,
|
|
"manage_field": True,
|
|
"manage_view": True,
|
|
"add_record": True,
|
|
"edit_record": True,
|
|
"delete_record": True,
|
|
"export_data": True,
|
|
"import_data": True,
|
|
},
|
|
"manager": {
|
|
"manage_table": False,
|
|
"manage_permission": True,
|
|
"manage_field": True,
|
|
"manage_view": True,
|
|
"add_record": True,
|
|
"edit_record": True,
|
|
"delete_record": True,
|
|
"export_data": True,
|
|
"import_data": True,
|
|
},
|
|
"editor": {
|
|
"manage_table": False,
|
|
"manage_permission": False,
|
|
"manage_field": False,
|
|
"manage_view": False,
|
|
"add_record": True,
|
|
"edit_record": True,
|
|
"delete_record": False,
|
|
"export_data": True,
|
|
"import_data": False,
|
|
},
|
|
"viewer": {
|
|
"manage_table": False,
|
|
"manage_permission": False,
|
|
"manage_field": False,
|
|
"manage_view": False,
|
|
"add_record": False,
|
|
"edit_record": False,
|
|
"delete_record": False,
|
|
"export_data": False,
|
|
"import_data": False,
|
|
},
|
|
}
|
|
|
|
ROLE_PRIORITY = {"owner": 100, "manager": 80, "editor": 60, "viewer": 40, "custom": 50}
|
|
|
|
|
|
class SmartTableRole(BaseModel):
|
|
"""多维表格 - 表角色定义"""
|
|
__tablename__ = "smart_table_role"
|
|
|
|
table_id = Column(String(21), nullable=True, index=True, comment="所属表ID(null=系统预置)")
|
|
name = Column(String(64), nullable=False, comment="角色名称")
|
|
role_type = Column(String(20), nullable=False, default="custom", comment="owner/manager/editor/viewer/custom")
|
|
capabilities = Column(PermJSON, default=dict, comment="能力配置JSON")
|
|
is_system = Column(Boolean, default=False, comment="是否系统预置(不可删除)")
|
|
|
|
__table_args__ = (
|
|
Index("ix_smart_table_role_table", "table_id", "role_type"),
|
|
)
|
|
|
|
|
|
class SmartTableCollaborator(BaseModel):
|
|
"""多维表格 - 表协作者"""
|
|
__tablename__ = "smart_table_collaborator"
|
|
|
|
table_id = Column(String(21), nullable=False, index=True, comment="所属表ID")
|
|
subject_type = Column(String(20), nullable=False, comment="授权对象类型: user/dept/role")
|
|
subject_id = Column(String(21), nullable=False, index=True, comment="授权对象ID(用户/部门/角色)")
|
|
role_id = Column(String(21), nullable=False, index=True, comment="表角色ID")
|
|
|
|
__table_args__ = (
|
|
Index("ix_smart_collab_table_subject", "table_id", "subject_type", "subject_id", unique=True),
|
|
)
|
|
|
|
|
|
class SmartTableFieldPerm(BaseModel):
|
|
"""多维表格 - 列权限"""
|
|
__tablename__ = "smart_table_field_perm"
|
|
|
|
table_id = Column(String(21), nullable=False, index=True, comment="所属表ID")
|
|
role_id = Column(String(21), nullable=False, index=True, comment="表角色ID")
|
|
field_id = Column(String(21), nullable=False, index=True, comment="字段ID")
|
|
access = Column(String(10), default="write", comment="访问级别: write/read/hidden")
|
|
|
|
__table_args__ = (
|
|
Index("ix_smart_fperm_role_field", "table_id", "role_id", "field_id", unique=True),
|
|
)
|
|
|
|
|
|
class SmartTableRowRule(BaseModel):
|
|
"""多维表格 - 行权限规则"""
|
|
__tablename__ = "smart_table_row_rule"
|
|
|
|
table_id = Column(String(21), nullable=False, index=True, comment="所属表ID")
|
|
role_id = Column(String(21), nullable=False, index=True, comment="表角色ID")
|
|
rule_type = Column(String(10), nullable=False, comment="规则类型: view/edit")
|
|
mode = Column(String(20), default="all", comment="模式: all/conditions/creator_only")
|
|
conditions = Column(PermJSON, default=list, comment="过滤条件(复用视图filter结构)")
|
|
|
|
__table_args__ = (
|
|
Index("ix_smart_row_rule_role_type", "table_id", "role_id", "rule_type", unique=True),
|
|
)
|