Skip to content

Commit

Permalink
Adds cli to register a user from the command line (#3292)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevgliss authored Apr 21, 2023
1 parent 3ea996f commit b6fc587
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/dispatch/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,43 @@ def dispatch_user():
pass


@dispatch_user.command("register")
@click.argument("email")
@click.option(
"--organization",
"-o",
required=True,
help="Organization to set role for.",
)
@click.password_option()
@click.option(
"--role",
"-r",
required=True,
type=click.Choice(UserRoles),
help="Role to be assigned to the user.",
)
def register_user(email: str, role: str, password: str, organization: str):
"""Registers a new user."""
from dispatch.database.core import refetch_db_session
from dispatch.auth import service as user_service
from dispatch.auth.models import UserRegister, UserOrganization

db_session = refetch_db_session(organization_slug=organization)
user = user_service.get_by_email(email=email, db_session=db_session)
if user:
click.secho(f"User already exists. Email: {email}", fg="red")
return

user_organization = UserOrganization(role=role, organization={"name": organization})
user_service.create(
user_in=UserRegister(email=email, password=password, organizations=[user_organization]),
db_session=db_session,
organization=organization,
)
click.secho("User registered successfully.", fg="green")


@dispatch_user.command("update")
@click.argument("email")
@click.option(
Expand Down

0 comments on commit b6fc587

Please sign in to comment.