From 748c86700d9bdefb60e52a67861196ba5597a2a6 Mon Sep 17 00:00:00 2001 From: Tessa Walsh Date: Fri, 6 Oct 2023 00:30:10 -0400 Subject: [PATCH] fix: lookup user object operator to pass to CrawlConfig.add_new_crawl (#1254) fixes #1253 Co-authored-by: Ilya Kreymer --- backend/btrixcloud/operator.py | 4 +++- backend/btrixcloud/users.py | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/backend/btrixcloud/operator.py b/backend/btrixcloud/operator.py index 3abacf54..d41b7b93 100644 --- a/backend/btrixcloud/operator.py +++ b/backend/btrixcloud/operator.py @@ -228,6 +228,7 @@ class BtrixOperator(K8sAPI): super().__init__() self.crawl_config_ops = crawl_config_ops + self.user_ops = crawl_config_ops.user_manager self.crawl_ops = crawl_ops self.org_ops = org_ops self.coll_ops = coll_ops @@ -1261,8 +1262,9 @@ class BtrixOperator(K8sAPI): return {"attachments": []} # db create + user = await self.user_ops.get_user_by_id(uuid.UUID(userid)) await self.crawl_config_ops.add_new_crawl( - crawl_id, crawlconfig, uuid.UUID(userid), manual=False + crawl_id, crawlconfig, user, manual=False ) print("Scheduled Crawl Created: " + crawl_id) diff --git a/backend/btrixcloud/users.py b/backend/btrixcloud/users.py index 047f29ee..80458435 100644 --- a/backend/btrixcloud/users.py +++ b/backend/btrixcloud/users.py @@ -121,6 +121,10 @@ class UserManager(BaseUserManager[UserCreate, UserDB]): ) return await cursor.to_list(length=1000) + async def get_user_by_id(self, user_id: uuid.UUID): + """return user from user_id""" + return await self.user_db.get(user_id) + async def get_superuser(self): """return current superuser, if any""" return await self.user_db.collection.find_one({"is_superuser": True})