From d3ad243c4ae3a273f623bd5fc631e3266aa4d0e4 Mon Sep 17 00:00:00 2001 From: Christophe Besson Date: Wed, 30 Sep 2026 11:49:56 +0200 Subject: fix: only the owner decides who hosts a group, and nobody is made a member unasked MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - hub: a node may host a group only if its account owns it or the owner approved that node (new `group_hosts`). Membership was the ceiling, and every member holds the group key, so any member's node could register as a host and be the one clients kept. A node claiming a group it may not host is recorded as a request; the owner is notified once and approves or refuses it (GET/POST/DELETE /v1/groups/{id}/hosts[/{node_id}]), which takes effect on a connected node at once. - hub: an owner adding a username creates an invitation (new `group_invitations`), accepted or declined by the invitee (/v1/groups/invitations, /{id}/invitation/accept|decline). Until then the group is not listed, not dialled, not searched and not in any token. Invitation links, open joins and group creation still make members directly: they are the account's own act. - hub: the MNP token names only the group it is minted for (group_id is now required), so a node operator no longer learns a member's other groups. - SPA: invitations on the home page; invited people and host requests in the group's settings; the transport sends group_id. Ten catalogues. - Browser probes for both screens, run in Chrome and Firefox. - Design §5.2, §7.2, §7.3, AV32, AV33; protocol §6.3; user guide. Co-Authored-By: Claude Opus 5.5 --- .../a1b2c3d4e5f7_invitations_and_group_hosts.py | 49 ++++++++++++++++++++++ packages/meshbay-hub/src/meshbay_hub/db/models.py | 47 +++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 packages/meshbay-hub/src/meshbay_hub/db/migrations/versions/a1b2c3d4e5f7_invitations_and_group_hosts.py (limited to 'packages/meshbay-hub/src/meshbay_hub/db') diff --git a/packages/meshbay-hub/src/meshbay_hub/db/migrations/versions/a1b2c3d4e5f7_invitations_and_group_hosts.py b/packages/meshbay-hub/src/meshbay_hub/db/migrations/versions/a1b2c3d4e5f7_invitations_and_group_hosts.py new file mode 100644 index 0000000..b47fca0 --- /dev/null +++ b/packages/meshbay-hub/src/meshbay_hub/db/migrations/versions/a1b2c3d4e5f7_invitations_and_group_hosts.py @@ -0,0 +1,49 @@ +"""an owner's addition is an invitation; hosts are designated by the owner + +Adding somebody to a group no longer makes them a member until they accept, and +a node may host a group only if its account owns it or the owner approved it. + +Revision ID: a1b2c3d4e5f7 +Revises: f7a8b9c0d1e2 +""" + +from collections.abc import Sequence + +import sqlalchemy as sa +from alembic import op + +revision: str = "a1b2c3d4e5f7" +down_revision: str | Sequence[str] | None = "f7a8b9c0d1e2" +branch_labels: str | Sequence[str] | None = None +depends_on: str | Sequence[str] | None = None + + +def upgrade() -> None: + op.create_table( + "group_invitations", + sa.Column("group_id", sa.String(36), sa.ForeignKey("groups.id"), nullable=False), + sa.Column("user_id", sa.String(36), sa.ForeignKey("users.id"), nullable=False), + sa.Column("invited_by", sa.String(36), sa.ForeignKey("users.id"), nullable=True), + sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, + server_default=sa.func.now()), + sa.PrimaryKeyConstraint("group_id", "user_id"), + ) + op.create_index("ix_group_invitations_user", "group_invitations", ["user_id"]) + op.create_table( + "group_hosts", + sa.Column("group_id", sa.String(36), sa.ForeignKey("groups.id"), nullable=False), + sa.Column("node_id", sa.String(36), sa.ForeignKey("nodes.id"), nullable=False), + sa.Column("status", sa.String(16), nullable=False, server_default="pending"), + sa.Column("requested_at", sa.DateTime(timezone=True), nullable=False, + server_default=sa.func.now()), + sa.Column("decided_at", sa.DateTime(timezone=True), nullable=True), + sa.PrimaryKeyConstraint("group_id", "node_id"), + ) + op.create_index("ix_group_hosts_node", "group_hosts", ["node_id"]) + + +def downgrade() -> None: + op.drop_index("ix_group_hosts_node", table_name="group_hosts") + op.drop_table("group_hosts") + op.drop_index("ix_group_invitations_user", table_name="group_invitations") + op.drop_table("group_invitations") diff --git a/packages/meshbay-hub/src/meshbay_hub/db/models.py b/packages/meshbay-hub/src/meshbay_hub/db/models.py index 5b140f1..a0437d6 100644 --- a/packages/meshbay-hub/src/meshbay_hub/db/models.py +++ b/packages/meshbay-hub/src/meshbay_hub/db/models.py @@ -145,6 +145,53 @@ class GroupMember(Base): user: Mapped["User"] = relationship(back_populates="group_memberships") +class GroupInvitation(Base): + """ + Somebody asked to add this account to a group, and it has not said yes. + + Separate from `GroupMember` on purpose. A membership row is what the hub + acts on — it lets an account's client dial the group's nodes, names the + group in the account's MNP tokens and lists the group in its sidebar and in + Search — and an owner could create one for any username, unasked. That made + any account able to have any other account's client connect to a node of + its choosing. So an owner's addition is an invitation until the invitee + accepts it; redeeming an invitation link, joining an open group and creating + a group are the account's own acts and still write the membership directly. + """ + __tablename__ = "group_invitations" + + group_id: Mapped[str] = mapped_column(ForeignKey("groups.id"), primary_key=True) + user_id: Mapped[str] = mapped_column(ForeignKey("users.id"), primary_key=True) + invited_by: Mapped[str | None] = mapped_column(ForeignKey("users.id")) + created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=_now) + + __table_args__ = (Index("ix_group_invitations_user", "user_id"),) + + +class GroupHost(Base): + """ + A node the group's owner has approved as a host, refused, or not yet + answered (`approved` / `refused` / `pending`). + + A node registers for the groups it claims, and clients connect to whichever + registered node answers first. Every member holds the group key, so a + member's node passes the handshake like the real host would: the ceiling on + what a node may claim cannot be "groups its account belongs to". It is + "groups its account owns", plus the nodes listed here as `approved`. A node + that claims a group it may not host is recorded `pending`, and the owner is + told, so a legitimate second host is one click away rather than refused. + """ + __tablename__ = "group_hosts" + + group_id: Mapped[str] = mapped_column(ForeignKey("groups.id"), primary_key=True) + node_id: Mapped[str] = mapped_column(ForeignKey("nodes.id"), primary_key=True) + status: Mapped[str] = mapped_column(String(16), default="pending", nullable=False) + requested_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=_now) + decided_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True)) + + __table_args__ = (Index("ix_group_hosts_node", "node_id"),) + + class GroupInviteLink(Base): """ The hub's half of an invitation link (docs/MESHBAY_DESIGN.md §7.3). -- cgit v1.2.3