Skip to content

Commit

Permalink
feat(cli): add command for group creation
Browse files Browse the repository at this point in the history
  • Loading branch information
utnapischtim committed Jul 23, 2024
1 parent 345abfc commit 861ded0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
19 changes: 19 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,6 +18,8 @@
from flask.cli import with_appcontext
from flask_security.forms import ConfirmRegisterForm
from flask_security.utils import hash_password
from invenio_access.permissions import system_identity
from invenio_users_resources.proxies import current_groups_service
from werkzeug.datastructures import MultiDict
from werkzeug.local import LocalProxy

Expand Down Expand Up @@ -44,6 +47,11 @@ def roles():
"""Role commands."""


@click.group()
def groups():
"""Group commands."""


@users.command("create")
@click.argument("email")
@click.password_option()
Expand Down Expand Up @@ -154,3 +162,14 @@ 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")


@groups.command("create")
@click.argument("name")
@with_appcontext
@commit
def groups_create(name):
"""Create group"""
_datastore.create_role(id=name, name=name, is_managed=False)
current_groups_service.rebuild_index(system_identity)
click.secho(f'Role "({name})s" created successfully.', fg="green")
7 changes: 7 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ install_requires =
cryptography>=3.0.0
Flask-KVSession-Invenio>=0.6.3
Flask-Security-Invenio>=3.2.0
invenio_access>=2.0.0
invenio-celery>=1.2.3
invenio-i18n>=2.0.0
invenio-mail>=1.0.2
invenio-rest>=1.2.4
invenio-theme>=2.0.0
invenio_users_resources>=5.0.0
maxminddb-geolite2>=2017.404
pyjwt>=1.5.0
simplekv>=0.11.2
Expand All @@ -50,6 +52,10 @@ mysql =
invenio-db[mysql]>=1.0.14
sqlite =
invenio-db>=1.0.14
opensearch1 =
invenio-search[opensearch1]>=2.1.0,<3.0.0
opensearch2 =
invenio-search[opensearch2]>=2.1.0,<3.0.0
tests =
mock>=1.3.0
invenio-app>=1.4.0
Expand All @@ -61,6 +67,7 @@ tests =
flask.commands =
roles = invenio_accounts.cli:roles
users = invenio_accounts.cli:users
groups = invenio_accounts.cli:groups
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 861ded0

Please sign in to comment.