feat(collaboration): 完善在线文档协作与通知闭环
- 新增协作文件夹、文件、不可变修订、成员、会话、回调回执、编辑申请与分享链接数据模型。 - 补齐新建、导入、复制、下载、回收站、恢复、成员授权、所有权转让及文件级权限接口。 - 接入 ONLYOFFICE 共同编辑、历史版本预览与恢复、修订另存副本、导出下载审计和幂等回调保存。 - 增加编辑权限申请、审批通知、项目提醒聚合、通知 Feed、已读处理及历史待办数据回填。 - 支持公开分享的查看或编辑模式、有效期、密码哈希、失败锁定、短时访问凭证与固定分享地址。 - 增加协作者导出、申请编辑、工作表结构保护和所有权管理策略,并纳入项目接口权限矩阵。 - 新增协作文件库、编辑工作区、公开分享页、下载与另存为对话框,以及导航、路由和权限入口。 - 统一网页端与桌面端通知布局,增加沉浸式工作区和浏览器、Tauri 双端全屏能力。 - 扩展运行时文件下载适配、Tauri 环境识别和原生全屏命令,继续保持业务代码运行时边界。 - 加固 ONLYOFFICE 消息桥的同源下载、签名地址隔离和保存为能力校验,并更新桌面发布检查。 - 增加连续数据库迁移、50MB 上传限制、OnlyOffice 中文文案与开发启动路由校验。 - 补充协作、通知、权限、路由、运行时、布局和 OnlyOffice 相关测试及模块说明文档。
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
"""Add the independent shared-library collaboration module.
|
||||
|
||||
Revision ID: 20260714_01
|
||||
Revises: 20260713_02
|
||||
"""
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
|
||||
revision = "20260714_01"
|
||||
down_revision = "20260713_02"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
uuid_type = postgresql.UUID(as_uuid=True)
|
||||
op.create_table(
|
||||
"collaboration_folders",
|
||||
sa.Column("id", uuid_type, primary_key=True),
|
||||
sa.Column("study_id", uuid_type, sa.ForeignKey("studies.id"), nullable=False),
|
||||
sa.Column("parent_id", uuid_type, sa.ForeignKey("collaboration_folders.id", ondelete="SET NULL")),
|
||||
sa.Column("name", sa.String(120), nullable=False),
|
||||
sa.Column("sort_order", sa.Integer(), nullable=False, server_default="0"),
|
||||
sa.Column("created_by", uuid_type, sa.ForeignKey("users.id"), nullable=False),
|
||||
sa.Column("deleted_at", sa.DateTime(timezone=True)),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()),
|
||||
)
|
||||
op.create_index("ix_collaboration_folders_study_parent", "collaboration_folders", ["study_id", "parent_id"])
|
||||
|
||||
op.create_table(
|
||||
"collaboration_files",
|
||||
sa.Column("id", uuid_type, primary_key=True),
|
||||
sa.Column("study_id", uuid_type, sa.ForeignKey("studies.id"), nullable=False),
|
||||
sa.Column("folder_id", uuid_type, sa.ForeignKey("collaboration_folders.id", ondelete="SET NULL")),
|
||||
sa.Column("title", sa.String(255), nullable=False),
|
||||
sa.Column("file_type", sa.String(16), nullable=False),
|
||||
sa.Column("extension", sa.String(16), nullable=False),
|
||||
sa.Column("status", sa.String(20), nullable=False, server_default="ACTIVE"),
|
||||
sa.Column("owner_id", uuid_type, sa.ForeignKey("users.id"), nullable=False),
|
||||
sa.Column("current_revision_id", uuid_type),
|
||||
sa.Column("generation", sa.Integer(), nullable=False, server_default="1"),
|
||||
sa.Column("deleted_at", sa.DateTime(timezone=True)),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()),
|
||||
)
|
||||
op.create_index("ix_collaboration_files_study_folder", "collaboration_files", ["study_id", "folder_id"])
|
||||
op.create_index("ix_collaboration_files_study_status", "collaboration_files", ["study_id", "status"])
|
||||
|
||||
op.create_table(
|
||||
"collaboration_members",
|
||||
sa.Column("id", uuid_type, primary_key=True),
|
||||
sa.Column("file_id", uuid_type, sa.ForeignKey("collaboration_files.id", ondelete="CASCADE"), nullable=False),
|
||||
sa.Column("user_id", uuid_type, sa.ForeignKey("users.id"), nullable=False),
|
||||
sa.Column("role", sa.String(16), nullable=False),
|
||||
sa.Column("invited_by", uuid_type, sa.ForeignKey("users.id"), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()),
|
||||
sa.UniqueConstraint("file_id", "user_id", name="uq_collaboration_member_file_user"),
|
||||
)
|
||||
op.create_index("ix_collaboration_members_user", "collaboration_members", ["user_id"])
|
||||
|
||||
op.create_table(
|
||||
"collaboration_revisions",
|
||||
sa.Column("id", uuid_type, primary_key=True),
|
||||
sa.Column("file_id", uuid_type, sa.ForeignKey("collaboration_files.id", ondelete="CASCADE"), nullable=False),
|
||||
sa.Column("revision_no", sa.Integer(), nullable=False),
|
||||
sa.Column("parent_revision_id", uuid_type, sa.ForeignKey("collaboration_revisions.id", ondelete="SET NULL")),
|
||||
sa.Column("file_uri", sa.String(500), nullable=False),
|
||||
sa.Column("original_filename", sa.String(255), nullable=False),
|
||||
sa.Column("file_hash", sa.String(128), nullable=False),
|
||||
sa.Column("file_size", sa.BigInteger(), nullable=False),
|
||||
sa.Column("mime_type", sa.String(100), nullable=False),
|
||||
sa.Column("source", sa.String(24), nullable=False),
|
||||
sa.Column("change_summary", sa.Text()),
|
||||
sa.Column("created_by", uuid_type, sa.ForeignKey("users.id")),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()),
|
||||
sa.UniqueConstraint("file_id", "revision_no", name="uq_collaboration_revision_file_no"),
|
||||
)
|
||||
op.create_index("ix_collaboration_revisions_file_created", "collaboration_revisions", ["file_id", "created_at"])
|
||||
op.create_foreign_key(
|
||||
"fk_collaboration_files_current_revision",
|
||||
"collaboration_files",
|
||||
"collaboration_revisions",
|
||||
["current_revision_id"],
|
||||
["id"],
|
||||
ondelete="SET NULL",
|
||||
)
|
||||
|
||||
op.create_table(
|
||||
"collaboration_sessions",
|
||||
sa.Column("id", uuid_type, primary_key=True),
|
||||
sa.Column("file_id", uuid_type, sa.ForeignKey("collaboration_files.id", ondelete="CASCADE"), nullable=False),
|
||||
sa.Column("base_revision_id", uuid_type, sa.ForeignKey("collaboration_revisions.id"), nullable=False),
|
||||
sa.Column("document_key", sa.String(128), nullable=False),
|
||||
sa.Column("generation", sa.Integer(), nullable=False),
|
||||
sa.Column("status", sa.String(20), nullable=False, server_default="ACTIVE"),
|
||||
sa.Column("started_by", uuid_type, sa.ForeignKey("users.id"), nullable=False),
|
||||
sa.Column("active_users", sa.Text()),
|
||||
sa.Column("last_callback_at", sa.DateTime(timezone=True)),
|
||||
sa.Column("closed_at", sa.DateTime(timezone=True)),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()),
|
||||
sa.UniqueConstraint("document_key", name="uq_collaboration_session_document_key"),
|
||||
)
|
||||
op.create_index("ix_collaboration_sessions_file_status", "collaboration_sessions", ["file_id", "status"])
|
||||
|
||||
op.create_table(
|
||||
"collaboration_callback_receipts",
|
||||
sa.Column("id", uuid_type, primary_key=True),
|
||||
sa.Column("session_id", uuid_type, sa.ForeignKey("collaboration_sessions.id", ondelete="CASCADE"), nullable=False),
|
||||
sa.Column("fingerprint", sa.String(128), nullable=False),
|
||||
sa.Column("callback_status", sa.Integer(), nullable=False),
|
||||
sa.Column("result", sa.String(24), nullable=False),
|
||||
sa.Column("revision_id", uuid_type, sa.ForeignKey("collaboration_revisions.id", ondelete="SET NULL")),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()),
|
||||
sa.UniqueConstraint("session_id", "fingerprint", name="uq_collaboration_callback_session_fingerprint"),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_table("collaboration_callback_receipts")
|
||||
op.drop_index("ix_collaboration_sessions_file_status", table_name="collaboration_sessions")
|
||||
op.drop_table("collaboration_sessions")
|
||||
op.drop_constraint("fk_collaboration_files_current_revision", "collaboration_files", type_="foreignkey")
|
||||
op.drop_index("ix_collaboration_revisions_file_created", table_name="collaboration_revisions")
|
||||
op.drop_table("collaboration_revisions")
|
||||
op.drop_index("ix_collaboration_members_user", table_name="collaboration_members")
|
||||
op.drop_table("collaboration_members")
|
||||
op.drop_index("ix_collaboration_files_study_status", table_name="collaboration_files")
|
||||
op.drop_index("ix_collaboration_files_study_folder", table_name="collaboration_files")
|
||||
op.drop_table("collaboration_files")
|
||||
op.drop_index("ix_collaboration_folders_study_parent", table_name="collaboration_folders")
|
||||
op.drop_table("collaboration_folders")
|
||||
@@ -0,0 +1,53 @@
|
||||
"""Add protected public links for collaboration files.
|
||||
|
||||
Revision ID: 20260715_01
|
||||
Revises: 20260714_01
|
||||
"""
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
|
||||
revision = "20260715_01"
|
||||
down_revision = "20260714_01"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
uuid_type = postgresql.UUID(as_uuid=True)
|
||||
op.create_table(
|
||||
"collaboration_share_links",
|
||||
sa.Column("id", uuid_type, primary_key=True),
|
||||
sa.Column(
|
||||
"file_id",
|
||||
uuid_type,
|
||||
sa.ForeignKey("collaboration_files.id", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column("enabled", sa.Boolean(), nullable=False, server_default=sa.false()),
|
||||
sa.Column("access_mode", sa.String(12), nullable=False, server_default="VIEW"),
|
||||
sa.Column("expiry_policy", sa.String(16), nullable=False, server_default="SEVEN_DAYS"),
|
||||
sa.Column("expires_at", sa.DateTime(timezone=True)),
|
||||
sa.Column("password_hash", sa.String(255)),
|
||||
sa.Column("token_version", sa.Integer(), nullable=False, server_default="1"),
|
||||
sa.Column("failed_attempts", sa.Integer(), nullable=False, server_default="0"),
|
||||
sa.Column("last_failed_at", sa.DateTime(timezone=True)),
|
||||
sa.Column("locked_until", sa.DateTime(timezone=True)),
|
||||
sa.Column("created_by", uuid_type, sa.ForeignKey("users.id"), nullable=False),
|
||||
sa.Column("updated_by", uuid_type, sa.ForeignKey("users.id"), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()),
|
||||
sa.UniqueConstraint("file_id", name="uq_collaboration_share_link_file"),
|
||||
)
|
||||
op.create_index(
|
||||
"ix_collaboration_share_links_enabled_expiry",
|
||||
"collaboration_share_links",
|
||||
["enabled", "expires_at"],
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index("ix_collaboration_share_links_enabled_expiry", table_name="collaboration_share_links")
|
||||
op.drop_table("collaboration_share_links")
|
||||
@@ -0,0 +1,25 @@
|
||||
"""Add effective export controls to collaboration share links.
|
||||
|
||||
Revision ID: 20260715_02
|
||||
Revises: 20260715_01
|
||||
"""
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
|
||||
revision = "20260715_02"
|
||||
down_revision = "20260715_01"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column(
|
||||
"collaboration_share_links",
|
||||
sa.Column("allow_export", sa.Boolean(), nullable=False, server_default=sa.false()),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_column("collaboration_share_links", "allow_export")
|
||||
@@ -0,0 +1,43 @@
|
||||
"""Add soft deletion metadata to collaboration revisions.
|
||||
|
||||
Revision ID: 20260715_03
|
||||
Revises: 20260715_02
|
||||
"""
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
|
||||
revision = "20260715_03"
|
||||
down_revision = "20260715_02"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column(
|
||||
"collaboration_revisions",
|
||||
sa.Column("deleted_by", postgresql.UUID(as_uuid=True), nullable=True),
|
||||
)
|
||||
op.add_column(
|
||||
"collaboration_revisions",
|
||||
sa.Column("deleted_at", sa.DateTime(timezone=True), nullable=True),
|
||||
)
|
||||
op.create_foreign_key(
|
||||
"fk_collaboration_revision_deleted_by",
|
||||
"collaboration_revisions",
|
||||
"users",
|
||||
["deleted_by"],
|
||||
["id"],
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_constraint(
|
||||
"fk_collaboration_revision_deleted_by",
|
||||
"collaboration_revisions",
|
||||
type_="foreignkey",
|
||||
)
|
||||
op.drop_column("collaboration_revisions", "deleted_at")
|
||||
op.drop_column("collaboration_revisions", "deleted_by")
|
||||
@@ -0,0 +1,35 @@
|
||||
"""Move collaboration export control to the file.
|
||||
|
||||
Revision ID: 20260715_04
|
||||
Revises: 20260715_03
|
||||
"""
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
|
||||
revision = "20260715_04"
|
||||
down_revision = "20260715_03"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column(
|
||||
"collaboration_files",
|
||||
sa.Column("allow_export", sa.Boolean(), nullable=False, server_default=sa.false()),
|
||||
)
|
||||
# Preserve links that already granted export: after consolidation the same
|
||||
# setting applies to authenticated collaborators and anonymous visitors.
|
||||
op.execute(
|
||||
"""
|
||||
UPDATE collaboration_files AS file
|
||||
SET allow_export = true
|
||||
FROM collaboration_share_links AS link
|
||||
WHERE link.file_id = file.id AND link.allow_export = true
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_column("collaboration_files", "allow_export")
|
||||
@@ -0,0 +1,33 @@
|
||||
"""Remove the redundant share-link export permission.
|
||||
|
||||
Revision ID: 20260715_05
|
||||
Revises: 20260715_04
|
||||
"""
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
|
||||
revision = "20260715_05"
|
||||
down_revision = "20260715_04"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.drop_column("collaboration_share_links", "allow_export")
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.add_column(
|
||||
"collaboration_share_links",
|
||||
sa.Column("allow_export", sa.Boolean(), nullable=False, server_default=sa.false()),
|
||||
)
|
||||
op.execute(
|
||||
"""
|
||||
UPDATE collaboration_share_links AS link
|
||||
SET allow_export = file.allow_export
|
||||
FROM collaboration_files AS file
|
||||
WHERE file.id = link.file_id
|
||||
"""
|
||||
)
|
||||
@@ -0,0 +1,66 @@
|
||||
"""Add collaboration edit requests and ownership controls.
|
||||
|
||||
Revision ID: 20260715_06
|
||||
Revises: 20260715_05
|
||||
"""
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
|
||||
revision = "20260715_06"
|
||||
down_revision = "20260715_05"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column(
|
||||
"collaboration_files",
|
||||
sa.Column("allow_edit_request", sa.Boolean(), nullable=False, server_default=sa.false()),
|
||||
)
|
||||
op.add_column(
|
||||
"collaboration_files",
|
||||
sa.Column("allow_sheet_structure_edit", sa.Boolean(), nullable=False, server_default=sa.true()),
|
||||
)
|
||||
op.add_column(
|
||||
"collaboration_files",
|
||||
sa.Column("sheet_structure_protection_backup", sa.Text(), nullable=True),
|
||||
)
|
||||
op.create_table(
|
||||
"collaboration_edit_requests",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column("file_id", postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column("requester_id", postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column("status", sa.String(length=16), nullable=False, server_default="PENDING"),
|
||||
sa.Column("resolved_by", postgresql.UUID(as_uuid=True), nullable=True),
|
||||
sa.Column("resolved_at", sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()),
|
||||
sa.ForeignKeyConstraint(["file_id"], ["collaboration_files.id"], ondelete="CASCADE"),
|
||||
sa.ForeignKeyConstraint(["requester_id"], ["users.id"]),
|
||||
sa.ForeignKeyConstraint(["resolved_by"], ["users.id"]),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.create_index(
|
||||
"ix_collaboration_edit_requests_file_status",
|
||||
"collaboration_edit_requests",
|
||||
["file_id", "status"],
|
||||
)
|
||||
op.create_index(
|
||||
"uq_collaboration_edit_requests_pending_user",
|
||||
"collaboration_edit_requests",
|
||||
["file_id", "requester_id"],
|
||||
unique=True,
|
||||
postgresql_where=sa.text("status = 'PENDING'"),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index("uq_collaboration_edit_requests_pending_user", table_name="collaboration_edit_requests")
|
||||
op.drop_index("ix_collaboration_edit_requests_file_status", table_name="collaboration_edit_requests")
|
||||
op.drop_table("collaboration_edit_requests")
|
||||
op.drop_column("collaboration_files", "sheet_structure_protection_backup")
|
||||
op.drop_column("collaboration_files", "allow_sheet_structure_edit")
|
||||
op.drop_column("collaboration_files", "allow_edit_request")
|
||||
@@ -0,0 +1,53 @@
|
||||
"""Add recipient-scoped generic notifications.
|
||||
|
||||
Revision ID: 20260716_01
|
||||
Revises: 20260715_06
|
||||
"""
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
|
||||
revision = "20260716_01"
|
||||
down_revision = "20260715_06"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"notifications",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column("study_id", postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column("recipient_id", postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column("category", sa.String(length=64), nullable=False),
|
||||
sa.Column("priority", sa.String(length=16), nullable=False, server_default="NORMAL"),
|
||||
sa.Column("title", sa.String(length=180), nullable=False),
|
||||
sa.Column("message", sa.String(length=500), nullable=False),
|
||||
sa.Column("action_path", sa.Text(), nullable=True),
|
||||
sa.Column("source_type", sa.String(length=64), nullable=False),
|
||||
sa.Column("source_id", sa.String(length=100), nullable=False),
|
||||
sa.Column("source_version", sa.String(length=100), nullable=True),
|
||||
sa.Column("dedupe_key", sa.String(length=255), nullable=False),
|
||||
sa.Column("read_at", sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column("resolved_at", sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()),
|
||||
sa.ForeignKeyConstraint(["recipient_id"], ["users.id"], ondelete="CASCADE"),
|
||||
sa.ForeignKeyConstraint(["study_id"], ["studies.id"], ondelete="CASCADE"),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.UniqueConstraint("recipient_id", "dedupe_key", name="uq_notifications_recipient_dedupe"),
|
||||
)
|
||||
op.create_index(
|
||||
"ix_notifications_recipient_study_state",
|
||||
"notifications",
|
||||
["recipient_id", "study_id", "resolved_at", "read_at", "created_at"],
|
||||
)
|
||||
op.create_index("ix_notifications_source", "notifications", ["source_type", "source_id"])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index("ix_notifications_source", table_name="notifications")
|
||||
op.drop_index("ix_notifications_recipient_study_state", table_name="notifications")
|
||||
op.drop_table("notifications")
|
||||
@@ -0,0 +1,75 @@
|
||||
"""Backfill notifications for pending collaboration edit requests.
|
||||
|
||||
Revision ID: 20260716_02
|
||||
Revises: 20260716_01
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
|
||||
|
||||
revision = "20260716_02"
|
||||
down_revision = "20260716_01"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.execute("""
|
||||
INSERT INTO notifications (
|
||||
id,
|
||||
study_id,
|
||||
recipient_id,
|
||||
category,
|
||||
priority,
|
||||
title,
|
||||
message,
|
||||
action_path,
|
||||
source_type,
|
||||
source_id,
|
||||
dedupe_key,
|
||||
created_at,
|
||||
updated_at
|
||||
)
|
||||
SELECT
|
||||
gen_random_uuid(),
|
||||
collaboration_files.study_id,
|
||||
study_members.user_id,
|
||||
'COLLABORATION_EDIT_REQUEST',
|
||||
'NORMAL',
|
||||
'新的编辑权限申请',
|
||||
concat(
|
||||
coalesce(nullif(users.full_name, ''), users.email, '项目成员'),
|
||||
' 申请编辑“',
|
||||
collaboration_files.title,
|
||||
'”'
|
||||
),
|
||||
concat('/knowledge/collaboration?editRequestFile=', collaboration_files.id::text),
|
||||
'COLLABORATION_EDIT_REQUEST',
|
||||
collaboration_edit_requests.id::text,
|
||||
concat('collaboration-edit-request:', collaboration_edit_requests.id::text),
|
||||
collaboration_edit_requests.created_at,
|
||||
collaboration_edit_requests.updated_at
|
||||
FROM collaboration_edit_requests
|
||||
JOIN collaboration_files
|
||||
ON collaboration_files.id = collaboration_edit_requests.file_id
|
||||
JOIN users
|
||||
ON users.id = collaboration_edit_requests.requester_id
|
||||
JOIN study_members
|
||||
ON study_members.study_id = collaboration_files.study_id
|
||||
AND study_members.is_active IS TRUE
|
||||
LEFT JOIN collaboration_members
|
||||
ON collaboration_members.file_id = collaboration_files.id
|
||||
AND collaboration_members.user_id = study_members.user_id
|
||||
WHERE collaboration_edit_requests.status = 'PENDING'
|
||||
AND collaboration_files.deleted_at IS NULL
|
||||
AND (
|
||||
study_members.user_id = collaboration_files.owner_id
|
||||
OR collaboration_members.role = 'MANAGER'
|
||||
)
|
||||
ON CONFLICT (recipient_id, dedupe_key) DO NOTHING
|
||||
""")
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# 这是业务通知数据迁移;降级时保留已读/未读状态,避免删除升级后新产生的同源通知。
|
||||
pass
|
||||
@@ -0,0 +1,65 @@
|
||||
"""Backfill pending edit request notifications for file owners.
|
||||
|
||||
Revision ID: 20260716_03
|
||||
Revises: 20260716_02
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
|
||||
|
||||
revision = "20260716_03"
|
||||
down_revision = "20260716_02"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.execute("""
|
||||
INSERT INTO notifications (
|
||||
id,
|
||||
study_id,
|
||||
recipient_id,
|
||||
category,
|
||||
priority,
|
||||
title,
|
||||
message,
|
||||
action_path,
|
||||
source_type,
|
||||
source_id,
|
||||
dedupe_key,
|
||||
created_at,
|
||||
updated_at
|
||||
)
|
||||
SELECT
|
||||
gen_random_uuid(),
|
||||
collaboration_files.study_id,
|
||||
collaboration_files.owner_id,
|
||||
'COLLABORATION_EDIT_REQUEST',
|
||||
'NORMAL',
|
||||
'新的编辑权限申请',
|
||||
concat(
|
||||
coalesce(nullif(users.full_name, ''), users.email, '项目成员'),
|
||||
' 申请编辑“',
|
||||
collaboration_files.title,
|
||||
'”'
|
||||
),
|
||||
concat('/knowledge/collaboration?editRequestFile=', collaboration_files.id::text),
|
||||
'COLLABORATION_EDIT_REQUEST',
|
||||
collaboration_edit_requests.id::text,
|
||||
concat('collaboration-edit-request:', collaboration_edit_requests.id::text),
|
||||
collaboration_edit_requests.created_at,
|
||||
collaboration_edit_requests.updated_at
|
||||
FROM collaboration_edit_requests
|
||||
JOIN collaboration_files
|
||||
ON collaboration_files.id = collaboration_edit_requests.file_id
|
||||
JOIN users
|
||||
ON users.id = collaboration_edit_requests.requester_id
|
||||
WHERE collaboration_edit_requests.status = 'PENDING'
|
||||
AND collaboration_files.deleted_at IS NULL
|
||||
ON CONFLICT (recipient_id, dedupe_key) DO NOTHING
|
||||
""")
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# 与上一数据迁移一致,降级时保留已产生的业务通知状态。
|
||||
pass
|
||||
Reference in New Issue
Block a user