Example #1
0
def get_groups_by_org_id(org_id):
    '''
    Takes in an organization ID and returns a list of all
    groups associated with it.

    '''

    user_dict = user_client.get_user_group_map(org_id)

    return user_dict.keys()
Example #2
0
def search_users(org_id):
    '''
    This function returns information about all users
    in a given organization.

    the group_name 'base' is used because all users we create
    have a user group which is mapped in the datastore to 'base'
    '''

    user_info = []
    response = user_client.search_user(org_id=org_id)

    if not response.userProfilesVO or \
            'userProfiles' not in response.userProfilesVO:
        return []

    group_map = user_client.get_user_group_map(org_id)

    for user in response.userProfilesVO.userProfiles:
        u = {}
        u['user_id'] = user.userInfo.userId
        u['org_id'] = user.userInfo.organizationId
        u['sublevelPermission'] = user.userInfo.sublevelPermission
        u['first_name'] = user.userInfo.firstName
        u['last_name'] = user.userInfo.lastName
        u['middle_name'] = user.userInfo.middleName
        u['email'] = user.userInfo.email1
        u['status'] = user.userLogin.status
        u['user_name'] = user.userLogin.userName
        if user.userInfo.organizationId == org_id:
            u['user_groups'] = [key for key in group_map
                                if group_map[key] in user.userGroupId]
        else:
            u['user_groups'] = [('Please view in organization '
                                 '{} to access').format(u['org_id'])]
        user_info.append(u)

    return user_info