fix: lookup user object operator to pass to CrawlConfig.add_new_crawl (#1254)

fixes #1253 
Co-authored-by: Ilya Kreymer <ikreymer@gmail.com>
This commit is contained in:
Tessa Walsh 2023-10-06 00:30:10 -04:00 committed by GitHub
parent fa86555eed
commit 748c86700d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -228,6 +228,7 @@ class BtrixOperator(K8sAPI):
super().__init__() super().__init__()
self.crawl_config_ops = crawl_config_ops self.crawl_config_ops = crawl_config_ops
self.user_ops = crawl_config_ops.user_manager
self.crawl_ops = crawl_ops self.crawl_ops = crawl_ops
self.org_ops = org_ops self.org_ops = org_ops
self.coll_ops = coll_ops self.coll_ops = coll_ops
@ -1261,8 +1262,9 @@ class BtrixOperator(K8sAPI):
return {"attachments": []} return {"attachments": []}
# db create # db create
user = await self.user_ops.get_user_by_id(uuid.UUID(userid))
await self.crawl_config_ops.add_new_crawl( 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) print("Scheduled Crawl Created: " + crawl_id)

View File

@ -121,6 +121,10 @@ class UserManager(BaseUserManager[UserCreate, UserDB]):
) )
return await cursor.to_list(length=1000) 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): async def get_superuser(self):
"""return current superuser, if any""" """return current superuser, if any"""
return await self.user_db.collection.find_one({"is_superuser": True}) return await self.user_db.collection.find_one({"is_superuser": True})