|
|
|
@ -20,7 +20,9 @@ def members(): |
|
|
|
|
|
|
|
|
|
@members.command(short_help='Add a new member or club rep') |
|
|
|
|
@click.argument('username') |
|
|
|
|
@click.option('--cn', help='Full name', prompt='Full name') |
|
|
|
|
@click.option('--cn', help='Full name', required=False) |
|
|
|
|
@click.option('--given-name', help='First name', required=False) |
|
|
|
|
@click.option('--sn', help='Last name', required=False) |
|
|
|
|
@click.option('--program', required=False, help='Academic program') |
|
|
|
|
@click.option('--terms', 'num_terms', type=click.IntRange(1, 100), |
|
|
|
|
help='Number of terms to add', default=1) |
|
|
|
@ -30,19 +32,40 @@ 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, program, num_terms, clubrep, forwarding_address): |
|
|
|
|
def add(username, cn, given_name, sn, program, num_terms, clubrep, forwarding_address): |
|
|
|
|
cfg = component.getUtility(IConfig) |
|
|
|
|
uw_domain = cfg.get('uw_domain') |
|
|
|
|
|
|
|
|
|
terms = get_terms_for_new_user(num_terms) |
|
|
|
|
|
|
|
|
|
# TODO: get email address from UWLDAP |
|
|
|
|
# Try to get info from UWLDAP |
|
|
|
|
resp = http_get('/api/uwldap/' + username) |
|
|
|
|
if resp.ok: |
|
|
|
|
result = handle_sync_response(resp) |
|
|
|
|
if cn is None and result.get('cn'): |
|
|
|
|
cn = result['cn'] |
|
|
|
|
if given_name is None and result.get('given_name'): |
|
|
|
|
given_name = result['given_name'] |
|
|
|
|
if sn is None and result.get('sn'): |
|
|
|
|
sn = result['sn'] |
|
|
|
|
if program is None and result.get('program'): |
|
|
|
|
program = result['program'] |
|
|
|
|
if forwarding_address is None: |
|
|
|
|
forwarding_address = result['mail_local_addresses'][0] |
|
|
|
|
if cn is None: |
|
|
|
|
cn = click.prompt('Full name') |
|
|
|
|
if given_name is None: |
|
|
|
|
given_name = click.prompt('First name') |
|
|
|
|
if sn is None: |
|
|
|
|
sn = click.prompt('Last name') |
|
|
|
|
if forwarding_address is None: |
|
|
|
|
forwarding_address = username + '@' + uw_domain |
|
|
|
|
|
|
|
|
|
terms = get_terms_for_new_user(num_terms) |
|
|
|
|
|
|
|
|
|
body = { |
|
|
|
|
'uid': username, |
|
|
|
|
'cn': cn, |
|
|
|
|
'given_name': given_name, |
|
|
|
|
'sn': sn, |
|
|
|
|
} |
|
|
|
|
if program is not None: |
|
|
|
|
body['program'] = program |
|
|
|
|