Include Team names when listing label hosts (#1267)

Fixes #1266
This commit is contained in:
Zach Wasserman 2021-06-30 09:28:45 -07:00 committed by GitHub
parent a3958ac24c
commit e0799bbc59
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -402,7 +402,7 @@ func (d *Datastore) ListLabelsForHost(hid uint) ([]*fleet.Label, error) {
// with fleet.Label referened by Label ID // with fleet.Label referened by Label ID
func (d *Datastore) ListHostsInLabel(filter fleet.TeamFilter, lid uint, opt fleet.HostListOptions) ([]*fleet.Host, error) { func (d *Datastore) ListHostsInLabel(filter fleet.TeamFilter, lid uint, opt fleet.HostListOptions) ([]*fleet.Host, error) {
sql := fmt.Sprintf(` sql := fmt.Sprintf(`
SELECT h.* SELECT h.*, (SELECT name FROM teams t WHERE t.id = h.team_id) AS team_name
FROM label_membership lm FROM label_membership lm
JOIN hosts h JOIN hosts h
ON lm.host_id = h.id ON lm.host_id = h.id
@ -429,7 +429,7 @@ func (d *Datastore) ListUniqueHostsInLabels(filter fleet.TeamFilter, labels []ui
} }
sqlStatement := fmt.Sprintf(` sqlStatement := fmt.Sprintf(`
SELECT DISTINCT h.* SELECT DISTINCT h.*, (SELECT name FROM teams t WHERE t.id = h.team_id) AS team_name
FROM label_membership lm FROM label_membership lm
JOIN hosts h JOIN hosts h
ON lm.host_id = h.id ON lm.host_id = h.id