found the issue. messages init was overwritting users bucket each time server started

This commit is contained in:
Michael Woods
2025-01-09 13:48:02 -05:00
parent 7daf78f133
commit 287b671afd
2 changed files with 13 additions and 8 deletions

View File

@@ -54,6 +54,7 @@ class Server:
self.storage = ZODB.FileStorage.FileStorage(self.data_file) self.storage = ZODB.FileStorage.FileStorage(self.data_file)
self.db = ZODB.DB(self.storage) self.db = ZODB.DB(self.storage)
with self.db.transaction() as conn: with self.db.transaction() as conn:
logging.debug(f"checking for datastructures: conn.root.keys(): {list(conn.root().keys())}")
if 'config' not in conn.root(): if 'config' not in conn.root():
logging.debug("no config, writing blank default config") logging.debug("no config, writing blank default config")
conn.root.config = PersistentMapping(deepcopy(default_server_config)) conn.root.config = PersistentMapping(deepcopy(default_server_config))
@@ -66,7 +67,7 @@ class Server:
conn.root.users = PersistentMapping() conn.root.users = PersistentMapping()
if 'messages' not in conn.root(): if 'messages' not in conn.root():
logging.debug("messages container missing, creating bucket") logging.debug("messages container missing, creating bucket")
conn.root.users = PersistentMapping() conn.root.messages = PersistentMapping()
if 'SYSTEM' not in conn.root.users: if 'SYSTEM' not in conn.root.users:
logging.debug("Creating system user for first time.") logging.debug("Creating system user for first time.")
User('SYSTEM', hidden=True, enabled=False).write_new(conn.root()) User('SYSTEM', hidden=True, enabled=False).write_new(conn.root())
@@ -103,11 +104,14 @@ class Server:
blacklisted = True blacklisted = True
# user object check # user object check
logging.debug(f"checking user existence for {base}")
logging.debug(f"users in db right now: {list(storage.root.users.keys())}")
if base in storage.root.users: if base in storage.root.users:
logging.debug(f"User {base} exists in db.") logging.debug(f"User {base} exists in db.")
u = storage.root.users[base] u = storage.root.users[base]
u.seen() u.seen()
else: else:
logging.debug(f"User {base} doesn't exist in db")
logging.info(f"Creating new user {base}") logging.info(f"Creating new user {base}")
u = User(base.upper().strip()) u = User(base.upper().strip())
u.write_new(storage.root()) u.write_new(storage.root())

View File

@@ -104,8 +104,10 @@ class Object(persistent.Persistent):
db.root.objects[self.uuid].owner = user.uuid db.root.objects[self.uuid].owner = user.uuid
if old_owner_uuid: if old_owner_uuid:
if old_owner: if old_owner:
logging.debug(f"The object has an old owner user: {old_owner}")
old_owner.remove_obj_uuid(self.uuid) old_owner.remove_obj_uuid(self.uuid)
logging.debug("adding object uuid to user objects set") logging.debug(f"adding this object uuid to user objects set ({self.uuid})")
logging.debug(f"user {user} objects before: {user.object_uuids}")
user.add_obj_uuid(self.uuid) user.add_obj_uuid(self.uuid)
logging.debug(f"user objects now: {user.object_uuids}") logging.debug(f"user objects now: {user.object_uuids}")
else: else:
@@ -329,15 +331,14 @@ def handle_object_post(req: Request, conn: PacketServerConnection, db: ZODB.DB):
except: except:
logging.debug(f"Error parsing new object:\n{format_exc()}") logging.debug(f"Error parsing new object:\n{format_exc()}")
send_blank_response(conn, req, status_code=400) send_blank_response(conn, req, status_code=400)
retur return
username = ax25.Address(conn.remote_callsign).call.upper().strip()
with db.transaction() as db_conn:
logging.debug(f"User {username}'s objects: {db_conn.root.users[username].object_uuids}")
logging.debug(f"writing new object: {obj}") logging.debug(f"writing new object: {obj}")
obj.write_new(db) obj.write_new(db)
with db.transaction() as db_conn:
logging.debug(f"looking up new object")
new_obj = Object.get_object_by_uuid(obj.uuid, db_conn.root())
username = ax25.Address(conn.remote_callsign).call.upper().strip()
logging.debug("chowning new object") logging.debug("chowning new object")
new_obj.chown(username, db) obj.chown(username, db)
send_blank_response(conn, req, status_code=201, payload=str(obj.uuid)) send_blank_response(conn, req, status_code=201, payload=str(obj.uuid))
def handle_object_update(req: Request, conn: PacketServerConnection, db: ZODB.DB): def handle_object_update(req: Request, conn: PacketServerConnection, db: ZODB.DB):