Exemplo n.º 1
0
def user_teams_by_username_get(username) -> Response:
    """
    Get the team memberships for a user.
    :param username: Username that uniquely identifies a user.
    :return: A response object for the GET API request.
    """
    teams: ResultProxy = TeamMemberDao.get_user_teams(username=username)
    team_list = []

    for team in teams:
        team_list.append({
            'team_name': team['team_name'],
            'title': team['title'],
            'status': team['status'],
            'user': team['user']
        })

    response = jsonify({
        'self': f'/v2/users/teams/{username}',
        'teams': team_list
    })
    response.status_code = 200
    return response
Exemplo n.º 2
0
def user_memberships_by_username_get(username) -> Response:
    """
    Get the team and group memberships for a user.
    :param username: Username that uniquely identifies a user.
    :return: A response object for the GET API request.
    """
    teams: ResultProxy = TeamMemberDao.get_user_teams(username=username)
    membership_list = []

    for team in teams:
        groups: ResultProxy = GroupMemberDao.get_user_groups_in_team(
            username=username, team_name=team['team_name'])
        membership_list.append({
            'team_name':
            team['team_name'],
            'title':
            team['title'],
            'status':
            team['status'],
            'user':
            team['user'],
            'groups': [{
                'group_name': group['group_name'],
                'group_title': group['group_title'],
                'group_id': group['group_id'],
                'status': group['status'],
                'user': group['user']
            } for group in groups]
        })

    response = jsonify({
        'self': f'/v2/users/memberships/{username}',
        'memberships': membership_list
    })
    response.status_code = 200
    return response