Skip to content

Commit b7ba690

Browse files
committed
modified create user command - can now designate as superuser
1 parent 0025eca commit b7ba690

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

piccolo/apps/user/commands/create.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ def get_is_admin() -> bool:
3333
return admin == "y"
3434

3535

36+
def get_is_superuser() -> bool:
37+
while True:
38+
superuser = input("Superuser? Enter y or n:\n")
39+
if superuser in ("y", "n"):
40+
break
41+
else:
42+
print("Unrecognised option")
43+
44+
return superuser == "y"
45+
46+
3647
def create():
3748
"""
3849
Create a new user.
@@ -49,13 +60,15 @@ def create():
4960
sys.exit("The password is too short")
5061

5162
is_admin = get_is_admin()
63+
is_superuser = get_is_superuser()
5264

5365
user = BaseUser(
5466
username=username,
5567
password=password,
5668
admin=is_admin,
5769
email=email,
5870
active=True,
71+
superuser=is_superuser,
5972
)
6073
user.save().run_sync()
6174

tests/apps/user/commands/test_create.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ def tearDown(self):
3131
@patch(
3232
"piccolo.apps.user.commands.create.get_is_admin", return_value=True,
3333
)
34+
@patch(
35+
"piccolo.apps.user.commands.create.get_is_superuser",
36+
return_value=True,
37+
)
3438
def test_create(self, *args, **kwargs):
3539
create()
3640

@@ -40,6 +44,7 @@ def test_create(self, *args, **kwargs):
4044
(BaseUser.admin == True) # noqa: E712
4145
& (BaseUser.username == "bob123")
4246
& (BaseUser.email == "[email protected]")
47+
& (BaseUser.superuser == True)
4348
)
4449
.run_sync()
4550
)

0 commit comments

Comments
 (0)