Skip to content

Commit

Permalink
api.admin: use user_models.User
Browse files Browse the repository at this point in the history
Use latest `User` model schema implemented using
`fastapi-users` package.
Initialize Beanie as per the package requirement
before inserting document to database.

Signed-off-by: Jeny Sadadia <[email protected]>
  • Loading branch information
Jeny Sadadia committed Oct 11, 2023
1 parent de35e85 commit 1f43b4b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

from .auth import Authentication
from .db import Database
from .models import User, UserGroup, UserProfile
from .models import UserGroup
from .user_models import User


async def setup_admin_group(db, admin_group):
Expand All @@ -42,19 +43,18 @@ async def setup_admin_user(db, username, email, admin_group):
return None
hashed_password = Authentication.get_password_hash(password)
print(f"Creating {username} user...")
profile = UserProfile(
return await db.create(User(
username=username,
hashed_password=hashed_password,
email=email,
groups=[admin_group]
)
return await db.create(User(
profile=profile
groups=[admin_group],
is_superuser=1
))


async def main(args):
db = Database(args.mongo, args.database)
await db.initialize_beanie()
group = await setup_admin_group(db, args.admin_group)
user = await setup_admin_user(db, args.username, args.email, group)
return True
Expand Down

0 comments on commit 1f43b4b

Please sign in to comment.