diff options
author | Frederick Muriuki Muriithi | 2023-06-20 20:01:33 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2023-06-20 20:01:33 +0300 |
commit | 4e40d4e48a2d41602647832f659ec1f43f991b7a (patch) | |
tree | 2a625c967c62166b1ff465665cd0cafd041a659e /gn3/auth/authorisation/users | |
parent | 9193597f12631bcf33ce768f2842132bd22a41c3 (diff) | |
download | genenetwork3-4e40d4e48a2d41602647832f659ec1f43f991b7a.tar.gz |
Bug: Don't overwrite/delete old collections
Diffstat (limited to 'gn3/auth/authorisation/users')
-rw-r--r-- | gn3/auth/authorisation/users/collections/models.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/gn3/auth/authorisation/users/collections/models.py b/gn3/auth/authorisation/users/collections/models.py index 1f0803f..8e37ef9 100644 --- a/gn3/auth/authorisation/users/collections/models.py +++ b/gn3/auth/authorisation/users/collections/models.py @@ -10,6 +10,9 @@ from gn3.auth.authorisation.errors import InvalidData, NotFoundError from ..models import User +__OLD_COLLECTIONS_DOC__ = "collections" +__COLLECTIONS_DOC__ = "collections2" + class CollectionJSONEncoder(json.JSONEncoder): """Serialise collection objects into JSON.""" def default(self, obj):# pylint: disable=[arguments-renamed] @@ -87,7 +90,8 @@ def dump_collection(pythoncollection: dict) -> str: def __retrieve_old_user_collections__(rconn: Redis, old_user_id: UUID) -> tuple: """Retrieve any old collections relating to the user.""" return tuple(parse_collection(coll) for coll in - json.loads(rconn.hget("collections", str(old_user_id)) or "[]")) + json.loads(rconn.hget( + __OLD_COLLECTIONS_DOC__, str(old_user_id)) or "[]")) def user_collections(rconn: Redis, user: User) -> tuple[dict, ...]: """Retrieve current user collections.""" @@ -100,16 +104,17 @@ def user_collections(rconn: Redis, user: User) -> tuple[dict, ...]: old_user_id = old_accounts[user.email]["user_id"] collections = tuple(collections + __retrieve_old_user_collections__( rconn, UUID(old_user_id))) - rconn.hdel("collections", old_user_id) __toggle_boolean_field__(rconn, user.email, "collections-migrated") rconn.hset( - "collections", key=user.user_id, value=json.dumps(collections)) + __COLLECTIONS_DOC__, + key=user.user_id, + value=json.dumps(collections)) return collections def save_collections(rconn: Redis, user: User, collections: tuple[dict, ...]) -> tuple[dict, ...]: """Save the `collections` to redis.""" rconn.hset( - "collections", + __COLLECTIONS_DOC__, str(user.user_id), json.dumps(collections, cls=CollectionJSONEncoder)) return collections |