|
|
|
@ -68,75 +68,78 @@ def get(group_name): |
|
|
|
|
print_group_lines(result) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@groups.command(short_help='Add a member to a group') |
|
|
|
|
@groups.command(short_help='Add one or more members to a group') |
|
|
|
|
@click.argument('group_name') |
|
|
|
|
@click.argument('username') |
|
|
|
|
@click.argument('usernames', nargs=-1) |
|
|
|
|
@click.option('--no-subscribe', is_flag=True, default=False, |
|
|
|
|
help='Do not subscribe the member to any auxiliary mailing lists.') |
|
|
|
|
def addmember(group_name, username, no_subscribe): |
|
|
|
|
click.confirm(f'Are you sure you want to add {username} to {group_name}?', |
|
|
|
|
abort=True) |
|
|
|
|
help='Do not subscribe the member(s) to any auxiliary mailing lists.') |
|
|
|
|
def addmember(group_name, username, usernames, no_subscribe): |
|
|
|
|
usernames = [username, *usernames] |
|
|
|
|
if len(usernames) == 1: |
|
|
|
|
click.confirm(f'Are you sure you want to add {username} to {group_name}?', |
|
|
|
|
abort=True) |
|
|
|
|
else: |
|
|
|
|
click.echo(f'The following users will be added to {group_name}:') |
|
|
|
|
click.echo(', '.join(usernames)) |
|
|
|
|
click.confirm('Do you want to continue?', abort=True) |
|
|
|
|
base_domain = component.getUtility(IConfig).get('base_domain') |
|
|
|
|
url = f'/api/groups/{group_name}/members/{username}' |
|
|
|
|
operations = AddMemberToGroupTransaction.operations |
|
|
|
|
|
|
|
|
|
if no_subscribe: |
|
|
|
|
url += '?subscribe_to_lists=false' |
|
|
|
|
operations.remove('subscribe_user_to_auxiliary_mailing_lists') |
|
|
|
|
resp = http_post(url) |
|
|
|
|
data = handle_stream_response(resp, operations) |
|
|
|
|
result = data[-1]['result'] |
|
|
|
|
lines = [] |
|
|
|
|
for i, group in enumerate(result['added_to_groups']): |
|
|
|
|
if i == 0: |
|
|
|
|
prefix = 'Added to groups' |
|
|
|
|
else: |
|
|
|
|
prefix = '' |
|
|
|
|
lines.append((prefix, group)) |
|
|
|
|
for i, mailing_list in enumerate(result.get('subscribed_to_lists', [])): |
|
|
|
|
if i == 0: |
|
|
|
|
prefix = 'Subscribed to lists' |
|
|
|
|
else: |
|
|
|
|
prefix = '' |
|
|
|
|
if '@' not in mailing_list: |
|
|
|
|
mailing_list += '@' + base_domain |
|
|
|
|
lines.append((prefix, mailing_list)) |
|
|
|
|
print_colon_kv(lines) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@groups.command(short_help='Remove a member from a group') |
|
|
|
|
for username in usernames: |
|
|
|
|
url = f'/api/groups/{group_name}/members/{username}' |
|
|
|
|
if no_subscribe: |
|
|
|
|
url += '?subscribe_to_lists=false' |
|
|
|
|
resp = http_post(url) |
|
|
|
|
data = handle_stream_response(resp, operations) |
|
|
|
|
result = data[-1]['result'] |
|
|
|
|
click.echo(f'Added {username} to ' + ', '.join(result['added_to_groups'])) |
|
|
|
|
if result.get('subscribed_to_lists'): |
|
|
|
|
mailing_lists = [ |
|
|
|
|
mailing_list + '@' + base_domain |
|
|
|
|
if '@' not in mailing_list |
|
|
|
|
else mailing_list |
|
|
|
|
for mailing_list in result['subscribed_to_lists'] |
|
|
|
|
] |
|
|
|
|
click.echo(f'Subscribed {username} to ' + ', '.join(mailing_lists)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@groups.command(short_help='Remove one or more members from a group') |
|
|
|
|
@click.argument('group_name') |
|
|
|
|
@click.argument('username') |
|
|
|
|
@click.argument('usernames', nargs=-1) |
|
|
|
|
@click.option('--no-unsubscribe', is_flag=True, default=False, |
|
|
|
|
help='Do not unsubscribe the member from any auxiliary mailing lists.') |
|
|
|
|
def removemember(group_name, username, no_unsubscribe): |
|
|
|
|
click.confirm(f'Are you sure you want to remove {username} from {group_name}?', |
|
|
|
|
abort=True) |
|
|
|
|
help='Do not unsubscribe the member(s) from any auxiliary mailing lists.') |
|
|
|
|
def removemember(group_name, username, usernames, no_unsubscribe): |
|
|
|
|
usernames = [username, *usernames] |
|
|
|
|
if len(usernames) == 1: |
|
|
|
|
click.confirm(f'Are you sure you want to remove {username} from {group_name}?', |
|
|
|
|
abort=True) |
|
|
|
|
else: |
|
|
|
|
click.echo(f'The following users will be removed from {group_name}:') |
|
|
|
|
click.echo(', '.join(usernames)) |
|
|
|
|
click.confirm('Do you want to continue?', abort=True) |
|
|
|
|
base_domain = component.getUtility(IConfig).get('base_domain') |
|
|
|
|
url = f'/api/groups/{group_name}/members/{username}' |
|
|
|
|
operations = RemoveMemberFromGroupTransaction.operations |
|
|
|
|
if no_unsubscribe: |
|
|
|
|
url += '?unsubscribe_from_lists=false' |
|
|
|
|
operations.remove('unsubscribe_user_from_auxiliary_mailing_lists') |
|
|
|
|
resp = http_delete(url) |
|
|
|
|
data = handle_stream_response(resp, operations) |
|
|
|
|
result = data[-1]['result'] |
|
|
|
|
lines = [] |
|
|
|
|
for i, group in enumerate(result['removed_from_groups']): |
|
|
|
|
if i == 0: |
|
|
|
|
prefix = 'Removed from groups' |
|
|
|
|
else: |
|
|
|
|
prefix = '' |
|
|
|
|
lines.append((prefix, group)) |
|
|
|
|
for i, mailing_list in enumerate(result.get('unsubscribed_from_lists', [])): |
|
|
|
|
if i == 0: |
|
|
|
|
prefix = 'Unsubscribed from lists' |
|
|
|
|
else: |
|
|
|
|
prefix = '' |
|
|
|
|
if '@' not in mailing_list: |
|
|
|
|
mailing_list += '@' + base_domain |
|
|
|
|
lines.append((prefix, mailing_list)) |
|
|
|
|
print_colon_kv(lines) |
|
|
|
|
for username in usernames: |
|
|
|
|
url = f'/api/groups/{group_name}/members/{username}' |
|
|
|
|
if no_unsubscribe: |
|
|
|
|
url += '?unsubscribe_from_lists=false' |
|
|
|
|
resp = http_delete(url) |
|
|
|
|
data = handle_stream_response(resp, operations) |
|
|
|
|
result = data[-1]['result'] |
|
|
|
|
click.echo(f'Removed {username} from ' + ', '.join(result['removed_from_groups'])) |
|
|
|
|
if result.get('unsubscribed_from_lists'): |
|
|
|
|
mailing_lists = [ |
|
|
|
|
mailing_list + '@' + base_domain |
|
|
|
|
if '@' not in mailing_list |
|
|
|
|
else mailing_list |
|
|
|
|
for mailing_list in result['unsubscribed_from_lists'] |
|
|
|
|
] |
|
|
|
|
click.echo(f'Unsubscribed {username} from ' + ', '.join(mailing_lists)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@groups.command(short_help='Delete a group') |
|
|
|
|