aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/src/meshbay_hub/db
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/db')
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/db/migrations/versions/c4d5e6f7a8b9_invite_links_unbound.py34
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/db/models.py13
2 files changed, 40 insertions, 7 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/db/migrations/versions/c4d5e6f7a8b9_invite_links_unbound.py b/packages/meshbay-hub/src/meshbay_hub/db/migrations/versions/c4d5e6f7a8b9_invite_links_unbound.py
new file mode 100644
index 0000000..ae9d2c9
--- /dev/null
+++ b/packages/meshbay-hub/src/meshbay_hub/db/migrations/versions/c4d5e6f7a8b9_invite_links_unbound.py
@@ -0,0 +1,34 @@
+"""invitation links bind no address
+
+A link is now redeemable by whichever account opens it first, so it can be sent
+through any messaging service. The address, when the inviter gives one, is only
+where the hub mails the link and a masked label in the owner's list.
+
+Revision ID: c4d5e6f7a8b9
+Revises: b2c3d4e5f6a7
+"""
+
+from collections.abc import Sequence
+
+import sqlalchemy as sa
+from alembic import op
+
+revision: str = "c4d5e6f7a8b9"
+down_revision: str | Sequence[str] | None = "b2c3d4e5f6a7"
+branch_labels: str | Sequence[str] | None = None
+depends_on: str | Sequence[str] | None = None
+
+
+def upgrade() -> None:
+ with op.batch_alter_table("group_invite_links") as batch:
+ batch.drop_column("email_hash")
+ batch.alter_column("email_masked", existing_type=sa.String(128), nullable=True)
+
+
+def downgrade() -> None:
+ # The bound address cannot be recovered; outstanding links are dropped.
+ op.execute("DELETE FROM group_invite_links")
+ with op.batch_alter_table("group_invite_links") as batch:
+ batch.alter_column("email_masked", existing_type=sa.String(128), nullable=False)
+ batch.add_column(sa.Column("email_hash", sa.String(64), nullable=False,
+ server_default=""))
diff --git a/packages/meshbay-hub/src/meshbay_hub/db/models.py b/packages/meshbay-hub/src/meshbay_hub/db/models.py
index 51a3d47..09eb437 100644
--- a/packages/meshbay-hub/src/meshbay_hub/db/models.py
+++ b/packages/meshbay-hub/src/meshbay_hub/db/models.py
@@ -151,12 +151,12 @@ class GroupInviteLink(Base):
A link carries two secrets. The node's code decides whether someone gets the
group key, and the hub never sees it. This row decides whether someone may
- *reach* the node at all — membership, which is all the hub has to give — and
- only for the account whose verified address matches `email_hash`. The ticket
- is stored as `sha256(ticket)`, so a copy of this table opens nothing.
+ *reach* the node at all — membership, which is all the hub has to give — for
+ the first account that redeems it. The ticket is stored as `sha256(ticket)`,
+ so a copy of this table opens nothing.
- No address in the clear: `email_hash` is the same blind index `users` has,
- and `email_masked` is what the owner's list shows (`al***@ex***.com`).
+ The address is optional and binds nothing: when the inviter gave one,
+ `email_masked` is what the owner's list shows (`al***@ex***.com`).
"""
__tablename__ = "group_invite_links"
@@ -164,8 +164,7 @@ class GroupInviteLink(Base):
group_id: Mapped[str] = mapped_column(ForeignKey("groups.id"), nullable=False)
created_by: Mapped[str] = mapped_column(ForeignKey("users.id"), nullable=False)
ticket_hash: Mapped[str] = mapped_column(String(64), nullable=False)
- email_hash: Mapped[str] = mapped_column(String(64), nullable=False)
- email_masked: Mapped[str] = mapped_column(String(128), nullable=False)
+ email_masked: Mapped[str | None] = mapped_column(String(128))
# The node's handle for its half, so cancelling can take back both.
node_invite_id: Mapped[str] = mapped_column(String(32), nullable=False, default="")
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=_now)