Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions ee/server/service/teams.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,20 @@ func (svc *Service) DeleteTeam(ctx context.Context, teamID uint) error {
}
name := team.Name

vc, ok := viewer.FromContext(ctx)
if !ok {
return fleet.ErrNoContext
}
filter := fleet.TeamFilter{User: vc.User, IncludeObserver: true}
hosts, err := svc.ds.ListHosts(ctx, filter, fleet.HostListOptions{TeamFilter: &teamID})
Comment thread
roperzh marked this conversation as resolved.
if err != nil {
return ctxerr.Wrap(ctx, err, "list hosts for reconcile profiles on team change")
}
hostIDs := make([]uint, 0, len(hosts))
for _, host := range hosts {
hostIDs = append(hostIDs, host.ID)
}

if err := svc.ds.DeleteTeam(ctx, teamID); err != nil {
return err
}
Expand All @@ -391,6 +405,10 @@ func (svc *Service) DeleteTeam(ctx context.Context, teamID uint) error {
return ctxerr.Wrap(ctx, err, "bulk set pending host profiles")
}

if err := svc.ds.CleanupDiskEncryptionKeysOnTeamChange(ctx, hostIDs, ptr.Uint(0)); err != nil {
return ctxerr.Wrap(ctx, err, "reconcile profiles on team change cleanup disk encryption keys")
}

logging.WithExtras(ctx, "id", teamID)

if err := svc.ds.NewActivity(
Expand Down
Loading