aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/src/meshbay_node
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-node/src/meshbay_node')
-rw-r--r--packages/meshbay-node/src/meshbay_node/daemon.py14
-rw-r--r--packages/meshbay-node/src/meshbay_node/ops.py22
-rw-r--r--packages/meshbay-node/src/meshbay_node/roster.py15
3 files changed, 45 insertions, 6 deletions
diff --git a/packages/meshbay-node/src/meshbay_node/daemon.py b/packages/meshbay-node/src/meshbay_node/daemon.py
index bb50bcf..c16e49f 100644
--- a/packages/meshbay-node/src/meshbay_node/daemon.py
+++ b/packages/meshbay-node/src/meshbay_node/daemon.py
@@ -2409,9 +2409,17 @@ def main() -> None:
cfg, f"/api/members/{match['user_id']}/revoke?group_id={group_id}",
method="POST")
print(f"{args.target} revoked from {group_id[:8]}")
- print("They stop receiving the group key on their next connection.")
- print("They still hold the current one — rotate it:")
- print(f" meshbay-node gek-init --group {group_id}")
+ if out.get("invites_dropped"):
+ print("Their unredeemed invitation was cancelled.")
+ # The node decides whether a rotation is warranted and says so in
+ # the reminder — somebody who never redeemed a code never held the
+ # key, and advising a rotation there is advice to ignore the next
+ # time it is real. Deciding it again here is the second
+ # implementation this file exists not to have.
+ if out.get("reminder"):
+ print("They stop receiving the group key on their next connection.")
+ print("They still hold the current one — rotate it:")
+ print(f" meshbay-node gek-init --group {group_id}")
return
if sub == "unpin":
diff --git a/packages/meshbay-node/src/meshbay_node/ops.py b/packages/meshbay-node/src/meshbay_node/ops.py
index baea365..b680d43 100644
--- a/packages/meshbay-node/src/meshbay_node/ops.py
+++ b/packages/meshbay-node/src/meshbay_node/ops.py
@@ -243,13 +243,29 @@ async def revoke_member(state: dict, user_id: str, group_id: str) -> dict:
Takes effect on their next connection: the key is wrapped on demand, so there
is no stored bundle left behind that would outlive this. Rotating the group
key is still required — they hold the current one.
+
+ **An unredeemed invite is a membership that has not happened yet**, so it is
+ revoked here too, and on its own it is enough for this to be a removal. A
+ member row appears only when a code is consumed: somebody invited to the
+ wrong group has none, this refused them with "no such member", and the
+ browser's removal — node half first, deliberately — died on that refusal
+ before it reached the hub half. They stayed a member on the hub, with a live
+ code, and the interface offered no other way to take either back.
"""
roster = _roster(state)
- if not await roster.set_status(group_id, user_id, "revoked"):
+ revoked = await roster.set_status(group_id, user_id, "revoked")
+ dropped = await roster.drop_invites(group_id, user_id)
+ if not revoked and not dropped:
raise OpError("No such member in that group", status=404)
- log.info("Member revoked: user=%s group=%s", user_id[:8], group_id[:8])
+ log.info("Member revoked: user=%s group=%s member=%s invites_dropped=%d",
+ user_id[:8], group_id[:8], revoked, dropped)
return {"status": "revoked", "user_id": user_id, "group_id": group_id,
- "reminder": "rotate the group key: meshbay-node gek rotate"}
+ "was_member": revoked, "invites_dropped": dropped,
+ # Only what is true: somebody who never redeemed a code never held
+ # the key, and telling an operator to rotate it teaches them that
+ # the advice is noise.
+ "reminder": ("rotate the group key: meshbay-node gek rotate"
+ if revoked else "")}
async def unpin_member(state: dict, user_id: str) -> dict:
diff --git a/packages/meshbay-node/src/meshbay_node/roster.py b/packages/meshbay-node/src/meshbay_node/roster.py
index 9478a32..9533f25 100644
--- a/packages/meshbay-node/src/meshbay_node/roster.py
+++ b/packages/meshbay-node/src/meshbay_node/roster.py
@@ -1081,6 +1081,21 @@ class Roster:
await self._db.commit()
return code
+ async def drop_invites(self, group_id: str, user_id: str) -> int:
+ """
+ Cancel any code this person has not redeemed yet for this group.
+
+ A code already used is left alone: `used_at` is the record that the join
+ happened, and it is the only thing that makes a second attempt fail.
+ """
+ assert self._db
+ cur = await self._db.execute(
+ "DELETE FROM invites WHERE group_id = ? AND user_id = ? AND used_at IS NULL",
+ (group_id, user_id),
+ )
+ await self._db.commit()
+ return cur.rowcount
+
async def consume_invite(self, code: str, user_id: str) -> dict | None:
"""
Redeem a code for `user_id`, or return None.