From 88f1689e0e737bafdd47345545125976465ad6c0 Mon Sep 17 00:00:00 2001 From: Ilya Kreymer Date: Sat, 15 Jan 2022 00:22:40 -0800 Subject: [PATCH] crawlconfig: add 'name' property to crawl config superuser init: don't check invite token for verified superuser (automatic init) fix formatting --- backend/crawlconfigs.py | 4 ++++ backend/invites.py | 2 +- backend/users.py | 19 ++++++++++++------- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/backend/crawlconfigs.py b/backend/crawlconfigs.py index 1ef4e34c..822fb7ff 100644 --- a/backend/crawlconfigs.py +++ b/backend/crawlconfigs.py @@ -78,6 +78,8 @@ class CrawlConfigIn(BaseModel): config: RawCrawlConfig + name: Optional[str] + colls: Optional[List[str]] = [] crawlTimeout: Optional[int] = 0 @@ -92,6 +94,8 @@ class CrawlConfig(BaseMongoModel): config: RawCrawlConfig + name: Optional[str] + colls: Optional[List[str]] = [] crawlTimeout: Optional[int] = 0 diff --git a/backend/invites.py b/backend/invites.py index 69913b3e..da80131a 100644 --- a/backend/invites.py +++ b/backend/invites.py @@ -130,7 +130,7 @@ class InviteOps: created=datetime.utcnow(), role=invite.role if hasattr(invite, "role") else None, email=invite.email, - inviterEmail=user.email + inviterEmail=user.email, ) other_user = await user_manager.user_db.get_by_email(invite.email) diff --git a/backend/users.py b/backend/users.py index f14dbe13..474304bc 100644 --- a/backend/users.py +++ b/backend/users.py @@ -120,7 +120,12 @@ class UserManager(BaseUserManager[UserCreate, UserDB]): user.name = user.name or user.email # if open registration not enabled, can only register with an invite - if not self.registration_enabled and not user.inviteToken: + if ( + not self.registration_enabled + and not user.inviteToken + and not user.is_verified + and not user.is_superuser + ): raise HTTPException(status_code=400, detail="Invite Token Required") if user.inviteToken and not await self.invites.get_valid_invite( @@ -226,14 +231,14 @@ class UserManager(BaseUserManager[UserCreate, UserDB]): result = invite.serialize() result["inviterName"] = inviter.name if invite.aid: - archive = await self.archive_ops.get_archive_for_user_by_id(invite.aid, inviter) + archive = await self.archive_ops.get_archive_for_user_by_id( + invite.aid, inviter + ) result["archiveName"] = archive.name return result - - # ============================================================================ def init_user_manager(mdb, emailsender, invites): """ @@ -323,8 +328,9 @@ def init_users_api(app, user_manager): return await user_manager.format_invite(invite) @users_router.get("/me/invite/{token}", tags=["invites"]) - async def get_existing_user_invite_info(token: str, - user: User = Depends(current_active_user)): + async def get_existing_user_invite_info( + token: str, user: User = Depends(current_active_user) + ): try: invite = user.invites[token] @@ -334,7 +340,6 @@ def init_users_api(app, user_manager): return await user_manager.format_invite(invite) - app.include_router(users_router, prefix="/users", tags=["users"]) asyncio.create_task(user_manager.create_super_user())