feat(postbox): add governed content protection profiles
This commit is contained in:
@@ -161,9 +161,7 @@ class PostboxTemplateRevision(Base, TimestampMixin):
|
||||
default="plaintext_v1",
|
||||
nullable=False,
|
||||
)
|
||||
encryption_vault_id: Mapped[str | None] = mapped_column(
|
||||
String(255), nullable=True
|
||||
)
|
||||
encryption_vault_id: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
history_policy: Mapped[dict[str, Any]] = mapped_column(
|
||||
JSON,
|
||||
default=dict,
|
||||
@@ -323,6 +321,11 @@ class Postbox(Base, TimestampMixin):
|
||||
back_populates="postbox",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
protection_transitions: Mapped[list["PostboxProtectionTransition"]] = relationship(
|
||||
back_populates="postbox",
|
||||
cascade="all, delete-orphan",
|
||||
order_by="PostboxProtectionTransition.created_at",
|
||||
)
|
||||
|
||||
@property
|
||||
def strong_etag(self) -> str:
|
||||
@@ -439,9 +442,7 @@ class PostboxMessage(Base, TimestampMixin):
|
||||
)
|
||||
subject: Mapped[str] = mapped_column(String(1000), nullable=False)
|
||||
body_text: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
body_ciphertext: Mapped[bytes | None] = mapped_column(
|
||||
LargeBinary, nullable=True
|
||||
)
|
||||
body_ciphertext: Mapped[bytes | None] = mapped_column(LargeBinary, nullable=True)
|
||||
status: Mapped[str] = mapped_column(
|
||||
String(30),
|
||||
default="delivered",
|
||||
@@ -558,6 +559,121 @@ class PostboxMessage(Base, TimestampMixin):
|
||||
)
|
||||
|
||||
|
||||
class PostboxProtectionTransition(Base, TimestampMixin):
|
||||
__tablename__ = "postbox_protection_transitions"
|
||||
__table_args__ = (
|
||||
Index(
|
||||
"ix_postbox_protection_transition_state",
|
||||
"tenant_id",
|
||||
"postbox_id",
|
||||
"state",
|
||||
),
|
||||
UniqueConstraint(
|
||||
"tenant_id",
|
||||
"postbox_id",
|
||||
"idempotency_key",
|
||||
name="uq_postbox_protection_transition_idem",
|
||||
),
|
||||
)
|
||||
|
||||
id: Mapped[str] = mapped_column(String(36), primary_key=True, default=new_uuid)
|
||||
tenant_id: Mapped[str] = mapped_column(String(36), nullable=False, index=True)
|
||||
postbox_id: Mapped[str] = mapped_column(
|
||||
ForeignKey("postboxes.id", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
idempotency_key: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
source_profile: Mapped[str] = mapped_column(String(80), nullable=False)
|
||||
target_profile: Mapped[str] = mapped_column(String(80), nullable=False)
|
||||
source_vault_id: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
target_vault_id: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
history_mode: Mapped[str] = mapped_column(String(30), nullable=False)
|
||||
authority_mode: Mapped[str] = mapped_column(String(40), nullable=False)
|
||||
required_quorum: Mapped[int] = mapped_column(Integer, default=1, nullable=False)
|
||||
evidence_refs: Mapped[list[str]] = mapped_column(JSON, default=list, nullable=False)
|
||||
reason: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
state: Mapped[str] = mapped_column(
|
||||
String(30), default="pending", nullable=False, index=True
|
||||
)
|
||||
message_count: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
|
||||
completed_count: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
|
||||
failed_count: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
|
||||
requested_by: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
activated_at: Mapped[datetime | None] = mapped_column(
|
||||
DateTime(timezone=True), nullable=True
|
||||
)
|
||||
completed_at: Mapped[datetime | None] = mapped_column(
|
||||
DateTime(timezone=True), nullable=True
|
||||
)
|
||||
resource_revision: Mapped[int] = mapped_column(Integer, default=1, nullable=False)
|
||||
configuration_snapshot: Mapped[dict[str, Any]] = mapped_column(
|
||||
JSON, default=dict, nullable=False
|
||||
)
|
||||
|
||||
postbox: Mapped[Postbox] = relationship(back_populates="protection_transitions")
|
||||
items: Mapped[list["PostboxProtectionTransitionItem"]] = relationship(
|
||||
back_populates="transition",
|
||||
cascade="all, delete-orphan",
|
||||
order_by="PostboxProtectionTransitionItem.created_at",
|
||||
)
|
||||
|
||||
@property
|
||||
def strong_etag(self) -> str:
|
||||
return strong_resource_etag(
|
||||
"postbox_protection_transition",
|
||||
self.id,
|
||||
self.resource_revision,
|
||||
)
|
||||
|
||||
|
||||
class PostboxProtectionTransitionItem(Base, TimestampMixin):
|
||||
__tablename__ = "postbox_protection_transition_items"
|
||||
__table_args__ = (
|
||||
UniqueConstraint(
|
||||
"transition_id",
|
||||
"message_id",
|
||||
name="uq_postbox_protection_transition_message",
|
||||
),
|
||||
Index(
|
||||
"ix_postbox_protection_transition_item_state",
|
||||
"tenant_id",
|
||||
"transition_id",
|
||||
"state",
|
||||
),
|
||||
)
|
||||
|
||||
id: Mapped[str] = mapped_column(String(36), primary_key=True, default=new_uuid)
|
||||
tenant_id: Mapped[str] = mapped_column(String(36), nullable=False, index=True)
|
||||
transition_id: Mapped[str] = mapped_column(
|
||||
ForeignKey("postbox_protection_transitions.id", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
message_id: Mapped[str] = mapped_column(
|
||||
ForeignKey("postbox_messages.id", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
source_profile: Mapped[str] = mapped_column(String(80), nullable=False)
|
||||
target_profile: Mapped[str] = mapped_column(String(80), nullable=False)
|
||||
state: Mapped[str] = mapped_column(
|
||||
String(30), default="pending", nullable=False, index=True
|
||||
)
|
||||
source_digest: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
target_digest: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
completed_by: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
completed_at: Mapped[datetime | None] = mapped_column(
|
||||
DateTime(timezone=True), nullable=True
|
||||
)
|
||||
error_code: Mapped[str | None] = mapped_column(String(100), nullable=True)
|
||||
evidence: Mapped[dict[str, Any]] = mapped_column(JSON, default=dict, nullable=False)
|
||||
|
||||
transition: Mapped[PostboxProtectionTransition] = relationship(
|
||||
back_populates="items"
|
||||
)
|
||||
|
||||
|
||||
class PostboxParticipant(Base, TimestampMixin):
|
||||
__tablename__ = "postbox_participants"
|
||||
__table_args__ = (
|
||||
|
||||
Reference in New Issue
Block a user