(ctx context.Context, template database.Template)
| 858 | } |
| 859 | |
| 860 | func (api *API) notifyUsersOfTemplateDeprecation(ctx context.Context, template database.Template) error { |
| 861 | workspaces, err := api.Database.GetWorkspaces(ctx, database.GetWorkspacesParams{ |
| 862 | TemplateIDs: []uuid.UUID{template.ID}, |
| 863 | }) |
| 864 | if err != nil { |
| 865 | return xerrors.Errorf("get workspaces by template id: %w", err) |
| 866 | } |
| 867 | |
| 868 | users := make(map[uuid.UUID]struct{}) |
| 869 | for _, workspace := range workspaces { |
| 870 | users[workspace.OwnerID] = struct{}{} |
| 871 | } |
| 872 | |
| 873 | errs := []error{} |
| 874 | |
| 875 | for userID := range users { |
| 876 | _, err = api.NotificationsEnqueuer.Enqueue( |
| 877 | //nolint:gocritic // We need the notifier auth context to be able to send the deprecation notification. |
| 878 | dbauthz.AsNotifier(ctx), |
| 879 | userID, |
| 880 | notifications.TemplateTemplateDeprecated, |
| 881 | map[string]string{ |
| 882 | "template": template.Name, |
| 883 | "message": template.Deprecated, |
| 884 | "organization": template.OrganizationName, |
| 885 | }, |
| 886 | "notify-users-of-template-deprecation", |
| 887 | ) |
| 888 | if err != nil { |
| 889 | errs = append(errs, xerrors.Errorf("enqueue notification: %w", err)) |
| 890 | } |
| 891 | } |
| 892 | |
| 893 | return errors.Join(errs...) |
| 894 | } |
| 895 | |
| 896 | // @Summary Get template DAUs by ID |
| 897 | // @ID get-template-daus-by-id |
no test coverage detected