summaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/src/meshbay_node/roster.py
diff options
context:
space:
mode:
authorChristophe Besson <cbesson@gmail.com>2026-08-18 18:21:57 +0200
committerChristophe Besson <cbesson@gmail.com>2026-08-18 18:21:57 +0200
commitb86981f7b4ffe758136a527542ce256315823a46 (patch)
tree0d06a1cb5ca6d946d73db8724faa89bb1bd17501 /packages/meshbay-node/src/meshbay_node/roster.py
parentcd2e89f5f5cccdb116db4fcb82d00b6325972782 (diff)
downloadmeshbay-b86981f7b4ffe758136a527542ce256315823a46.tar.gz
feat(node): the operator can close uploading to everyone but themselves
A group where every member may add files stays the default. Some groups want a library the operator curates, and until now the only way to get one was to designate no upload root at all — which refuses the operator too. **The node enforces it; the interface merely stops offering it.** The Upload button in the Files toolbar and the paperclip in the chat composer both disappear, which is a courtesy to the people who are not trying. The control is `_do_file_upload` refusing with `member_upload_off`, so a member on an old tab, or one speaking MNP directly, gets the same answer. There is a test for each, and the enforcement test is in the node package rather than beside the UI one so nobody reads the hidden button as the mechanism. **Changing it is a signed operator instruction** — `OP_MEMBER_UPLOAD`, on the same path as removing a member. An unsigned one would let any member turn it back on and make the setting a suggestion. The transcript's subject is `on` or `off`: what the operator is shown before signing has to name the outcome, not the operation. **It lives on the node**, in a new `group_settings` table in `roster.db`. Not the hub, which has no business deciding who may write to someone else's disk. Not `node.toml` either: that file is hand-written and full of comments recording decisions, `ops.py` appends to it rather than round-tripping it through a writer, and a setting toggled from a panel must not rewrite the operator's file or need a restart. The value is cached in the group context because the upload path is synchronous, and the signed operation updates both — storing it without applying it would make the panel say one thing while the node did another. **Absent means allowed**, at every layer: no row in the table, no key in the context, no field in `handshake_ack`. An older node and an older client both behave exactly as before, and upgrading never silently closes a group. Each of those three has its own test, because they fail independently. The operator is always exempt — otherwise turning it off locks them out of their own node with a config file and a restart as the only way back. `is_node_admin` was being computed in two places by then and is now one function, since two copies of "is this the operator" is how the ack and the gate come to disagree. A change reaches everyone already connected via `member_upload_ack`, so the button goes without a reconnection. That message is both a broadcast and the reply to the request that caused it, which is why the client does not return early on it. Docs updated for a cold start: draft-v6 §2.1b and change 9, a new "Where Phase 13 stands" section in CLAUDE.md recording what is built, deployed and still missing, the module map row, and desktop-client-v1 §10b on the Settings tab and where group settings live. 883 tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'packages/meshbay-node/src/meshbay_node/roster.py')
-rw-r--r--packages/meshbay-node/src/meshbay_node/roster.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/packages/meshbay-node/src/meshbay_node/roster.py b/packages/meshbay-node/src/meshbay_node/roster.py
index 226b784..c811016 100644
--- a/packages/meshbay-node/src/meshbay_node/roster.py
+++ b/packages/meshbay-node/src/meshbay_node/roster.py
@@ -100,6 +100,26 @@ CREATE TABLE IF NOT EXISTS members (
PRIMARY KEY (group_id, user_id)
);
+-- Per-group settings the operator changes while the node runs.
+--
+-- Not node.toml: that file is hand-written, full of comments explaining
+-- decisions, and `ops.py` deliberately appends to it rather than round-tripping
+-- it through a TOML writer. A setting toggled from a panel has to take effect
+-- without an edit to the operator's file and without a restart, so it lives
+-- here, where the node already keeps what it decided rather than what it was
+-- configured with.
+--
+-- Absent means default. Nothing writes a row until someone changes something,
+-- so an existing node has the same behaviour it had before this table existed.
+CREATE TABLE IF NOT EXISTS group_settings (
+ group_id TEXT NOT NULL,
+ key TEXT NOT NULL,
+ value TEXT NOT NULL,
+ set_by TEXT NOT NULL DEFAULT '',
+ set_at TEXT NOT NULL DEFAULT '',
+ PRIMARY KEY (group_id, key)
+);
+
CREATE TABLE IF NOT EXISTS invites (
code_hash TEXT PRIMARY KEY,
group_id TEXT NOT NULL,
@@ -518,6 +538,43 @@ class Roster:
# ── Invites ──────────────────────────────────────────────────────────────
+ # ── Group settings ──────────────────────────────────────────────────────
+
+ # Whether members who are not the operator may upload. Default is yes: a
+ # group that nobody may add to is the unusual case, and an existing node
+ # must not change behaviour because a table was added under it.
+ SETTING_MEMBER_UPLOAD = "member_upload"
+
+ async def get_setting(self, group_id: str, key: str,
+ default: str | None = None) -> str | None:
+ async with self._db.execute(
+ "SELECT value FROM group_settings WHERE group_id = ? AND key = ?",
+ (group_id, key)) as cur:
+ row = await cur.fetchone()
+ return row["value"] if row else default
+
+ async def set_setting(self, group_id: str, key: str, value: str,
+ set_by: str = "") -> None:
+ await self._db.execute(
+ "INSERT INTO group_settings (group_id, key, value, set_by, set_at) "
+ "VALUES (?, ?, ?, ?, ?) "
+ "ON CONFLICT(group_id, key) DO UPDATE SET "
+ "value = excluded.value, set_by = excluded.set_by, "
+ "set_at = excluded.set_at",
+ (group_id, key, value, set_by, _now()))
+ await self._db.commit()
+
+ async def member_upload_allowed(self, group_id: str) -> bool:
+ """Whether an ordinary member may upload to this group."""
+ value = await self.get_setting(group_id, self.SETTING_MEMBER_UPLOAD, "1")
+ return value != "0"
+
+ async def set_member_upload(self, group_id: str, allowed: bool,
+ set_by: str = "") -> bool:
+ await self.set_setting(group_id, self.SETTING_MEMBER_UPLOAD,
+ "1" if allowed else "0", set_by)
+ return allowed
+
async def create_invite(
self,
group_id: str,