From abfce0adc4eb380ecd90e566e8cd715555ee73b6 Mon Sep 17 00:00:00 2001 From: Nick Satterly Date: Sun, 18 Apr 2021 10:08:11 +0200 Subject: [PATCH] feat: add and remove users to/from groups --- alertaclient/commands/cmd_group.py | 11 ++++++++--- alertaclient/commands/cmd_user.py | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/alertaclient/commands/cmd_group.py b/alertaclient/commands/cmd_group.py index ebe6d0d..ee4c693 100644 --- a/alertaclient/commands/cmd_group.py +++ b/alertaclient/commands/cmd_group.py @@ -8,13 +8,18 @@ @click.option('--id', '-i', metavar='UUID', help='Group ID') @click.option('--name', help='Group name') @click.option('--text', help='Description of user group') -@click.option('--users', '-U', is_flag=True, metavar='ID', help='Get list of group users') +@click.option('--user', '-U', help='Add user to group') +@click.option('--users', is_flag=True, metavar='ID', help='Get list of group users') @click.option('--delete', '-D', metavar='ID', help='Delete user group using ID') @click.pass_obj -def cli(obj, id, name, text, users, delete): +def cli(obj, id, name, text, user, users, delete): """Create or delete a user group.""" client = obj['client'] - if users: + if id and user: + client.add_user_to_group(id, user) + elif id and delete: + client.remove_user_from_group(id, delete) + elif users: group_users = client.get_group_users(id) timezone = obj['timezone'] headers = {'id': 'ID', 'name': 'USER', 'email': 'EMAIL', 'roles': 'ROLES', 'status': 'STATUS', diff --git a/alertaclient/commands/cmd_user.py b/alertaclient/commands/cmd_user.py index 7016f07..2638b6a 100644 --- a/alertaclient/commands/cmd_user.py +++ b/alertaclient/commands/cmd_user.py @@ -28,7 +28,7 @@ def parse_args(self, ctx, args): @click.option('--role', 'roles', multiple=True, help='List of roles') @click.option('--text', help='Description of user') @click.option('--email-verified/--email-not-verified', default=None, help='Email address verified flag') -@click.option('--groups', '-G', is_flag=True, help='Get list of user groups') +@click.option('--groups', is_flag=True, help='Get list of user groups') @click.option('--delete', '-D', metavar='ID', help='Delete user using ID') @click.pass_obj def cli(obj, id, name, email, password, status, roles, text, email_verified, groups, delete):