Esempio n. 1
0
def merge_site_members(api, data):
    print('Merging users...')

    # Get existing site users
    keys = ['user']
    src = api.get_site_members()
    users = filter_data(src['data'], keys)

    # Get existing corp users in case user needs to be added
    keys = ['email']
    src = api.get_corp_users()
    corp_users = [user['email'] for user in filter_data(src['data'], keys)]

    # Loop through the users to add
    for item in data:
        for user in users:
            # Skip users that exist in the site
            if item['user']['email'] == user['user']['email']:
                print('  Skipping %s (exists)' % item['user']['email'])
                break
        else:
            if item['user']['email'] not in corp_users:
                # User does not exist in corp so invite it to the corp and add
                # it to the site
                print('  %s (New user - Corp role: %s, API user: %s)' %
                      (item['user']['email'], item['role'],
                       item['user']['apiUser']))
                add_new_user(api, item['user']['email'], item['role'],
                             item['user']['apiUser'])
            else:
                # Add missing user
                print('  Adding %s' % item['user']['email'])
                role = {'role': item['role']}
                api.update_site_member(item['user']['email'], role)
Esempio n. 2
0
def add_site_members(api, data):
    print('Adding users...')

    # Get existing corp users in case user needs to be added
    keys = ['email']
    src = api.get_corp_users()
    users = [user['email'] for user in filter_data(src['data'], keys)]
    for item in data:
        if item['user']['email'] not in users:
            # User does not exist in corp so invite it to the corp and add it
            # to the site
            print('  %s (New user - Corp role: %s, API user: %s)' %
                  (item['user']['email'],
                   item['role'],
                   item['user']['apiUser']))
            add_new_user(api,
                         item['user']['email'],
                         item['role'],
                         item['user']['apiUser'])
        elif item['role'] == 'owner':
            # Owners are auto-added at site creation
            continue
        else:
            # User exists in corp and is not an owner to add it to the site
            print('  %s' % item['user']['email'])
            role = {'role': item['role']}
            api.update_site_member(item['user']['email'], role)
Esempio n. 3
0
def do_add_user(args):
    api = init_api(args.username, args.password, args.token, args.corp,
                   args.dry_run)

    input_file = resolve_input_file(args.file_name)
    location_string = 'corp'
    if args.site_name:
        api.site = args.site_name
        location_string = args.site_name

    user_list = []
    if args.email_id:
        user_list.append([args.email_id, args.role_name])
    if input_file:
        user_list = get_users_from_file(input_file, 2)

    added_users = 0
    for entry in user_list:
        user_role = entry[1]
        if args.role_name and len(entry[1]) >= 0:
            user_role = args.role_name
        data = resolve_user_data_role(api, user_role)
        if args.dry_run:
            print("Adding %s to %s with %s role" %
                  (entry[0], location_string, data['role']))
        add_new_user(api, entry[0], data['role'], args.api_user)
        added_users += 1
    print("Added %d users" % added_users)