diff --git a/server/datastore/mysql/teams.go b/server/datastore/mysql/teams.go index 72bdba605e..f9f0e123d6 100644 --- a/server/datastore/mysql/teams.go +++ b/server/datastore/mysql/teams.go @@ -81,7 +81,10 @@ func (d *Datastore) SaveTeam(team *kolide.Team) (*kolide.Team, error) { // kolide.ListOptions func (d *Datastore) ListTeams(opt kolide.ListOptions) ([]*kolide.Team, error) { query := ` - SELECT * FROM teams + SELECT *, + (SELECT count(*) FROM user_teams WHERE team_id = id) AS user_count, + (SELECT count(*) FROM hosts WHERE team_id = id) AS host_count + FROM teams WHERE TRUE ` query, params := searchLike(query, nil, opt.MatchQuery, teamSearchColumns...) diff --git a/server/kolide/teams.go b/server/kolide/teams.go index b1bc6e8565..496a81b617 100644 --- a/server/kolide/teams.go +++ b/server/kolide/teams.go @@ -54,8 +54,12 @@ type Team struct { // Derived from JOINs + // UserCount is the count of users with explicit roles on this team. + UserCount int `json:"user_count" db:"user_count"` // Users is the users that have a role on this team. Users []TeamUser `json:"users,omitempty"` + // UserCount is the count of hosts assigned to this team. + HostCount int `json:"host_count" db:"host_count"` // Hosts are the hosts assigned to the team. Hosts []Host `json:"hosts,omitempty"` }