From f21f39ef1926dc24765626f3879cc5f81a05faad Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 17 May 2023 12:08:07 +0300 Subject: auth: Delete collections by ID. --- gn3/auth/authorisation/users/collections/models.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'gn3/auth/authorisation/users/collections/models.py') diff --git a/gn3/auth/authorisation/users/collections/models.py b/gn3/auth/authorisation/users/collections/models.py index a0c3ebf..eaee9af 100644 --- a/gn3/auth/authorisation/users/collections/models.py +++ b/gn3/auth/authorisation/users/collections/models.py @@ -145,3 +145,17 @@ def get_collection(rconn: Redis, user: User, collection_id: UUID) -> dict: err.error_code = 513 raise err return colls[0] + +def delete_collections(rconn: Redis, + user: User, + collection_ids: tuple[UUID, ...]) -> tuple[dict, ...]: + """ + Delete collections with the given `collection_ids` returning the deleted + collections. + """ + ucolls = user_collections(rconn, user) + save_collections( + rconn, + user, + tuple(coll for coll in ucolls if coll["id"] not in collection_ids)) + return tuple(coll for coll in ucolls if coll["id"] in collection_ids) -- cgit v1.2.3