diff options
author | Frederick Muriuki Muriithi | 2023-12-18 16:21:00 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2023-12-18 16:21:00 +0300 |
commit | 5a644ebea8bf9708ec89674e5789a88add56b440 (patch) | |
tree | dc9d86f1cea42f6a7b64b59ccc2fb11db318ef08 /gn_auth/auth/authorisation/users/collections/models.py | |
parent | 2290b274689114442c4fee87bfb1eb325c240c14 (diff) | |
download | gn-auth-5a644ebea8bf9708ec89674e5789a88add56b440.tar.gz |
Provide the correct Redis key
Previously, when the user would request to either import or delete the
collections they had created before logging in, the system would try
deleting the collections from the wrong key, leading to the
collections still showing up.
This commit fixes that by providing the code with the correct Redis
key to act upon.
Diffstat (limited to 'gn_auth/auth/authorisation/users/collections/models.py')
-rw-r--r-- | gn_auth/auth/authorisation/users/collections/models.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/gn_auth/auth/authorisation/users/collections/models.py b/gn_auth/auth/authorisation/users/collections/models.py index 9157100..9397094 100644 --- a/gn_auth/auth/authorisation/users/collections/models.py +++ b/gn_auth/auth/authorisation/users/collections/models.py @@ -10,8 +10,8 @@ from ...errors import InvalidData, NotFoundError from ..models import User +REDIS_COLLECTIONS_KEY = "collections2" __OLD_REDIS_COLLECTIONS_KEY__ = "collections" -__REDIS_COLLECTIONS_KEY__ = "collections2" class CollectionJSONEncoder(json.JSONEncoder): """Serialise collection objects into JSON.""" @@ -96,7 +96,7 @@ def __retrieve_old_user_collections__(rconn: Redis, old_user_id: UUID) -> tuple: def user_collections(rconn: Redis, user: User) -> tuple[dict, ...]: """Retrieve current user collections.""" collections = tuple(parse_collection(coll) for coll in json.loads( - rconn.hget(__REDIS_COLLECTIONS_KEY__, str(user.user_id)) or + rconn.hget(REDIS_COLLECTIONS_KEY, str(user.user_id)) or "[]")) old_accounts = __retrieve_old_accounts__(rconn) if (user.email in old_accounts and @@ -109,7 +109,7 @@ def user_collections(rconn: Redis, user: User) -> tuple[dict, ...]: }.values()) __toggle_boolean_field__(rconn, user.email, "collections-migrated") rconn.hset( - __REDIS_COLLECTIONS_KEY__, + REDIS_COLLECTIONS_KEY, key=str(user.user_id), value=json.dumps(collections, cls=CollectionJSONEncoder)) return collections @@ -117,7 +117,7 @@ def user_collections(rconn: Redis, user: User) -> tuple[dict, ...]: def save_collections(rconn: Redis, user: User, collections: tuple[dict, ...]) -> tuple[dict, ...]: """Save the `collections` to redis.""" rconn.hset( - __REDIS_COLLECTIONS_KEY__, + REDIS_COLLECTIONS_KEY, str(user.user_id), json.dumps(collections, cls=CollectionJSONEncoder)) return collections |