Skip to content

Commit b78822b

Browse files
Jeny Sadadiagctucker
Jeny Sadadia
authored andcommitted
api.admin: update setup_admin_user script to use profile
Update `setup_admin_user` method to use user profile to while creating admin user. Signed-off-by: Jeny Sadadia <jeny.sadadia@collabora.com>
1 parent aa6a165 commit b78822b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

api/admin.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from .auth import Authentication
1919
from .db import Database
20-
from .models import User, UserGroup
20+
from .models import User, UserGroup, UserProfile
2121

2222

2323
async def setup_admin_group(db):
@@ -29,18 +29,22 @@ async def setup_admin_group(db):
2929

3030

3131
async def setup_admin_user(db, username, admin_group):
32-
user_obj = await db.find_one(User, username=username)
32+
user_obj = await db.find_one_by_attributes(User,
33+
{'profile.username': username})
3334
if user_obj:
3435
print(f"User {username} already exists, aborting.")
3536
print(user_obj.json())
3637
return None
3738
password = getpass.getpass(f"Password for user '{args.username}': ")
3839
hashed_password = Authentication.get_password_hash(password)
3940
print(f"Creating {username} user...")
40-
return await db.create(User(
41+
profile = UserProfile(
4142
username=username,
4243
hashed_password=hashed_password,
4344
groups=[admin_group]
45+
)
46+
return await db.create(User(
47+
profile=profile
4448
))
4549

4650

0 commit comments

Comments
 (0)