Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/cli/admin.py
Show First 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | except DepositCollection.DoesNotExist: | ||||
click.echo(f"Create collection '{name}'.") | click.echo(f"Create collection '{name}'.") | ||||
collection = DepositCollection.objects.create(name=name) | collection = DepositCollection.objects.create(name=name) | ||||
click.echo(f"Collection '{name}' created.") | click.echo(f"Collection '{name}' created.") | ||||
return collection | return collection | ||||
@user.command("create") | @user.command("create") | ||||
@click.option("--username", required=True, help="User's name") | @click.option("--username", required=True, help="User's name") | ||||
@click.option("--password", required=True, help="Desired user's password (plain).") | @click.option("--password", help="(Deprecated) Desired user password (plain).") | ||||
@click.option("--firstname", default="", help="User's first name") | @click.option("--firstname", default="", help="User's first name") | ||||
@click.option("--lastname", default="", help="User's last name") | @click.option("--lastname", default="", help="User's last name") | ||||
@click.option("--email", default="", help="User's email") | @click.option("--email", default="", help="User's email") | ||||
@click.option("--collection", help="User's collection") | @click.option("--collection", help="User's collection") | ||||
@click.option("--provider-url", default="", help="Provider URL") | @click.option("--provider-url", default="", help="Provider URL") | ||||
@click.option("--domain", default="", help="The domain") | @click.option("--domain", default="", help="The domain") | ||||
@click.pass_context | @click.pass_context | ||||
def user_create( | def user_create( | ||||
anlambert: When the migration to Keycloak will be done, you should never have to use that CLI again
as… | |||||
Done Inline Actionsit's not entirely clear yet ;) collection, provider-url and domain are the deposit's concern for now. It has been discussed to move this over to the keycloak but same it's not ¯\_(ツ)_/¯ ardumont: it's not entirely clear yet ;)
collection, provider-url and domain are the deposit's concern… | |||||
ctx, | ctx, | ||||
username: str, | username: str, | ||||
password: str, | password: str, | ||||
firstname: str, | firstname: str, | ||||
lastname: str, | lastname: str, | ||||
email: str, | email: str, | ||||
collection: str, | collection: str, | ||||
provider_url: str, | provider_url: str, | ||||
Show All 15 Lines | if not collection: | ||||
collection = username | collection = username | ||||
# create the collection if it does not exist | # create the collection if it does not exist | ||||
collection_ = _create_collection(collection) | collection_ = _create_collection(collection) | ||||
# user create/update | # user create/update | ||||
try: | try: | ||||
user = DepositClient.objects.get(username=username) # type: ignore | user = DepositClient.objects.get(username=username) # type: ignore | ||||
click.echo(f"Update user '{username}'.") | click.echo(f"Update user '{username}'.") | ||||
user.set_password(password) | |||||
action_done = "updated" | action_done = "updated" | ||||
except DepositClient.DoesNotExist: | except DepositClient.DoesNotExist: | ||||
click.echo(f"Create user '{username}'.") | click.echo(f"Create user '{username}'.") | ||||
user = DepositClient.objects.create_user( # type: ignore | user = DepositClient(username=username) | ||||
username=username, password=password | user.save() | ||||
) | |||||
action_done = "created" | action_done = "created" | ||||
user.collections = [collection_.id] | user.collections = [collection_.id] | ||||
user.first_name = firstname | user.first_name = firstname | ||||
user.last_name = lastname | user.last_name = lastname | ||||
user.email = email | user.email = email | ||||
user.is_active = True | user.is_active = True | ||||
user.provider_url = provider_url | user.provider_url = provider_url | ||||
▲ Show 20 Lines • Show All 155 Lines • Show Last 20 Lines |
When the migration to Keycloak will be done, you should never have to use that CLI again
as user registration will be delegated to Keycloak.