Add user_id field to guest_module_mas_users

Currently unused, but may be useful in future.
This commit is contained in:
Andrew Morgan
2026-01-23 14:38:19 +00:00
parent 514c6957f7
commit 2e71abdfda
4 changed files with 10 additions and 8 deletions
@@ -218,6 +218,7 @@ class GuestModule:
""" """
CREATE TABLE IF NOT EXISTS guest_module_mas_users ( CREATE TABLE IF NOT EXISTS guest_module_mas_users (
mas_user_id TEXT PRIMARY KEY, mas_user_id TEXT PRIMARY KEY,
user_id TEXT,
created_at BIGINT NOT NULL created_at BIGINT NOT NULL
) )
""", """,
@@ -104,7 +104,7 @@ class GuestRegistrationServlet(DirectServeJsonResource):
displayname + self._config.display_name_suffix, displayname + self._config.display_name_suffix,
) )
await self._store_mas_user(mas_user_id, int(time.time())) await self._store_mas_user(mas_user_id, user_id, int(time.time()))
# Determine how long to keep the access token valid for. # Determine how long to keep the access token valid for.
# #
@@ -135,7 +135,7 @@ class GuestRegistrationServlet(DirectServeJsonResource):
return 500, {"msg": "Internal error: Could not find a free username"} return 500, {"msg": "Internal error: Could not find a free username"}
async def _store_mas_user(self, mas_user_id: str, created_at: int) -> None: async def _store_mas_user(self, mas_user_id: str, user_id: str, created_at: int) -> None:
if self._mas_tables_ready is not None: if self._mas_tables_ready is not None:
await self._mas_tables_ready.wait() await self._mas_tables_ready.wait()
@@ -145,6 +145,7 @@ class GuestRegistrationServlet(DirectServeJsonResource):
table="guest_module_mas_users", table="guest_module_mas_users",
values={ values={
"mas_user_id": mas_user_id, "mas_user_id": mas_user_id,
"user_id": user_id,
"created_at": created_at, "created_at": created_at,
}, },
) )
@@ -160,5 +160,5 @@ def _setup_db(conn: sqlite3.Connection) -> None:
"CREATE TABLE users(name text, deactivated smallint, creation_ts bigint)" "CREATE TABLE users(name text, deactivated smallint, creation_ts bigint)"
) )
conn.execute( conn.execute(
"CREATE TABLE guest_module_mas_users(mas_user_id text, created_at bigint)" "CREATE TABLE guest_module_mas_users(mas_user_id text, user_id text, created_at bigint)"
) )
@@ -136,10 +136,10 @@ class GuestUserReaperTest(aiounittest.AsyncTestCase):
now = int(time.time()) now = int(time.time())
store.conn.executemany( store.conn.executemany(
"INSERT INTO guest_module_mas_users VALUES (?, ?)", "INSERT INTO guest_module_mas_users VALUES (?, ?, ?)",
[ [
["mas-old-1", 0], ["mas-old-1", "@old-1:localhost", 0],
["mas-active", now], ["mas-active", "@active:localhost", now],
], ],
) )
@@ -161,6 +161,6 @@ class GuestUserReaperTest(aiounittest.AsyncTestCase):
) )
remaining_users = store.conn.execute( remaining_users = store.conn.execute(
"SELECT mas_user_id FROM guest_module_mas_users" "SELECT mas_user_id, user_id FROM guest_module_mas_users"
).fetchall() ).fetchall()
self.assertEqual(remaining_users, [("mas-active",)]) self.assertEqual(remaining_users, [("mas-active", "@active:localhost")])