forked from cgwire/zou
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cli] for create-admin command allow to bypass protected accounts
- Loading branch information
Showing
2 changed files
with
15 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,7 +140,7 @@ def reset_migrations(): | |
|
||
@cli.command() | ||
@click.argument("email") | ||
@click.option("--password", required=True) | ||
@click.option("--password", default=None) | ||
def create_admin(email, password): | ||
""" | ||
Create an admin user to allow usage of the API when database is empty. | ||
|
@@ -149,10 +149,18 @@ def create_admin(email, password): | |
try: | ||
person = persons_service.get_person_by_email(email) | ||
if person["role"] != "admin": | ||
persons_service.update_person(person["id"], {"role": "admin"}) | ||
persons_service.update_person( | ||
person["id"], | ||
{"role": "admin"}, | ||
bypass_protected_accounts=True, | ||
) | ||
print("Existing user's role has been upgraded to 'admin'.") | ||
except PersonNotFoundException: | ||
try: | ||
if password is None: | ||
raise click.MissingParameter( | ||
param_type="option", param_hint="--password" | ||
) | ||
auth.validate_password(password) | ||
# Allow "[email protected]" to be invalid. | ||
if email != "[email protected]": | ||
|