api/auth.go
func teamInfo(w http.ResponseWriter, r *http.Request, t auth.Token) error {
	teamName := r.URL.Query().Get(":name")
	team, err := servicemanager.Team.FindByName(teamName)
	if err != nil {
		return &errors.HTTP{Code: http.StatusNotFound, Message: err.Error()}
	}
	canRead := permission.Check(t, permission.PermTeamRead)
	if !canRead {
		return permission.ErrUnauthorized
	}
	apps, err := app.List(&app.Filter{
		Extra:     map[string][]string{"teams": {team.Name}},
		TeamOwner: team.Name})
	if err != nil {
		return &errors.HTTP{Code: http.StatusNotFound, Message: err.Error()}
	}
	pools, err := pool.ListPoolsForTeam(team.Name)
	if err != nil {
		return &errors.HTTP{Code: http.StatusNotFound, Message: err.Error()}
	}
	users, err := auth.ListUsers()
	if err != nil {
		return &errors.HTTP{Code: http.StatusNotFound, Message: err.Error()}
	}
	cachedRoles := make(map[string]permission.Role)
	includedUsers := make([]*apiUser, 0)
	for _, user := range users {
		for _, roleInstance := range user.Roles {
			role, ok := cachedRoles[roleInstance.Name]
			if !ok {
				roleFound, err := permission.FindRole(roleInstance.Name)
				if err != nil {
					return &errors.HTTP{Code: http.StatusNotFound, Message: err.Error()}
				}
				cachedRoles[roleInstance.Name] = roleFound
				role = cachedRoles[roleInstance.Name]
			}
			if role.ContextType == permTypes.CtxGlobal || (role.ContextType == permTypes.CtxTeam && roleInstance.ContextValue == team.Name) {
				canInclude := permission.Check(t, permission.PermTeam)
				if canInclude {
					roleMap := make(map[string]*permission.Role)
					perms, err := t.Permissions()
					if err != nil {
						return &errors.HTTP{Code: http.StatusNotFound, Message: err.Error()}
					}
					userData, err := createAPIUser(perms, &user, roleMap, canInclude)
					if err != nil {
						return &errors.HTTP{Code: http.StatusInternalServerError, Message: err.Error()}
					}
					includedUsers = append(includedUsers, userData)
					break
				}
			}
		}
	}
	result := map[string]interface{}{
		"name":  team.Name,
		"tags":  team.Tags,
		"users": includedUsers,
		"pools": pools,
		"apps":  apps,
	}
	w.Header().Set("Content-Type", "application/json")
	return json.NewEncoder(w).Encode(result)
}
func teamInfo(w http.ResponseWriter, r *http.Request, t auth.Token) error {
	teamName := r.URL.Query().Get(":name")
	team, err := servicemanager.Team.FindByName(teamName)
	if err != nil {
		return &errors.HTTP{Code: http.StatusNotFound, Message: err.Error()}
	}
	canRead := permission.Check(t, permission.PermTeamRead)
	if !canRead {
		return permission.ErrUnauthorized
	}
	apps, err := app.List(&app.Filter{
		Extra:     map[string][]string{"teams": {team.Name}},
		TeamOwner: team.Name})
	if err != nil {
		return &errors.HTTP{Code: http.StatusNotFound, Message: err.Error()}
	}
	pools, err := pool.ListPoolsForTeam(team.Name)
	if err != nil {
		return &errors.HTTP{Code: http.StatusNotFound, Message: err.Error()}
	}
	users, err := auth.ListUsers()
	if err != nil {
		return &errors.HTTP{Code: http.StatusNotFound, Message: err.Error()}
	}
	cachedRoles := make(map[string]permission.Role)
	includedUsers := make([]*apiUser, 0)
	for _, user := range users {
		for _, roleInstance := range user.Roles {
			role, ok := cachedRoles[roleInstance.Name]
			if !ok {
				roleFound, err := permission.FindRole(roleInstance.Name)
				if err != nil {
					return &errors.HTTP{Code: http.StatusNotFound, Message: err.Error()}
				}
				cachedRoles[roleInstance.Name] = roleFound
				role = cachedRoles[roleInstance.Name]
			}
			if role.ContextType == permTypes.CtxGlobal || (role.ContextType == permTypes.CtxTeam && roleInstance.ContextValue == team.Name) {
				canInclude := permission.Check(t, permission.PermTeam)
				if canInclude {
					roleMap := make(map[string]*permission.Role)
					perms, err := t.Permissions()
					if err != nil {
						return &errors.HTTP{Code: http.StatusNotFound, Message: err.Error()}
					}
					userData, err := createAPIUser(perms, &user, roleMap, canInclude)
					if err != nil {
						return &errors.HTTP{Code: http.StatusInternalServerError, Message: err.Error()}
					}
					includedUsers = append(includedUsers, userData)
					break
				}
			}
		}
	}
	result := map[string]interface{}{
		"name":  team.Name,
		"tags":  team.Tags,
		"users": includedUsers,
		"pools": pools,
		"apps":  apps,
	}
	w.Header().Set("Content-Type", "application/json")
	return json.NewEncoder(w).Encode(result)
}
// title: team info
// path: /teams/{name}
// method: GET
// produce: application/json
// responses:
//   200: Info team
//   404: Not found
//   401: Unauthorized