Skip to content

Commit

Permalink
cli: add command for domain create
Browse files Browse the repository at this point in the history
  • Loading branch information
utnapischtim committed Jul 30, 2024
1 parent 345abfc commit 4eb1a16
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
24 changes: 24 additions & 0 deletions invenio_accounts/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# This file is part of Invenio.
# Copyright (C) 2015-2023 CERN.
# Copyright (C) 2024 Graz University of Technology.
#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand All @@ -17,9 +18,12 @@
from flask.cli import with_appcontext
from flask_security.forms import ConfirmRegisterForm
from flask_security.utils import hash_password
from invenio_db import db
from werkzeug.datastructures import MultiDict
from werkzeug.local import LocalProxy

from .models import DomainCategory

_datastore = LocalProxy(lambda: current_app.extensions["security"].datastore)


Expand All @@ -44,6 +48,11 @@ def roles():
"""Role commands."""


@click.group()
def domains():
"""Domain commands."""


@users.command("create")
@click.argument("email")
@click.password_option()
Expand Down Expand Up @@ -154,3 +163,18 @@ def users_deactivate(user):
click.secho('User "%s" has been deactivated.' % user, fg="green")
else:
click.secho('User "%s" was already deactivated.' % user, fg="yellow")


@domains.command("create")
@click.argument("domain")
@with_appcontext
def domains_create(domain):
"""Create domain."""
try:
domain_category = DomainCategory.create(domain.lower())
db.session.merge(domain_category)
db.session.commit()
except Exception as error:
click.secho(f"Domain {domain} creating failed with {error}", fg="red")
else:
click.secho(f"Domain {domain} created successfully", fg="green")
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ tests =
flask.commands =
roles = invenio_accounts.cli:roles
users = invenio_accounts.cli:users
domains = invenio_accounts.cli:domains
invenio_admin.views =
invenio_accounts_user = invenio_accounts.admin:user_adminview
invenio_accounts_role = invenio_accounts.admin:role_adminview
Expand Down

0 comments on commit 4eb1a16

Please sign in to comment.