Fixes #66, not tested yet #94
|
@ -32,11 +32,12 @@ Host: {db_host}''')
|
|||
click.echo(f"\nWe were unable to write these settings to {filename}.")
|
||||
|
||||
|
||||
def create(username: str, db_type: str):
|
||||
def create(username: str, db_type: str, yes: bool):
|
||||
db_type_name = 'MySQL' if db_type == 'mysql' else 'PostgreSQL'
|
||||
resp = http_get(f'/api/members/{username}')
|
||||
user_dict = handle_sync_response(resp)
|
||||
click.confirm(f'Are you sure you want to create a {db_type_name} database for {username}?', abort=True)
|
||||
if not yes:
|
||||
click.confirm(f'Are you sure you want to create a {db_type_name} database for {username}?', abort=True)
|
||||
|
||||
info_file_path = os.path.join(user_dict['home_directory'], f"ceo-{db_type}-info")
|
||||
|
||||
|
@ -47,11 +48,12 @@ def create(username: str, db_type: str):
|
|||
db_cli_response(info_file_path, user_dict, password, db_type, 'create')
|
||||
|
||||
|
||||
def pwreset(username: str, db_type: str):
|
||||
def pwreset(username: str, db_type: str, yes: bool):
|
||||
db_type_name = 'MySQL' if db_type == 'mysql' else 'PostgreSQL'
|
||||
resp = http_get(f'/api/members/{username}')
|
||||
user_dict = handle_sync_response(resp)
|
||||
click.confirm(f'Are you sure you want reset the {db_type_name} password for {username}?', abort=True)
|
||||
if not yes:
|
||||
click.confirm(f'Are you sure you want reset the {db_type_name} password for {username}?', abort=True)
|
||||
|
||||
info_file_path = os.path.join(user_dict['home_directory'], f"ceo-{db_type}-info")
|
||||
|
||||
|
@ -62,9 +64,10 @@ def pwreset(username: str, db_type: str):
|
|||
db_cli_response(info_file_path, user_dict, password, db_type, 'pwreset')
|
||||
|
||||
|
||||
def delete(username: str, db_type: str):
|
||||
def delete(username: str, db_type: str, yes: bool):
|
||||
check_if_in_development()
|
||||
db_type_name = 'MySQL' if db_type == 'mysql' else 'PostgreSQL'
|
||||
click.confirm(f"Are you sure you want to delete the {db_type_name} database for {username}?", abort=True)
|
||||
if not yes:
|
||||
click.confirm(f"Are you sure you want to delete the {db_type_name} database for {username}?", abort=True)
|
||||
resp = http_delete(f'/api/db/{db_type}/{username}')
|
||||
handle_sync_response(resp)
|
||||
|
|
|
@ -23,7 +23,8 @@ def groups():
|
|||
@groups.command(short_help='Add a new group')
|
||||
@click.argument('group_name')
|
||||
@click.option('-d', '--description', help='Group description', prompt=True)
|
||||
def add(group_name, description):
|
||||
@click.option('--yes', '-y', is_flag=True, default=False)
|
||||
def add(group_name, description, yes):
|
||||
click.echo('The following group will be created:')
|
||||
lines = [
|
||||
('cn', group_name),
|
||||
|
@ -31,7 +32,8 @@ def add(group_name, description):
|
|||
]
|
||||
print_colon_kv(lines)
|
||||
|
||||
click.confirm('Do you want to continue?', abort=True)
|
||||
if not yes:
|
||||
click.confirm('Do you want to continue?', abort=True)
|
||||
|
||||
body = {
|
||||
'cn': group_name,
|
||||
|
@ -74,15 +76,17 @@ def get(group_name):
|
|||
@click.argument('usernames', nargs=-1)
|
||||
@click.option('--no-subscribe', is_flag=True, default=False,
|
||||
help='Do not subscribe the member(s) to any auxiliary mailing lists.')
|
||||
def addmember(group_name, username, usernames, no_subscribe):
|
||||
@click.option('--yes', '-y', is_flag=True, default=False)
|
||||
def addmember(group_name, username, usernames, no_subscribe, yes):
|
||||
usernames = [username, *usernames]
|
||||
if len(usernames) == 1:
|
||||
if not yes or 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)
|
||||
if not yes:
|
||||
click.confirm('Do you want to continue?', abort=True)
|
||||
base_domain = component.getUtility(IConfig).get('base_domain')
|
||||
operations = AddMemberToGroupTransaction.operations
|
||||
if no_subscribe:
|
||||
|
@ -111,15 +115,17 @@ def addmember(group_name, username, usernames, no_subscribe):
|
|||
@click.argument('usernames', nargs=-1)
|
||||
@click.option('--no-unsubscribe', is_flag=True, default=False,
|
||||
help='Do not unsubscribe the member(s) from any auxiliary mailing lists.')
|
||||
def removemember(group_name, username, usernames, no_unsubscribe):
|
||||
@click.option('--yes', '-y', is_flag=True, default=False)
|
||||
def removemember(group_name, username, usernames, no_unsubscribe, yes):
|
||||
usernames = [username, *usernames]
|
||||
if len(usernames) == 1:
|
||||
if not yes or 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)
|
||||
if not yes:
|
||||
click.confirm('Do you want to continue?', abort=True)
|
||||
base_domain = component.getUtility(IConfig).get('base_domain')
|
||||
operations = RemoveMemberFromGroupTransaction.operations
|
||||
if no_unsubscribe:
|
||||
|
|
|
@ -12,8 +12,10 @@ def mailman():
|
|||
@mailman.command(short_help='Subscribe a member to a mailing list')
|
||||
@click.argument('username')
|
||||
@click.argument('mailing_list')
|
||||
def subscribe(username, mailing_list):
|
||||
click.confirm(f'Are you sure you want to subscribe {username} to {mailing_list}?', abort=True)
|
||||
@click.option('--yes', '-y', is_flag=True, default=False)
|
||||
def subscribe(username, mailing_list, yes):
|
||||
if not yes:
|
||||
click.confirm(f'Are you sure you want to subscribe {username} to {mailing_list}?', abort=True)
|
||||
resp = http_post(f'/api/mailman/{mailing_list}/{username}')
|
||||
handle_sync_response(resp)
|
||||
click.echo('Done.')
|
||||
|
@ -22,8 +24,10 @@ def subscribe(username, mailing_list):
|
|||
@mailman.command(short_help='Unsubscribe a member from a mailing list')
|
||||
@click.argument('username')
|
||||
@click.argument('mailing_list')
|
||||
def unsubscribe(username, mailing_list):
|
||||
click.confirm(f'Are you sure you want to unsubscribe {username} from {mailing_list}?', abort=True)
|
||||
@click.option('--yes', '-y', is_flag=True, default=False)
|
||||
def unsubscribe(username, mailing_list, yes):
|
||||
if not yes:
|
||||
click.confirm(f'Are you sure you want to unsubscribe {username} from {mailing_list}?', abort=True)
|
||||
resp = http_delete(f'/api/mailman/{mailing_list}/{username}')
|
||||
handle_sync_response(resp)
|
||||
click.echo('Done.')
|
||||
|
|
|
@ -33,7 +33,8 @@ def members():
|
|||
help=('Forwarding address to set in ~/.forward. '
|
||||
'Default is UW address. '
|
||||
'Set to the empty string to disable forwarding.'))
|
||||
def add(username, cn, given_name, sn, program, num_terms, clubrep, forwarding_address):
|
||||
@click.option('--yes', '-y', is_flag=True, default=False)
|
||||
def add(username, cn, given_name, sn, program, num_terms, clubrep, forwarding_address, yes):
|
||||
cfg = component.getUtility(IConfig)
|
||||
uw_domain = cfg.get('uw_domain')
|
||||
|
||||
|
@ -81,7 +82,8 @@ def add(username, cn, given_name, sn, program, num_terms, clubrep, forwarding_ad
|
|||
|
||||
click.echo("The following user will be created:")
|
||||
print_user_lines(body)
|
||||
click.confirm('Do you want to continue?', abort=True)
|
||||
if not yes:
|
||||
click.confirm('Do you want to continue?', abort=True)
|
||||
|
||||
operations = get_adduser_operations(body)
|
||||
|
||||
|
@ -118,7 +120,8 @@ def get(username):
|
|||
'Comma-separated list of forwarding addresses. '
|
||||
'Set to the empty string to disable forwarding.'
|
||||
))
|
||||
def modify(username, login_shell, forwarding_addresses):
|
||||
@click.option('--yes', '-y', is_flag=True, default=False)
|
||||
def modify(username, login_shell, forwarding_addresses, yes):
|
||||
if login_shell is None and forwarding_addresses is None:
|
||||
click.echo('Nothing to do.')
|
||||
sys.exit()
|
||||
|
@ -143,7 +146,8 @@ def modify(username, login_shell, forwarding_addresses):
|
|||
else:
|
||||
click.echo(prefix)
|
||||
|
||||
click.confirm('Do you want to continue?', abort=True)
|
||||
if not yes:
|
||||
click.confirm('Do you want to continue?', abort=True)
|
||||
|
||||
resp = http_patch('/api/members/' + username, json=body)
|
||||
handle_stream_response(resp, operations)
|
||||
|
@ -155,7 +159,8 @@ def modify(username, login_shell, forwarding_addresses):
|
|||
help='Number of terms to add', prompt='Number of terms')
|
||||
@click.option('--clubrep', is_flag=True, default=False,
|
||||
help='Add non-member terms instead of member terms')
|
||||
def renew(username, num_terms, clubrep):
|
||||
@click.option('--yes', '-y', is_flag=True, default=False)
|
||||
def renew(username, num_terms, clubrep, yes):
|
||||
terms = get_terms_for_renewal_for_user(username, num_terms, clubrep)
|
||||
|
||||
if clubrep:
|
||||
|
@ -165,7 +170,8 @@ def renew(username, num_terms, clubrep):
|
|||
body = {'terms': terms}
|
||||
click.echo('The following member terms will be added: ' + ','.join(terms))
|
||||
|
||||
click.confirm('Do you want to continue?', abort=True)
|
||||
if not yes:
|
||||
click.confirm('Do you want to continue?', abort=True)
|
||||
|
||||
resp = http_post(f'/api/members/{username}/renew', json=body)
|
||||
handle_sync_response(resp)
|
||||
|
@ -174,8 +180,10 @@ def renew(username, num_terms, clubrep):
|
|||
|
||||
@members.command(short_help="Reset a user's password")
|
||||
@click.argument('username')
|
||||
def pwreset(username):
|
||||
click.confirm(f"Are you sure you want to reset {username}'s password?", abort=True)
|
||||
@click.option('--yes', '-y', is_flag=True, default=False)
|
||||
def pwreset(username, yes):
|
||||
if not yes:
|
||||
click.confirm(f"Are you sure you want to reset {username}'s password?", abort=True)
|
||||
resp = http_post(f'/api/members/{username}/pwreset')
|
||||
result = handle_sync_response(resp)
|
||||
click.echo('New password: ' + result['password'])
|
||||
|
@ -183,9 +191,11 @@ def pwreset(username):
|
|||
|
||||
@members.command(short_help="Delete a user")
|
||||
@click.argument('username')
|
||||
def delete(username):
|
||||
@click.option('--yes', '-y', is_flag=True, default=False)
|
||||
def delete(username, yes):
|
||||
check_if_in_development()
|
||||
click.confirm(f"Are you sure you want to delete {username}?", abort=True)
|
||||
if not yes:
|
||||
click.confirm(f"Are you sure you want to delete {username}?", abort=True)
|
||||
resp = http_delete(f'/api/members/{username}')
|
||||
handle_stream_response(resp, DeleteMemberTransaction.operations)
|
||||
|
||||
|
|
|
@ -10,17 +10,20 @@ def mysql():
|
|||
|
||||
@mysql.command(short_help='Create a MySQL database for a user')
|
||||
@click.argument('username')
|
||||
def create(username):
|
||||
db_create(username, 'mysql')
|
||||
@click.option('--yes', '-y', is_flag=True, default=False)
|
||||
def create(username, yes):
|
||||
db_create(username, 'mysql', yes)
|
||||
|
||||
|
||||
@mysql.command(short_help='Reset the password of a MySQL user')
|
||||
@click.argument('username')
|
||||
def pwreset(username):
|
||||
db_pwreset(username, 'mysql')
|
||||
@click.option('--yes', '-y', is_flag=True, default=False)
|
||||
def pwreset(username, yes):
|
||||
db_pwreset(username, 'mysql', yes)
|
||||
|
||||
|
||||
@mysql.command(short_help="Delete the database of a MySQL user")
|
||||
@click.argument('username')
|
||||
def delete(username):
|
||||
db_delete(username, 'mysql')
|
||||
@click.option('--yes', '-y', is_flag=True, default=False)
|
||||
def delete(username, yes):
|
||||
db_delete(username, 'mysql', yes)
|
||||
|
|
|
@ -7,14 +7,15 @@ from .utils import handle_sync_response, print_colon_kv
|
|||
@click.command(short_help="Sync the 'program' attribute with UWLDAP")
|
||||
@click.option('--dry-run', is_flag=True, default=False)
|
||||
@click.option('--members', required=False)
|
||||
def updateprograms(dry_run, members):
|
||||
@click.option('--yes', '-y', is_flag=True, default=False)
|
||||
def updateprograms(dry_run, members, yes):
|
||||
body = {}
|
||||
if dry_run:
|
||||
body['dry_run'] = True
|
||||
if members is not None:
|
||||
body['members'] = ','.split(members)
|
||||
|
||||
if not dry_run:
|
||||
if not dry_run or not yes:
|
||||
click.confirm('Are you sure that you want to sync programs with UWLDAP?', abort=True)
|
||||
|
||||
resp = http_post('/api/uwldap/updateprograms', json=body)
|
||||
|
|
|
@ -12,13 +12,14 @@ def webhosting():
|
|||
@webhosting.command(short_help='Disable club sites with no active club reps')
|
||||
@click.option('--dry-run', is_flag=True, default=False)
|
||||
@click.option('--remove-inactive-club-reps', is_flag=True, default=False)
|
||||
def disableclubsites(dry_run, remove_inactive_club_reps):
|
||||
@click.option('--yes', '-y', is_flag=True, default=False)
|
||||
def disableclubsites(dry_run, remove_inactive_club_reps, yes):
|
||||
params = {}
|
||||
if dry_run:
|
||||
params['dry_run'] = 'true'
|
||||
if remove_inactive_club_reps:
|
||||
params['remove_inactive_club_reps'] = 'true'
|
||||
if not dry_run:
|
||||
if not dry_run or not yes:
|
||||
click.confirm('Are you sure you want to disable the websites of clubs with no active club reps?', abort=True)
|
||||
|
||||
resp = http_post('/api/webhosting/disableclubsites', params=params)
|
||||
|
|
Loading…
Reference in New Issue