Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add no-input options for make-admin-user command #469

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions OpenOversight/app/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,50 @@


@click.command()
@click.option(
"-u",
"--username",
"supplied_username",
help="username for the admin account",
)
@click.option(
"-e",
"--email",
"supplied_email",
help="email for the admin account",
)
@click.option(
"-p",
"--password",
"supplied_password",
help="password for the admin account",
)
@with_appcontext
def make_admin_user():
def make_admin_user(
supplied_username: str | None,
supplied_email: str | None,
supplied_password: str | None,
):
"""Add confirmed administrator account."""
while True:
username = input("Username: ")
username = supplied_username or input("Username: ")
user = User.by_username(username).one_or_none()
if user:
print("Username is already in use")
else:
break

while True:
email = input("Email: ")
email = supplied_email or input("Email: ")
user = User.by_email(email).one_or_none()
if user:
print("Email address already in use")
else:
break

while True:
password = getpass("Password: ")
password_again = getpass("Type your password again: ")
password = supplied_password or getpass("Password: ")
password_again = supplied_password or getpass("Type your password again: ")
Comment on lines +59 to +79
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we put the while loops in a if not supplied_... block? I'm a little worried that if an existing email/username is supplied somehow that we'll fall into an infinite loop


if password == password_again:
break
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ This repository represents the **Seattle fork** of the original project. For mor

To run the project locally:
1. [Install `just`](https://github.com/casey/just)
2. Run `just fresh-start` to spin up the database and insert the initial data. **This will prompt you for information to create a local super-admin user.** Enter this information for the following fields:
2. Run `just fresh-start` to spin up the database and insert the initial data. **This will create a local super-admin user for you** with the following information:
1. `Username`: `admin`
2. `Email`: `[email protected]`
3. `Password`: `admin`
4. `Commit changes?`: `y`
3. Run `just up` and visit http://localhost:3000!
3. Visit http://localhost:3000!

To re-generate the poetry lock file (if you need to update dependencies in pyproject.toml):
1. Run `just lock`
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fresh-start: dotenv

# Start up and populate fields
{{ RUN_WEB }} python create_db.py
{{ RUN_WEB }} flask make-admin-user
{{ RUN_WEB }} flask make-admin-user --username admin --email [email protected] --password admin
{{ RUN_WEB }} flask add-department "Seattle Police Department" "SPD" "WA"
{{ RUN_WEB }} flask bulk-add-officers /data/init_data.csv

Expand Down